From 34b426da4cd8a41f29b1a962f3890e71c15f415b Mon Sep 17 00:00:00 2001 From: mavogel <mavogel@cern.ch> Date: Tue, 3 Sep 2024 16:18:51 +0200 Subject: [PATCH 1/6] Testing tag for tdaq-common --- CrestApiLibConfig.cmake.in | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/CrestApiLibConfig.cmake.in b/CrestApiLibConfig.cmake.in index 7f64c03..4eba1a5 100644 --- a/CrestApiLibConfig.cmake.in +++ b/CrestApiLibConfig.cmake.in @@ -1,15 +1,25 @@ -@PACKAGE_INIT@ +# - Check if the user provided a path to CrestApiLib_INCLUDE_DIRS. +# If not, set it to the correct include directory. +if(NOT CrestApiLib_INCLUDE_DIRS) + set(CrestApiLib_INCLUDE_DIRS "@CMAKE_INSTALL_PREFIX@/include") +endif() -include(CMakeFindDependencyMacro) -include(FindPackageHandleStandardArgs) +# Create a CrestApiLib::CrestApiLib target to be used by consumers of CrestApiLib +add_library(CrestApiLib::CrestApiLib SHARED IMPORTED) +set_target_properties(CrestApiLib::CrestApiLib PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${CrestApiLib_INCLUDE_DIRS}" + IMPORTED_LOCATION "@CMAKE_INSTALL_PREFIX@/lib/libCrestApiLib.so" +) -# Set the include directories for the project -set(CrestApiLib_INCLUDE_DIRS "@CMAKE_INSTALL_PREFIX@/include/CrestApi-@PROJECT_VERSION@") +# Set variables to help consumers locate CrestApiLib library and headers +set(CrestApiLib_FOUND TRUE) +set(CrestApiLib_LIBRARIES CrestApiLib::CrestApiLib) -# Set the library directories and targets -set(CrestApiLib_LIBRARIES "@CMAKE_INSTALL_PREFIX@/lib/CrestApiLib/@PROJECT_VERSION@/${CMAKE_SHARED_LIBRARY_PREFIX}CrestApiLib${CMAKE_SHARED_LIBRARY_SUFFIX}") -message(STATUS "Found CrestApiLib includes and lib : ${CrestApiLib_INCLUDE_DIRS} ${CrestApiLib_LIBRARIES}") +# Provide configuration results +include(CMakeFindDependencyMacro) +if(NOT TARGET CURL::CURL) # This condition is optional and can be modified based on your dependencies + find_dependency(CURL REQUIRED) +endif() -# Provide the directory for includes -include_directories(${CrestApiLib_INCLUDE_DIRS}) +include("${CMAKE_CURRENT_LIST_DIR}/../../CrestApiLib.cmake") -- GitLab From 5620dd5993433c76814caefb424f2987ede279b9 Mon Sep 17 00:00:00 2001 From: mavogel <mavogel@cern.ch> Date: Tue, 3 Sep 2024 22:55:40 +0200 Subject: [PATCH 2/6] First version for tdaq-common integration --- CMakeLists.txt | 88 ++++++++++++++------------------------------------ 1 file changed, 25 insertions(+), 63 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bcda6a6..4bc464f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,14 +6,7 @@ # Then use cmake from a build directory : cmake .. # Set the name of the package. cmake_minimum_required(VERSION 3.10) -project( CrestApiLib VERSION 5.0) # The name of the package - -# Create version header file (version.h) -configure_file( - "${PROJECT_SOURCE_DIR}/CrestApi/version.h.in" - "${PROJECT_BINARY_DIR}/version.h" -) - +project( CrestApiLib ) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) @@ -30,8 +23,7 @@ else() message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.") endif() -# External dependencies. -# CURL + find_package(CURL REQUIRED) if(CURL_FOUND) @@ -47,7 +39,6 @@ else() FetchContent_MakeAvailable(CURL) endif() -# BOOST find_package(Boost COMPONENTS system thread filesystem unit_test_framework regex REQUIRED) IF (Boost_FOUND) @@ -55,13 +46,15 @@ IF (Boost_FOUND) ADD_DEFINITIONS( "-DHAS_BOOST" ) ENDIF() -# NLOHMANN_JSON -find_package(nlohmann_json 3.2.0 REQUIRED) - SET(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} ${Boost_INCLUDE_DIR}) SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} ../build/CrestApi) -# Set the path to the headers and sources + +# External dependencies. +#find_package( CURL ) +#find_package( Boost ) + + set(header_path "./CrestApi") set(HEADERS ${header_path}/CrestApi.h ${header_path}/CrestModel.h @@ -76,21 +69,29 @@ set(HEADERS ${header_path}/CrestApi.h set(SOURCES src/CrestApi.cxx src/CrestRequest.cxx src/CrestApiFs.cxx src/CrestModel.cxx src/CrestContainer.cxx) -# Include the headers and the external libraries include_directories(CrestApi ./ ${Boost_INCLUDE_DIRS}) - -# Set the sources for the examples and tests set (SOURCES_EXAMPLE_FS doc/crest_example_fs.cxx) set (SOURCES_EXAMPLE_SRV doc/crest_example_server.cxx) set (SOURCES_EXAMPLE_FUNC doc/crest_functions_example.cxx) set (SOURCES_TEST test/test-json.cxx) set (SOURCES_BTEST test/CrestApi_test.cxx) -set (SOURCES_CONTAINERTEST doc/crest_condcontainer_example.cxx) set (SOURCES_JSON_TEST test/json_parse.cxx) +if(${CMAKE_INSTALL_PREFIX} STREQUAL "/usr/local") + set(CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/../installed) +endif() + # Component(s) in the package. +set(include_dest "${CMAKE_INSTALL_PREFIX}/include/CrestApi") + add_library(CrestApiLib SHARED ${SOURCES} ${HEADERS}) target_link_libraries(CrestApiLib ${CURL_LIBRARIES} ${Boost_LIBRARIES}) +target_include_directories(CrestApiLib PUBLIC + $<BUILD_INTERFACE:${headers_path}> # for headers when building + $<INSTALL_INTERFACE:${include_dest}> # for client in install mode + ) +install(TARGETS CrestApiLib EXPORT CrestApiLib DESTINATION "${CMAKE_INSTALL_PREFIX}/lib") +install(EXPORT CrestApiLib DESTINATION "${CMAKE_INSTALL_PREFIX}/lib") add_executable(crest_example_server ${SOURCES_EXAMPLE_SRV} ${HEADERS}) target_link_libraries(crest_example_server CrestApiLib stdc++) @@ -107,55 +108,16 @@ add_executable(json_parse ${SOURCES_JSON_TEST} ${HEADERS}) target_link_libraries(json_parse CrestApiLib stdc++) add_executable(crestapi-test ${SOURCES_BTEST} ${HEADERS}) target_link_libraries(crestapi-test CrestApiLib ${Boost_LIBRARIES} stdc++) -add_executable(crestapi-crestcontainer-test ${SOURCES_CONTAINERTEST} ${HEADERS}) -target_link_libraries(crestapi-crestcontainer-test CrestApiLib ${Boost_LIBRARIES} stdc++) # Register the test with ctest enable_testing() add_test(NAME crestapi-test COMMAND crestapi-test) -# Set the properties for the library installation (version, soversion, output name) -set_target_properties(CrestApiLib PROPERTIES - VERSION ${PROJECT_VERSION} # Full version (used in file name for shared libraries) - ## SOVERSION ${PROJECT_VERSION_MAJOR} # ABI version (used for symbolic link) - OUTPUT_NAME "CrestApiLib" # Name with version -) -set(PACKAGE_INCLUDE_INSTALL_DIR "include/CrestApi-${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}") - -include(CMakePackageConfigHelpers) - # Generate the Config.cmake file configure_file(CrestApiLibConfig.cmake.in CrestApiLibConfig.cmake @ONLY) -write_basic_package_version_file( - "${PROJECT_BINARY_DIR}/CrestApiLibConfigVersion.cmake" - VERSION ${PROJECT_VERSION} - COMPATIBILITY AnyNewerVersion -) - -# Set the version for the library -# Install the library to a versioned directory like lib/1.2.3/ - -install(DIRECTORY ${PROJECT_SOURCE_DIR}/CrestApi - DESTINATION include/CrestApi-${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} -) -# Install the library and headers -install(TARGETS CrestApiLib - LIBRARY DESTINATION lib/CrestApiLib/${PROJECT_VERSION} - ARCHIVE DESTINATION lib/CrestApiLib/${PROJECT_VERSION} -) -install(FILES "${PROJECT_BINARY_DIR}/version.h" DESTINATION include/CrestApi-${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}/CrestApi) - -# Create the config file -configure_package_config_file( - "${CMAKE_CURRENT_SOURCE_DIR}/CrestApiLibConfig.cmake.in" - "${CMAKE_CURRENT_BINARY_DIR}/CrestApiLibConfig.cmake" - INSTALL_DESTINATION lib/cmake/CrestApiLib - PATH_VARS PROJECT_VERSION -) -# Install the config and version files -install(FILES - "${CMAKE_CURRENT_BINARY_DIR}/CrestApiLibConfig.cmake" - "${CMAKE_CURRENT_BINARY_DIR}/CrestApiLibConfigVersion.cmake" - DESTINATION lib/cmake/CrestApiLib -) +install(FILES ${HEADERS} DESTINATION "${include_dest}") +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/CrestApiLibConfig.cmake" + DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/cmake/CrestApiLib") + + -- GitLab From 8f785589bbd01a217196e22c839e11eb547ff65f Mon Sep 17 00:00:00 2001 From: mavogel <mavogel@cern.ch> Date: Wed, 4 Sep 2024 11:27:53 +0200 Subject: [PATCH 3/6] Added nlohmann version --- CMakeLists.txt | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4bc464f..33a5360 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,15 +46,12 @@ IF (Boost_FOUND) ADD_DEFINITIONS( "-DHAS_BOOST" ) ENDIF() +# NLOHMANN_JSON +find_package(nlohmann_json 3.2.0 REQUIRED) + SET(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} ${Boost_INCLUDE_DIR}) SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} ../build/CrestApi) - -# External dependencies. -#find_package( CURL ) -#find_package( Boost ) - - set(header_path "./CrestApi") set(HEADERS ${header_path}/CrestApi.h ${header_path}/CrestModel.h -- GitLab From dc5749709f12a44323fc14acfc58118958ce300b Mon Sep 17 00:00:00 2001 From: mavogel <mavogel@cern.ch> Date: Wed, 4 Sep 2024 13:06:35 +0200 Subject: [PATCH 4/6] Linking nlohmann --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 33a5360..526a365 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,7 +82,7 @@ endif() set(include_dest "${CMAKE_INSTALL_PREFIX}/include/CrestApi") add_library(CrestApiLib SHARED ${SOURCES} ${HEADERS}) -target_link_libraries(CrestApiLib ${CURL_LIBRARIES} ${Boost_LIBRARIES}) +target_link_libraries(CrestApiLib ${CURL_LIBRARIES} ${Boost_LIBRARIES} nlohmann_json::nlohmann_json) target_include_directories(CrestApiLib PUBLIC $<BUILD_INTERFACE:${headers_path}> # for headers when building $<INSTALL_INTERFACE:${include_dest}> # for client in install mode -- GitLab From cfd05797b3c2614b7885bb6eda58b1e6dfff112c Mon Sep 17 00:00:00 2001 From: Reiner Hauser <Reiner.Hauser@cern.ch> Date: Thu, 5 Sep 2024 08:36:42 +0200 Subject: [PATCH 5/6] Make installed cmake config file relocatable --- CrestApiLibConfig.cmake.in | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/CrestApiLibConfig.cmake.in b/CrestApiLibConfig.cmake.in index 4eba1a5..ab10bfd 100644 --- a/CrestApiLibConfig.cmake.in +++ b/CrestApiLibConfig.cmake.in @@ -1,21 +1,27 @@ + +# Avoid hard-coding absolute paths +# This calculates ${PACKAGE_PREFIX_DIR} at run-time based on the +# relative locations of the CMAKE_INSTALL_PREFIX and this config file +# after installation +@PACKAGE_INIT@ + # - Check if the user provided a path to CrestApiLib_INCLUDE_DIRS. # If not, set it to the correct include directory. if(NOT CrestApiLib_INCLUDE_DIRS) - set(CrestApiLib_INCLUDE_DIRS "@CMAKE_INSTALL_PREFIX@/include") + set(CrestApiLib_INCLUDE_DIRS "${PACKAGE_PREFIX_DIR}/include") endif() # Create a CrestApiLib::CrestApiLib target to be used by consumers of CrestApiLib add_library(CrestApiLib::CrestApiLib SHARED IMPORTED) set_target_properties(CrestApiLib::CrestApiLib PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${CrestApiLib_INCLUDE_DIRS}" - IMPORTED_LOCATION "@CMAKE_INSTALL_PREFIX@/lib/libCrestApiLib.so" + IMPORTED_LOCATION "${PACKAGE_PREFIX_DIR}/lib/libCrestApiLib.so" ) # Set variables to help consumers locate CrestApiLib library and headers set(CrestApiLib_FOUND TRUE) set(CrestApiLib_LIBRARIES CrestApiLib::CrestApiLib) - # Provide configuration results include(CMakeFindDependencyMacro) if(NOT TARGET CURL::CURL) # This condition is optional and can be modified based on your dependencies -- GitLab From 73e9171f9a4261448b7f52ed11abf663e2de53ec Mon Sep 17 00:00:00 2001 From: Reiner Hauser <Reiner.Hauser@cern.ch> Date: Thu, 5 Sep 2024 09:21:32 +0200 Subject: [PATCH 6/6] Make export config file relocatable Get rid of all absolute path names (by removing $CMAKE_INSTALL_PREFIX path and using relative paths). Use the cmake helper module to generate a relocatable config file that can be consumed by clients. --- CMakeLists.txt | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 526a365..16d5754 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,12 +74,12 @@ set (SOURCES_TEST test/test-json.cxx) set (SOURCES_BTEST test/CrestApi_test.cxx) set (SOURCES_JSON_TEST test/json_parse.cxx) -if(${CMAKE_INSTALL_PREFIX} STREQUAL "/usr/local") +if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/../installed) endif() # Component(s) in the package. -set(include_dest "${CMAKE_INSTALL_PREFIX}/include/CrestApi") +set(include_dest "include/CrestApi") add_library(CrestApiLib SHARED ${SOURCES} ${HEADERS}) target_link_libraries(CrestApiLib ${CURL_LIBRARIES} ${Boost_LIBRARIES} nlohmann_json::nlohmann_json) @@ -87,8 +87,8 @@ target_include_directories(CrestApiLib PUBLIC $<BUILD_INTERFACE:${headers_path}> # for headers when building $<INSTALL_INTERFACE:${include_dest}> # for client in install mode ) -install(TARGETS CrestApiLib EXPORT CrestApiLib DESTINATION "${CMAKE_INSTALL_PREFIX}/lib") -install(EXPORT CrestApiLib DESTINATION "${CMAKE_INSTALL_PREFIX}/lib") +install(TARGETS CrestApiLib EXPORT CrestApiLib DESTINATION lib) +install(EXPORT CrestApiLib DESTINATION lib) add_executable(crest_example_server ${SOURCES_EXAMPLE_SRV} ${HEADERS}) target_link_libraries(crest_example_server CrestApiLib stdc++) @@ -111,10 +111,13 @@ enable_testing() add_test(NAME crestapi-test COMMAND crestapi-test) # Generate the Config.cmake file -configure_file(CrestApiLibConfig.cmake.in CrestApiLibConfig.cmake @ONLY) +include(CMakePackageConfigHelpers) +# Note: INSTALL_DESTINATION is the relative +configure_package_config_file(CrestApiLibConfig.cmake.in CrestApiLibConfig.cmake + INSTALL_DESTINATION lib/cmake/CrestApiLib) install(FILES ${HEADERS} DESTINATION "${include_dest}") install(FILES "${CMAKE_CURRENT_BINARY_DIR}/CrestApiLibConfig.cmake" - DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/cmake/CrestApiLib") + DESTINATION lib/cmake/CrestApiLib) -- GitLab