From 6af06eecf8f90e62aecf7251a1a14ffe445455b6 Mon Sep 17 00:00:00 2001 From: Lectem Date: Sat, 8 Jun 2024 01:28:03 +0200 Subject: [PATCH] Install CMake config file to allow `find_package(StormLib)` and linking to `StormLib::storm` Users will now be able to do: ```cmake find_package(StormLib CONFIG REQUIRED) target_link_libraries(SomeTarget PRIVATE StormLib::storm) ``` Note that vcpkg now relies on this CMakeLists.txt, so if this is merged and a new version is released it will make it even easier to consume the library as it automatically detects config files. --- CMakeLists.txt | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d99ba20..4758091 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -334,8 +334,9 @@ if(WIN32) endif() target_link_libraries(${LIBRARY_NAME} ${LINK_LIBS}) +add_library(${PROJECT_NAME}::${LIBRARY_NAME} ALIAS ${LIBRARY_NAME}) # Allow users to link StormLib::storm when using add_subdirectory target_compile_definitions(${LIBRARY_NAME} INTERFACE STORMLIB_NO_AUTO_LINK) #CMake will take care of the linking -target_include_directories(${LIBRARY_NAME} PUBLIC src/) +target_include_directories(${LIBRARY_NAME} PUBLIC $) set_target_properties(${LIBRARY_NAME} PROPERTIES PUBLIC_HEADER "src/StormLib.h;src/StormPort.h") if(BUILD_SHARED_LIBS) message(STATUS "Linking against dependent libraries dynamically") @@ -358,12 +359,15 @@ endif() if (NOT STORM_SKIP_INSTALL) install(TARGETS ${LIBRARY_NAME} - RUNTIME DESTINATION bin - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib - FRAMEWORK DESTINATION /Library/Frameworks - PUBLIC_HEADER DESTINATION include - INCLUDES DESTINATION include) + EXPORT ${PROJECT_NAME}Config + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib + FRAMEWORK DESTINATION /Library/Frameworks + PUBLIC_HEADER DESTINATION include + INCLUDES DESTINATION include) + + install(EXPORT ${PROJECT_NAME}Config NAMESPACE ${PROJECT_NAME}:: DESTINATION share/${PROJECT_NAME}) #CPack configurtion SET(CPACK_GENERATOR "DEB" "RPM")