Skip to content
Snippets Groups Projects
Unverified Commit b57f9dc9 authored by Dietrich Rothe's avatar Dietrich Rothe Committed by GitHub
Browse files

chore: modernise cmake (#287)

* use imported targets where possible

also for the export

* cmake: remove explicit definitions for downstream projects

* increase minor version

will be done for all projects using cmake-exports

* remove --export-dynamic linker flag

because it makes no sense for libs
parent adcb1fd0
No related branches found
No related tags found
No related merge requests found
PROJECT(ChimeraTK-ApplicationCore) PROJECT(ChimeraTK-ApplicationCore)
cmake_minimum_required(VERSION 2.8) cmake_minimum_required(VERSION 3.16)
include(cmake/add_dependency.cmake)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules)
set(${PROJECT_NAME}_MAJOR_VERSION 03) set(${PROJECT_NAME}_MAJOR_VERSION 03)
set(${PROJECT_NAME}_MINOR_VERSION 00) set(${PROJECT_NAME}_MINOR_VERSION 01)
set(${PROJECT_NAME}_PATCH_VERSION 02) set(${PROJECT_NAME}_PATCH_VERSION 00)
include(cmake/set_version_numbers.cmake) include(cmake/set_version_numbers.cmake)
option(BUILD_TESTS "Build tests." ON) option(BUILD_TESTS "Build tests." ON)
# Find the ControlSystemAdapter # Find the ControlSystemAdapter
add_dependency(ChimeraTK-ControlSystemAdapter 02.04 REQUIRED) FIND_PACKAGE(ChimeraTK-ControlSystemAdapter 02.06 REQUIRED)
# Find the DeviceAccess # Find the DeviceAccess
# Although all the linker flags are added again, the include path might be different FIND_PACKAGE(ChimeraTK-DeviceAccess 03.08 REQUIRED)
# if the libraries are installed in different directories for development purposes.
add_dependency(ChimeraTK-DeviceAccess 03.03 REQUIRED)
# Find the XML parser library libxml++ # Find the XML parser library libxml++
FIND_PACKAGE(PkgConfig REQUIRED) FIND_PACKAGE(PkgConfig REQUIRED)
set(LIBXML++_VERSION "libxml++-2.6") set(LIBXML++_VERSION "libxml++-2.6")
PKG_CHECK_MODULES(LibXML++ REQUIRED ${LIBXML++_VERSION}) PKG_CHECK_MODULES(LibXML++ REQUIRED IMPORTED_TARGET ${LIBXML++_VERSION})
PKG_CHECK_MODULES(glib REQUIRED glib-2.0) PKG_CHECK_MODULES(glib REQUIRED IMPORTED_TARGET glib-2.0)
include_directories(SYSTEM ${glib_INCLUDE_DIRS} ${LibXML++_INCLUDE_DIRS})
# Find BOOST filesystem # Find BOOST filesystem
# Note: we need to search this after looking for the unit_test_framework, since we must not link against the # Note: we need to search this before looking for the unit_test_framework, since we must not link against the
# unit_test_framework library (use header-only) # unit_test_framework library (use header-only)
FIND_PACKAGE(Boost COMPONENTS filesystem date_time chrono system thread REQUIRED) FIND_PACKAGE(Boost COMPONENTS filesystem date_time chrono system thread REQUIRED)
...@@ -36,21 +31,16 @@ include(cmake/set_default_build_to_release.cmake) ...@@ -36,21 +31,16 @@ include(cmake/set_default_build_to_release.cmake)
include(cmake/set_default_flags.cmake) include(cmake/set_default_flags.cmake)
include(cmake/enable_code_coverage_report.cmake) include(cmake/enable_code_coverage_report.cmake)
# linker flags
if(NOT APPLE)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--export-dynamic")
endif()
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${ChimeraTK-ControlSystemAdapter_LINK_FLAGS}")
include_directories(${CMAKE_SOURCE_DIR}/include) include_directories(${CMAKE_SOURCE_DIR}/include)
file(GLOB headers "${CMAKE_SOURCE_DIR}/include/*.h") file(GLOB headers "${CMAKE_SOURCE_DIR}/include/*.h")
set(${PROJECT_NAME}_INCLUDE_DIRS ${${PROJECT_NAME}_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}/include/ ${CMAKE_SOURCE_DIR}/Modules/include/)
aux_source_directory(${CMAKE_SOURCE_DIR}/src library_sources) aux_source_directory(${CMAKE_SOURCE_DIR}/src library_sources)
set(${PROJECT_NAME}_INCLUDE_DIRS ${${PROJECT_NAME}_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}/include/ )
# add generic modules # add generic modules
include_directories(${CMAKE_SOURCE_DIR}/Modules/include) include_directories(${CMAKE_SOURCE_DIR}/Modules/include)
file(GLOB module_headers "${CMAKE_SOURCE_DIR}/Modules/include/*.h") file(GLOB module_headers "${CMAKE_SOURCE_DIR}/Modules/include/*.h")
aux_source_directory(${CMAKE_SOURCE_DIR}/Modules/src library_sources) set(${PROJECT_NAME}_INCLUDE_DIRS ${${PROJECT_NAME}_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}/Modules/include/)
aux_source_directory(${CMAKE_SOURCE_DIR}/Modules/src library_module_sources)
MACRO( COPY_MAPPING_FILES ) MACRO( COPY_MAPPING_FILES )
foreach( FILE_TO_COPY test.xlmap test.dmap ) foreach( FILE_TO_COPY test.xlmap test.dmap )
...@@ -66,16 +56,16 @@ if(BUILD_TESTS) ...@@ -66,16 +56,16 @@ if(BUILD_TESTS)
endif() endif()
# C++ library # C++ library
add_library(${PROJECT_NAME} SHARED ${library_sources} ${headers} ${module_headers}) add_library(${PROJECT_NAME} SHARED ${library_sources} ${library_module_sources} ${headers} ${module_headers})
set_target_properties(${PROJECT_NAME} PROPERTIES VERSION ${${PROJECT_NAME}_FULL_LIBRARY_VERSION} set_target_properties(${PROJECT_NAME} PROPERTIES VERSION ${${PROJECT_NAME}_FULL_LIBRARY_VERSION}
SOVERSION ${${PROJECT_NAME}_SOVERSION}) SOVERSION ${${PROJECT_NAME}_SOVERSION})
set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "${ChimeraTK-ControlSystemAdapter_LINK_FLAGS}") # exported includes are all under ${CMAKE_INSTALL_PREFIX}/include
target_link_libraries(${PROJECT_NAME} ${ChimeraTK-ControlSystemAdapter_LIBRARIES} target_include_directories(${PROJECT_NAME} INTERFACE "$<INSTALL_INTERFACE:include>")
${Boost_LIBRARIES} target_link_libraries(${PROJECT_NAME}
pthread # put ControlSystemAdapter public since implicit dep DeviceAccess must be public
${LibXML++_LIBRARIES} PUBLIC ChimeraTK::ChimeraTK-ControlSystemAdapter
${glib_LIBRARIES} PUBLIC ${Boost_LIBRARIES}
${HDF5_LIBRARIES}) PRIVATE pthread PkgConfig::LibXML++ PkgConfig::glib ${HDF5_LIBRARIES})
# do not remove runtime path of the library when installing # do not remove runtime path of the library when installing
set_property(TARGET ${PROJECT_NAME} PROPERTY INSTALL_RPATH_USE_LINK_PATH TRUE) set_property(TARGET ${PROJECT_NAME} PROPERTY INSTALL_RPATH_USE_LINK_PATH TRUE)
...@@ -87,7 +77,10 @@ include(cmake/enable_doxygen_documentation.cmake) ...@@ -87,7 +77,10 @@ include(cmake/enable_doxygen_documentation.cmake)
include(cmake/enable_code_style_check.cmake) include(cmake/enable_code_style_check.cmake)
# Install the library and the executables # Install the library and the executables
install( TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin LIBRARY DESTINATION lib ) install( TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}Targets
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib )
# all include files go into include/PROJECT_NAME # all include files go into include/PROJECT_NAME
# The exclusion of ${PROJECT_NAME} prevents the recursive installation of the files just being installed. # The exclusion of ${PROJECT_NAME} prevents the recursive installation of the files just being installed.
...@@ -97,11 +90,8 @@ install(DIRECTORY ${${PROJECT_NAME}_INCLUDE_DIRS} DESTINATION include/ChimeraTK/ ...@@ -97,11 +90,8 @@ install(DIRECTORY ${${PROJECT_NAME}_INCLUDE_DIRS} DESTINATION include/ChimeraTK/
PATTERN ".svn" EXCLUDE PATTERN ".svn" EXCLUDE
PATTERN "${PROJECT_NAME}" EXCLUDE) PATTERN "${PROJECT_NAME}" EXCLUDE)
set(${PROJECT_NAME}_INCLUDE_DIRS "${CMAKE_INSTALL_PREFIX}/include") # we need the public dependencies so create_cmake_config_files can find them as implicit dependencies
set(${PROJECT_NAME}_LIBRARIES "${ChimeraTK-ControlSystemAdapter_LIBRARIES}") list(APPEND ${PROJECT_NAME}_PUBLIC_DEPENDENCIES "Boost COMPONENTS system thread chrono filesystem date_time;ChimeraTK-ControlSystemAdapter")
set(${PROJECT_NAME}_LIBRARY_DIRS "${CMAKE_INSTALL_PREFIX}/lib") # we support our cmake EXPORTS as imported targets
set(${PROJECT_NAME}_CXX_FLAGS "${ChimeraTK-ControlSystemAdapter_CXX_FLAGS}") set(PROVIDES_EXPORTED_TARGETS 1)
set(${PROJECT_NAME}_LINK_FLAGS "${ChimeraTK-ControlSystemAdapter_LINK_FLAGS}")
list(APPEND ${PROJECT_NAME}_PUBLIC_DEPENDENCIES "Boost COMPONENTS system thread chrono filesystem date_time atomic")
include(${CMAKE_SOURCE_DIR}/cmake/create_cmake_config_files.cmake) include(${CMAKE_SOURCE_DIR}/cmake/create_cmake_config_files.cmake)
...@@ -8,8 +8,8 @@ foreach( testExecutableSrcFile ${testExecutables}) ...@@ -8,8 +8,8 @@ foreach( testExecutableSrcFile ${testExecutables})
get_filename_component(executableName ${testExecutableSrcFile} NAME_WE) get_filename_component(executableName ${testExecutableSrcFile} NAME_WE)
add_executable(${executableName} ${testExecutableSrcFile} ${test_headers}) add_executable(${executableName} ${testExecutableSrcFile} ${test_headers})
# do not link against the boost unit test library, the tests are not written for it! # do not link against the boost unit test library, the tests are not written for it!
target_link_libraries(${executableName} ${PROJECT_NAME} ${ChimeraTK-ControlSystemAdapter_LIBRARIES} ${HDF5_LIBRARIES}) target_link_libraries(${executableName}
set_target_properties(${executableName} PROPERTIES LINK_FLAGS "-Wl,-rpath,${PROJECT_BINARY_DIR} ${Boost_LINK_FLAGS} ${ChimeraTK-ControlSystemAdapter_LINK_FLAGS}") PRIVATE ${PROJECT_NAME} ChimeraTK::ChimeraTK-ControlSystemAdapter PkgConfig::LibXML++ ${HDF5_LIBRARIES})
add_test(${executableName} ${executableName}) add_test(${executableName} ${executableName})
endforeach( testExecutableSrcFile ) endforeach( testExecutableSrcFile )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment