Skip to content

Commit

Permalink
Improve monolithic build support
Browse files Browse the repository at this point in the history
  • Loading branch information
jacky309 committed May 5, 2020
1 parent 0cc5f04 commit 1e5eb92
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 22 deletions.
15 changes: 12 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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
58 changes: 45 additions & 13 deletions cmake/faceliftMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}")
Expand All @@ -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})
Expand All @@ -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)
Expand All @@ -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)

Expand Down Expand Up @@ -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()


Expand Down
5 changes: 3 additions & 2 deletions src/ipc/dbus/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/ipc/ipc-common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
2 changes: 1 addition & 1 deletion src/ipc/local/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
3 changes: 1 addition & 2 deletions src/model/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

0 comments on commit 1e5eb92

Please sign in to comment.