diff --git a/CMakeLists.txt b/CMakeLists.txt index 16d575487f63dc628fad2393171ceb20240bd750..c09a6548121dbd042b055546c39d2e3beddac6a3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -85,10 +85,10 @@ add_library(CrestApiLib SHARED ${SOURCES} ${HEADERS}) 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 + $<INSTALL_INTERFACE:include> # for client in install mode ) -install(TARGETS CrestApiLib EXPORT CrestApiLib DESTINATION lib) -install(EXPORT CrestApiLib DESTINATION lib) +install(TARGETS CrestApiLib EXPORT CrestApiLib DESTINATION lib/cmake/CrestApiLib) +install(EXPORT CrestApiLib NAMESPACE CrestApiLib:: DESTINATION lib/cmake/CrestApiLib) add_executable(crest_example_server ${SOURCES_EXAMPLE_SRV} ${HEADERS}) target_link_libraries(crest_example_server CrestApiLib stdc++) diff --git a/CrestApiLibConfig.cmake.in b/CrestApiLibConfig.cmake.in index c4e2e0f3b297555c97da36c340c65c63eda40940..3acacc3a8efa641c44e1ad3482494c89ae6e7b8a 100644 --- a/CrestApiLibConfig.cmake.in +++ b/CrestApiLibConfig.cmake.in @@ -5,27 +5,21 @@ # after installation @PACKAGE_INIT@ +# Find dependencies +include(CMakeFindDependencyMacro) +find_dependency(CURL) +find_dependency(nlohmann_json) +find_dependency(Boost COMPONENTS system thread filesystem unit_test_framework regex) + +# Use the cmake generated target +include("${CMAKE_CURRENT_LIST_DIR}/CrestApiLib.cmake") + # - 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 "${PACKAGE_PREFIX_DIR}/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 "${PACKAGE_PREFIX_DIR}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}CrestApiLib${CMAKE_SHARED_LIBRARY_SUFFIX}" -) - -# 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 - find_dependency(CURL REQUIRED) -endif() - -include("${CMAKE_CURRENT_LIST_DIR}/../../CrestApiLib.cmake") +set(CrestApiLib_FOUND TRUE)