From b95044abb202838837b0566efc40ae26308a4bb4 Mon Sep 17 00:00:00 2001 From: Martin Willers Date: Mon, 10 May 2021 03:02:08 +0200 Subject: Export cmake config file (#289) Create and install proper CMake *-target.cmake and *-config.cmake files, for use by other CMake-using projects. It installs a file called automotive-dlt-targets.cmake into a common location for such files, namely /lib/cmake/automotive-dlt/automotive-dlt-targets.cmake They can now call find_package(automotive-dlt) and obtain a target called Genivi::dlt that they can link against with target_link_libraries(), by which they automatically gain all necessary attributes, including libdlt's include directories. Signed-off-by: Martin Willers --- src/lib/CMakeLists.txt | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 6d20c64..5a94bef 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -44,8 +44,14 @@ else() message(STATUS "pthread_setname_np API not available on this platform") endif() -target_link_libraries(dlt ${RT_LIBRARY} ${SOCKET_LIBRARY} ${CMAKE_THREAD_LIBS_INIT}) -target_include_directories(dlt PUBLIC ${PROJECT_SOURCE_DIR}/include/dlt ${PROJECT_BINARY_DIR}/include/dlt) +target_link_libraries(dlt ${RT_LIBRARY} ${SOCKET_LIBRARY} Threads::Threads) + +target_include_directories(dlt + PUBLIC + $ + $ + $ +) if(WITH_LIB_SHORT_VERSION) set_target_properties(dlt PROPERTIES VERSION ${PROJECT_VERSION_MAJOR} SOVERSION ${PROJECT_VERSION_MAJOR}) @@ -53,7 +59,11 @@ else() set_target_properties(dlt PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR}) endif() +add_library(Genivi::dlt ALIAS dlt) + install(TARGETS dlt + EXPORT + ${PROJECT_NAME}-targets RUNTIME DESTINATION bin COMPONENT base @@ -63,3 +73,27 @@ install(TARGETS dlt ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/static COMPONENT base) + +# Install *-targets.cmake file +install( + EXPORT ${PROJECT_NAME}-targets + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} + NAMESPACE Genivi:: +) + +# Create *-config.cmake file +include(CMakePackageConfigHelpers) +configure_package_config_file( + ${PROJECT_SOURCE_DIR}/${PROJECT_NAME}-config.cmake.in + ${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} + NO_SET_AND_CHECK_MACRO +) + +# Install *-config.cmake file +install( + FILES + ${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake + DESTINATION + ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} +) -- cgit v1.2.1