diff --git a/CommonApplication.cmake b/CommonApplication.cmake index 18b07f2..e050c9f 100644 --- a/CommonApplication.cmake +++ b/CommonApplication.cmake @@ -15,38 +15,17 @@ # # Builds Name application and installs it. -# include(CMakeParseArguments) +include(CommonQtSupport) function(COMMON_APPLICATION Name) string(TOUPPER ${Name} NAME) string(TOLOWER ${Name} name) set(SOURCES ${${NAME}_SOURCES}) - set(HEADERS ${${NAME}_HEADERS}) + set(HEADERS ${${NAME}_HEADERS} ${${NAME}_MOC_HEADERS}) set(LINK_LIBRARIES ${${NAME}_LINK_LIBRARIES}) - if(${NAME}_MOC_HEADERS) - if(NOT Qt5Core_FOUND) - message(FATAL_ERROR "Qt5Core not found, needed for MOC of application ${Name}") - endif() - qt5_wrap_cpp(MOC_SOURCES ${${NAME}_MOC_HEADERS}) - list(APPEND HEADERS ${${NAME}_MOC_HEADERS}) - list(APPEND SOURCES ${MOC_SOURCES}) - endif() - if(${NAME}_UI_FORMS) - if(NOT Qt5Widgets_FOUND) - message(FATAL_ERROR "Qt5Widgets not found, needed for UIC of application ${Name}") - endif() - qt5_wrap_ui(UI_SOURCES ${${NAME}_UI_FORMS}) - list(APPEND SOURCES ${UI_SOURCES}) - include_directories(${PROJECT_BINARY_DIR}) - endif() - if(${NAME}_RESOURCES) - if(NOT Qt5Core_FOUND) - message(FATAL_ERROR "Qt5Core not found, needed for QRC of application ${Name}") - endif() - qt5_add_resources(QRC_SOURCES ${${NAME}_RESOURCES}) - list(APPEND SOURCES ${QRC_SOURCES}) - endif() + common_qt_support(${NAME}) + list(APPEND SOURCES ${COMMON_QT_SUPPORT_SOURCES}) add_executable(${Name} ${ARGN} ${HEADERS} ${SOURCES}) target_link_libraries(${Name} ${LINK_LIBRARIES}) diff --git a/CommonLibrary.cmake b/CommonLibrary.cmake index 2d1922b..1e87112 100644 --- a/CommonLibrary.cmake +++ b/CommonLibrary.cmake @@ -14,6 +14,11 @@ # * PROJECT_INCLUDE_NAME for the include directory and project include header # * VERSION for the API version # * VERSION_ABI for the ABI version +# * Optional Qt support: +# ** NAME_MOC_HEADERS list of internal moc input headers +# ** NAME_MOC_PUBLIC_HEADERS list of public moc input headers, to be installed +# ** NAME_UI_FORMS list of all .ui input files +# ** NAME_RESOURCES list of all .qrc resource files # # If NAME_LIBRARY_TYPE is a list, libraries are built of each specified # (i.e. shared and static) type. Whichever is first becomes the library @@ -24,6 +29,7 @@ # including all public headers. include(InstallFiles) +include(CommonQtSupport) set(COMMON_LIBRARY_TYPE SHARED CACHE STRING "Library type {any combination of SHARED, STATIC}") @@ -67,14 +73,17 @@ function(COMMON_LIBRARY Name) string(TOLOWER ${Name} PROJECT_INCLUDE_NAME) endif() set(SOURCES ${${NAME}_SOURCES}) - set(HEADERS ${${NAME}_HEADERS}) - set(PUBLIC_HEADERS ${${NAME}_PUBLIC_HEADERS}) + set(HEADERS ${${NAME}_HEADERS} ${${NAME}_MOC_HEADERS}) + set(PUBLIC_HEADERS ${${NAME}_PUBLIC_HEADERS} ${${NAME}_MOC_PUBLIC_HEADERS}) set(LINK_LIBRARIES ${${NAME}_LINK_LIBRARIES}) if(NOT ${NAME}_OMIT_PROJECT_HEADER) generate_project_header(${NAME}) endif() + common_qt_support(${NAME}) + list(APPEND SOURCES ${COMMON_QT_SUPPORT_SOURCES}) + if(SOURCES) list(SORT SOURCES) endif() diff --git a/CommonQtSupport.cmake b/CommonQtSupport.cmake new file mode 100644 index 0000000..4a9e776 --- /dev/null +++ b/CommonQtSupport.cmake @@ -0,0 +1,44 @@ +# Copyright (c) 2015 raphael.dumusc@epfl.ch + +# Provides Qt support for CommonLibrary and CommonApplication: +# common_qt_support() +# +# Uses: +# * NAME_MOC_HEADERS, NAME_MOC_PUBLIC_HEADERS list of all moc input headers +# * NAME_UI_FORMS list of all .ui input files +# * NAME_RESOURCES list of all .qrc resource files +# * Sets the output to the following variables in parent scope: +# * COMMON_QT_SUPPORT_SOURCES + +macro(COMMON_QT_SUPPORT NAME) + if(${NAME}_MOC_HEADERS) + if(NOT Qt5Core_FOUND) + message(FATAL_ERROR "Qt5Core not found, needed for MOC of application ${Name}") + endif() + qt5_wrap_cpp(MOC_SOURCES ${${NAME}_MOC_HEADERS}) + list(APPEND COMMON_QT_SUPPORT_SOURCES ${MOC_SOURCES}) + endif() + if(${NAME}_MOC_PUBLIC_HEADERS) + if(NOT Qt5Core_FOUND) + message(FATAL_ERROR "Qt5Core not found, needed for MOC of application ${Name}") + endif() + qt5_wrap_cpp(MOC_SOURCES ${${NAME}_MOC_PUBLIC_HEADERS}) + list(APPEND COMMON_QT_SUPPORT_SOURCES ${MOC_SOURCES}) + endif() + if(${NAME}_UI_FORMS) + if(NOT Qt5Widgets_FOUND) + message(FATAL_ERROR "Qt5Widgets not found, needed for UIC of application ${Name}") + endif() + qt5_wrap_ui(UI_SOURCES ${${NAME}_UI_FORMS}) + list(APPEND COMMON_QT_SUPPORT_SOURCES ${UI_SOURCES}) + include_directories(${PROJECT_BINARY_DIR}) + endif() + if(${NAME}_RESOURCES) + if(NOT Qt5Core_FOUND) + message(FATAL_ERROR "Qt5Core not found, needed for QRC of application ${Name}") + endif() + qt5_add_resources(QRC_SOURCES ${${NAME}_RESOURCES}) + list(APPEND COMMON_QT_SUPPORT_SOURCES ${QRC_SOURCES}) + endif() + set(COMMON_QT_SUPPORT_SOURCES ${COMMON_QT_SUPPORT_SOURCES} PARENT_SCOPE) +endmacro()