# additional qt functions# MINI HACK# find qt translations directoryif (QT_LIBRARY_DIR AND NOT QT_TRANSLATIONS_DIR)exec_program(${QT_QMAKE_EXECUTABLE} ARGS "-query QT_INSTALL_TRANSLATIONS"OUTPUT_VARIABLE qt_translations_dir)file(TO_CMAKE_PATH "${qt_translations_dir}" qt_translations_dir)set(QT_TRANSLATIONS_DIR ${qt_translations_dir} CACHE PATH "The location of qt translations")endif (QT_LIBRARY_DIR AND NOT QT_TRANSLATIONS_DIR)
# MINI HACK# create function to wrap qt *.ts files# qt4_wrap_ts(outfiles infiles ...)# outfiles receives .qm generated files from# .ts files in arguments# a target lupdate is created for you# update/generate your translations files# example: QT4_WRAP_TS(foo_QM ${foo_TS})macro (QT4_WRAP_TS outfiles)# a target to manually run lupdateadd_custom_target(lupdate COMMAND ${QT_LUPDATE_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR} -recursive -extensions ui,c,c++,cc,cpp,cxx,ch,h,h++,hh,hpp,hxx,js,qs -ts ${ARGN} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )add_custom_command (OUTPUT ${ARGN} COMMAND ${QT_LUPDATE_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR} -recursive -extensions ui,c,c++,cc,cpp,cxx,ch,h,h++,hh,hpp,hxx,js,qs -ts ${ARGN} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )foreach (it ${ARGN}) get_filename_component(outfile ${it} NAME_WE) get_filename_component(outpath ${it} PATH) set(outfile ${outpath}/${outfile}.qm) add_custom_command(OUTPUT ${outfile} COMMAND ${QT_LRELEASE_EXECUTABLE} ARGS ${it} -qm ${outfile} DEPENDS ${it} ) set(${outfiles} ${${outfiles}} ${outfile})endforeach (it)endmacro (QT4_WRAP_TS)
# just insert the languages you want to support in this list # add your language set(LANGUAGES ru be) set(TS_FILES) foreach(LANGUAGE ${LANGUAGES}) set(TS_FILES ${TS_FILES} ${TRANSLATIONS_PATH}/${PROJECT}_${LANGUAGE}.ts) endforeach(LANGUAGE) # create|update language *.ts and create compiled language files *.qm qt4_wrap_ts(QM_FILES ${TS_FILES})# COMPILATION add_library(${PROJECT} SHARED ${SOURCES} ${HEADERS} ${UI_HEADERS} ${MOC_SOURCES} ${QRC_SOURCES} ${QM_FILES})
IDI_ICON1 ICON DISCARDABLE "logo.ico"
if(MINGW AND WIN32)# Путь к файлу win-ресурсов SET(WIN_RESOURCES "${CMAKE_SOURCE_DIR}/share/images/application/logo.rc")endif(MINGW AND WIN32)add_executable(${PROJECT_NAME} WIN32 ${WIN_RESOURCES})
#create app icon# Путь к объектному файлу иконкиset(WIN_RESOURCES)# Если в win среде компилируем с помощью MINGWif(MINGW AND WIN32)# resource compilation for mingw# Добавляем команду компиляции ADD_CUSTOM_COMMAND(OUTPUT # Получаемый объектный файл win-ресурсов${CMAKE_CURRENT_BINARY_DIR}/logo_rc.o# Компилятор ресурсов COMMAND windres.exe # Место, где лежит иконка-I"${CMAKE_SOURCE_DIR}/share/images/application/"# Файл win-ресурсов -i "${CMAKE_SOURCE_DIR}/share/images/application/logo.rc"# Получаемый объектный файл win-ресурсов -o ${CMAKE_CURRENT_BINARY_DIR}/logo_rc.o)# Путь к объектному файлу win-ресурсов SET(WIN_RESOURCES ${CMAKE_CURRENT_BINARY_DIR}/logo_rc.o)# Если не используем MINGWelseif((NOT MINGW) AND WIN32) SET(WIN_RESOURCES"${CMAKE_SOURCE_DIR}/share/images/application/logo.rc")endif(MINGW AND WIN32)#Компилируем вместе с иконкойadd_executable(${PROJECT_NAME} WIN32 ${SOURCES} ${Q_SOURCES} ${MOC_SOURCES} ${QRC_SOURCES} ${HEADERS} ${Q_HEADERS} ${P_HEADERS} ${UI_HEADERS} ${QS_SOURCES} ${WIN_RESOURCES})
get_filename_component(THIS_PATH ${CMAKE_CURRENT_LIST_FILE} PATH)include_directories(${THIS_PATH})# QObject-basedlist(APPEND Q_HEADERS ${THIS_PATH}/someqobjectfile.h)# QObject-based implementation and nonQObject-based implementationlist(APPEND SOURCES ${THIS_PATH}/someqobjectfile.cpp)# NonQObject-based or moc included in implementation filelist(APPEND HEADERS ${THIS_PATH}/somenonqobjectfile.h)# QObject-based with moc includinglist(APPEND Q_SOURCES ${THIS_PATH}/somefileincludingmoc.cpp)# Resourceslist(APPEND Q_RESOURCES ${THIS_PATH}/someresources.qrc)# Ui Formslist(APPEND Q_FORMS ${THIS_PATH}/someform.ui)
include("subddir/subdir.cmake")qt4_wrap_cpp(MOC_SOURCES ${Q_HEADERS})qt4_automoc(${Q_SOURCES})qt4_wrap_ui(UI_HEADERS ${Q_FORMS})qt4_add_resources(QRC_SOURCES ${Q_RESOURCES})
INCLUDEPATH += $${PWD}HEADERS += $${PWD}/someqobjectfile.h \ $${PWD}/somenonqobjectfile.hSOURCES += $${PWD}/someqobjectfile.cpp \ $${PWD}/somefileincludingmoc.cpp
project/ src/ 3rdparty/ qttoolbardialog/ CMakeLists.txt kernel/ main/ models/ views/ CMakeLists.txt
add_subdirectory(src/3rdparty/qttoolbardialog)include_directories(src/3rdparty/qttoolbardialog).....................target_link_libraries(..... qttoolbardialog)
project(qttoolbardialog)set(SOURCES ....)set(HEADERS .....)add_library(${PROJECT_NAME} STATIC ${SOURCES} ${HEADERS})
# генерируем mocqt4_generate_moc(qttoolbardialog.cpp ${CMAKE_CURRENT_BINARY_DIR}/qttoolbardiralog.moc)# исходный файл зависит от сгенерированного моком файла.set_source_files_properties(qttoolbardialog.cpp OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/qttoolbardiralog.moc)..................# сгенерированный моком добавлять не нужно, так как он подключается через #include "qttoolbardialog.moc"add_executable(${PROJECT_NAME} qttoolbardialog.cpp ............)
# all 3rd party subdirectories ---------------------------------------------------------file(GLOB 3RDPARTY_DIRS "3rdparty/*")foreach(3RDPARTY_DIR ${3RDPARTY_DIRS}) if (IS_DIRECTORY ${3RDPARTY_DIR}) message("${3RDPARTY_DIR}") add_subdirectory(${3RDPARTY_DIR}) endif(IS_DIRECTORY ${3RDPARTY_DIR})endforeach(3RDPARTY_DIR)
cmake_minimum_required( VERSION 2.6 )find_package( Qt4 REQUIRED )set (QT_USE_QTTEST TRUE)include( ${QT_USE_FILE} )qt4_generate_moc( testqstring.cpp ${CMAKE_CURRENT_BINARY_DIR}/testqstring.moc )set_source_files_properties( testqstring.cpp OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/testqstring.moc )set(CMAKE_INCLUDE_CURRENT_DIR TRUE)add_executable( QtTest testqstring.cpp )target_link_libraries( QtTest ${QT_LIBRARIES} )
enable_testing()add_test(NAME testqstring COMMAND QtTest)
set(ENABLE_TESTING True)
enable_testing()