Skip to content

Commit

Permalink
Implement Qt support for common_library
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphael Dumusc committed May 29, 2015
1 parent a9c3537 commit 00e5add
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 27 deletions.
29 changes: 4 additions & 25 deletions CommonApplication.cmake
Expand Up @@ -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})
Expand Down
13 changes: 11 additions & 2 deletions CommonLibrary.cmake
Expand Up @@ -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
Expand All @@ -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}")
Expand Down Expand Up @@ -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()
Expand Down
44 changes: 44 additions & 0 deletions CommonQtSupport.cmake
@@ -0,0 +1,44 @@
# Copyright (c) 2015 raphael.dumusc@epfl.ch

# Provides Qt support for CommonLibrary and CommonApplication:
# common_qt_support(<Name>)
#
# 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()

0 comments on commit 00e5add

Please sign in to comment.