From 1e5eb921a1acec282f6184b732c3dc57d0cd40af Mon Sep 17 00:00:00 2001 From: Jacques GUILLOU Date: Thu, 30 Apr 2020 17:59:11 +0200 Subject: [PATCH] Improve monolithic build support --- .travis.yml | 15 ++++++-- cmake/faceliftMacros.cmake | 58 ++++++++++++++++++++++++------- src/ipc/dbus/CMakeLists.txt | 5 +-- src/ipc/ipc-common/CMakeLists.txt | 2 +- src/ipc/local/CMakeLists.txt | 2 +- src/model/CMakeLists.txt | 3 +- 6 files changed, 63 insertions(+), 22 deletions(-) diff --git a/.travis.yml b/.travis.yml index 04d858a7..b7b91011 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,7 +23,16 @@ matrix: - ubuntu-toolchain-r-test - sourceline: 'ppa:beineri/opt-qt-5.12.0-xenial' packages: [ g++-5 qt512base qt512declarative ] - env: COMPILER=g++-5 QT=512 DISABLE_IPC=ON + env: COMPILER=g++-5 QT=512 DISABLE_IPC=ON MONOLITHIC_BUILD=OFF + - os: linux + compiler: gcc # g++-5, Qt5.12.0, MONOLITHIC_BUILD + addons: + apt: + sources: + - ubuntu-toolchain-r-test + - sourceline: 'ppa:beineri/opt-qt-5.12.0-xenial' + packages: [ g++-5 qt512base qt512declarative ] + env: COMPILER=g++-5 QT=512 MONOLITHIC_BUILD=ON - os: linux compiler: clang # clang-6.0, Qt5.12.0, IPC enabled addons: @@ -32,7 +41,7 @@ matrix: - ubuntu-toolchain-r-test - sourceline: 'ppa:beineri/opt-qt-5.12.0-xenial' packages: [ clang-6.0 libstdc++-6-dev qt512base qt512declarative ] - env: COMPILER=clang++-6.0 QT=512 DISABLE_IPC=OFF + env: COMPILER=clang++-6.0 QT=512 DISABLE_IPC=OFF MONOLITHIC_BUILD=OFF install: - sudo apt-get install python3 python3-pip python3-setuptools doxygen libgl1-mesa-dev @@ -49,5 +58,5 @@ before_script: script: - cd build - > - cmake -DCMAKE_CXX_COMPILER=${COMPILER} -DCMAKE_BUILD_TYPE=Release -DFACELIFT_DISABLE_DBUS_IPC=${DISABLE_IPC} -DFACELIFT_BUILD_TESTS=ON -DCMAKE_SYSTEM_PREFIX_PATH=$CMAKE_SYSTEM_PREFIX_PATH .. + cmake -DCMAKE_CXX_COMPILER=${COMPILER} -DCMAKE_BUILD_TYPE=Release -DFACELIFT_DISABLE_DBUS_IPC=${DISABLE_IPC} -DENABLE_MONOLITHIC_BUILD=${MONOLITHIC_BUILD} -DFACELIFT_BUILD_TESTS=ON -DCMAKE_SYSTEM_PREFIX_PATH=$CMAKE_SYSTEM_PREFIX_PATH .. - make -j2 && dbus-launch make check && cat ./tests/results.csv diff --git a/cmake/faceliftMacros.cmake b/cmake/faceliftMacros.cmake index 022ae341..869f3b3b 100644 --- a/cmake/faceliftMacros.cmake +++ b/cmake/faceliftMacros.cmake @@ -10,6 +10,7 @@ if(ENABLE_MONOLITHIC_BUILD) message(WARNING "CMake > 3.12.0 is required to enable monolithic build, but your version is ${CMAKE_VERSION}. Forcing ENABLE_MONOLITHIC_BUILD to OFF") set(ENABLE_MONOLITHIC_BUILD OFF) endif() + cmake_policy(SET CMP0079 NEW) # Needed to alter library definition in parent scope endif() include(GNUInstallDirs) # for standard installation locations @@ -481,7 +482,10 @@ endmacro() function(facelift_add_library TARGET_NAME) - _facelift_parse_target_arguments("SYSTEM;STATIC;SHARED;OBJECT;MODULE;MONOLITHIC_SUPPORTED" "" "HEADERS_NO_INSTALL;HEADERS_GLOB_NO_INSTALL;HEADERS_GLOB_RECURSE_NO_INSTALL;PUBLIC_HEADER_BASE_PATH;MONOLITHIC_LINK_LIBRARIES" ${ARGN}) + _facelift_parse_target_arguments("SYSTEM;STATIC;SHARED;OBJECT;MODULE;MONOLITHIC_SUPPORTED" "" + "HEADERS_NO_INSTALL;HEADERS_GLOB_NO_INSTALL;HEADERS_GLOB_RECURSE_NO_INSTALL;PUBLIC_HEADER_BASE_PATH;MONOLITHIC_LINK_LIBRARIES" + ${ARGN} + ) if(ARGUMENT_SYSTEM) message("System library ${TARGET_NAME}") @@ -490,6 +494,8 @@ function(facelift_add_library TARGET_NAME) unset(SYSTEM_LIB_ARGUMENT) endif() + list(APPEND ARGUMENT_LINK_LIBRARIES ${ARGUMENT_MONOLITHIC_LINK_LIBRARIES}) + unset(__INTERFACE) if(ARGUMENT_INTERFACE) _facelift_add_target_start(${TARGET_NAME}) @@ -516,6 +522,8 @@ function(facelift_add_library TARGET_NAME) if(ENABLE_MONOLITHIC_BUILD) + set_property(GLOBAL PROPERTY ${TARGET_NAME}_IS_MONOLITHIC ON) + set(TARGET_NAME ${TARGET_NAME}_) set(__INTERFACE INTERFACE) @@ -533,19 +541,19 @@ function(facelift_add_library TARGET_NAME) target_link_libraries(${IMPLEMENTATION_TARGET_NAME} ${TARGET_NAME}) endif() - foreach(MONOLITHIC_LINK_LIBRARY ${ARGUMENT_MONOLITHIC_LINK_LIBRARIES}) - list(APPEND ARGUMENT_LINK_LIBRARIES ${MONOLITHIC_LINK_LIBRARY}_) - endforeach() + set_property(GLOBAL APPEND PROPERTY ${ALIAS_NAME}_LINK_LIBRARIES ${ARGUMENT_LINK_LIBRARIES}) + get_property(LINK_LIBRARIES GLOBAL PROPERTY ${TARGET_NAME}_LINK_LIBRARIES) list(APPEND ARGUMENT_LINK_LIBRARIES ${MONOLITHIC_LINK_LIBRARIES}) + unset(ARGUMENT_LINK_LIBRARIES) _facelift_add_target_finish(${TARGET_NAME} ${IMPLEMENTATION_TARGET_NAME}) # Append our object library to the list of libraries to be linked to the monolithic library - set_property(GLOBAL APPEND PROPERTY MONOLITHIC_LIBRARIES ${IMPLEMENTATION_TARGET_NAME}) + set_property(GLOBAL APPEND PROPERTY MONOLITHIC_LIBRARIES ${ALIAS_NAME}) # Create an interface library with the original target name, which links against the monolithic library add_library(${ALIAS_NAME} INTERFACE) - target_link_libraries(${ALIAS_NAME} INTERFACE ${TARGET_NAME} ${PROJECT_NAME} ${ARGUMENT_MONOLITHIC_LINK_LIBRARIES}) + target_link_libraries(${ALIAS_NAME} INTERFACE ${TARGET_NAME} ${CMAKE_PROJECT_NAME}) set(BUILD_MONOLITHIC ON) @@ -749,17 +757,41 @@ function(facelift_export_project) install(FILES ${CONFIG_DESTINATION_PATH}/${PROJECT_NAME}Config.cmake.installed DESTINATION ${CMAKE_CONFIG_INSTALLATION_PATH} RENAME ${PROJECT_NAME}Config.cmake) facelift_export_monolithic() + endfunction() + function(facelift_export_monolithic) - get_property(MONOLITHIC_LIBRARIES GLOBAL PROPERTY MONOLITHIC_LIBRARIES) - if(MONOLITHIC_LIBRARIES AND NOT TARGET ${PROJECT_NAME}) - add_library(${PROJECT_NAME} SHARED) - foreach(LIB ${MONOLITHIC_LIBRARIES}) - target_link_libraries(${PROJECT_NAME} PRIVATE ${LIB}) - endforeach() - install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}Targets DESTINATION ${CMAKE_INSTALL_LIBDIR}) + + if (${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME}) # We only export the main project + get_property(MONOLITHIC_LIBRARIES GLOBAL PROPERTY MONOLITHIC_LIBRARIES) + if(MONOLITHIC_LIBRARIES AND NOT TARGET ${CMAKE_PROJECT_NAME}) + + add_library(${CMAKE_PROJECT_NAME} SHARED) + + foreach(LIB ${MONOLITHIC_LIBRARIES}) + target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE ${LIB}__OBJECTS) + + get_property(LINK_LIBRARIES GLOBAL PROPERTY ${LIB}_LINK_LIBRARIES) + + foreach(LINK_LIBRARY ${LINK_LIBRARIES}) + + get_property(IS_MONOLITHIC GLOBAL PROPERTY ${LINK_LIBRARY}_IS_MONOLITHIC SET) + + if (IS_MONOLITHIC) + target_link_libraries(${LIB} INTERFACE ${LINK_LIBRARY}) + target_link_libraries(${LIB}_ INTERFACE ${LINK_LIBRARY}_) + else() + target_link_libraries(${LIB}_ INTERFACE ${LINK_LIBRARY}) + endif() + + endforeach() + + endforeach() + install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}Targets DESTINATION ${CMAKE_INSTALL_LIBDIR}) + endif() endif() + endfunction() diff --git a/src/ipc/dbus/CMakeLists.txt b/src/ipc/dbus/CMakeLists.txt index b912b55b..4744ab55 100644 --- a/src/ipc/dbus/CMakeLists.txt +++ b/src/ipc/dbus/CMakeLists.txt @@ -3,6 +3,8 @@ find_package(Qt5DBus QUIET) if(Qt5DBus_FOUND) + set_target_properties(Qt5::DBus PROPERTIES IMPORTED_GLOBAL TRUE) + if(WIN32) set(GENERATED_FILE_PATH ${CMAKE_CURRENT_BINARY_DIR}/facelift_generated/FaceliftIPCLibDBus) # There is a weird issue on Windows related to the MOC if the generated files are outside of ${CMAKE_CURRENT_BINARY_DIR} else() @@ -35,8 +37,7 @@ if(Qt5DBus_FOUND) ${GENERATED_FILE_PATH}/ipc/*.h ${GENERATED_FILE_PATH}/ipc_dbus/*.h ${GENERATED_FILE_PATH}/types/*.h - LINK_LIBRARIES Qt5::DBus - MONOLITHIC_LINK_LIBRARIES FaceliftIPCCommonLib FaceliftIPCLocalLib + LINK_LIBRARIES Qt5::DBus FaceliftIPCCommonLib FaceliftIPCLocalLib PUBLIC_HEADER_BASE_PATH ${CMAKE_CURRENT_SOURCE_DIR} PUBLIC_DEFINITIONS DBUS_IPC_ENABLED diff --git a/src/ipc/ipc-common/CMakeLists.txt b/src/ipc/ipc-common/CMakeLists.txt index 07340855..b35e0412 100644 --- a/src/ipc/ipc-common/CMakeLists.txt +++ b/src/ipc/ipc-common/CMakeLists.txt @@ -31,6 +31,6 @@ facelift_add_library(FaceliftIPCCommonLib IPCAdapterFactoryManager.h IPCServiceAdapter.h Registry.h - MONOLITHIC_LINK_LIBRARIES FaceliftModelLib FaceliftCommonLib + LINK_LIBRARIES FaceliftModelLib FaceliftCommonLib MONOLITHIC_SUPPORTED ) diff --git a/src/ipc/local/CMakeLists.txt b/src/ipc/local/CMakeLists.txt index 81609840..cffdafe9 100644 --- a/src/ipc/local/CMakeLists.txt +++ b/src/ipc/local/CMakeLists.txt @@ -8,7 +8,7 @@ facelift_add_library(FaceliftIPCLocalLib LocalIPCRegistry.h LocalIPC-serialization.h LocalIPCServiceAdapter.h - MONOLITHIC_LINK_LIBRARIES FaceliftIPCCommonLib FaceliftModelLib + LINK_LIBRARIES FaceliftIPCCommonLib FaceliftModelLib PUBLIC_HEADER_BASE_PATH ${CMAKE_CURRENT_SOURCE_DIR} MONOLITHIC_SUPPORTED ) diff --git a/src/model/CMakeLists.txt b/src/model/CMakeLists.txt index d9b8ffec..7c367e4e 100644 --- a/src/model/CMakeLists.txt +++ b/src/model/CMakeLists.txt @@ -29,7 +29,6 @@ facelift_add_library(FaceliftModelLib FaceliftImplementationBase.h FaceliftQMLUtils.h AsyncAnswer.h - LINK_LIBRARIES Qt5::Qml Qt5::Quick - MONOLITHIC_LINK_LIBRARIES FaceliftCommonLib + LINK_LIBRARIES Qt5::Qml Qt5::Quick FaceliftCommonLib MONOLITHIC_SUPPORTED )