From a32d7e2a7db0a3a1e522cd357be906c9e28377cc Mon Sep 17 00:00:00 2001 From: simutisernestas <35775651+simutisernestas@users.noreply.github.com> Date: Fri, 8 Apr 2022 10:06:40 +0200 Subject: [PATCH] cmake package config (#93) --- CMakeLists.txt | 2 +- src/libdbcppp/CMakeLists.txt | 41 ++++++++++++++++++++--- src/libdbcppp/cmake/libdbcpppConfig.cmake | 1 + 3 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 src/libdbcppp/cmake/libdbcpppConfig.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index e0917d27..d905b291 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,7 +45,7 @@ target_sources("libxmlmm" ) install( - TARGETS "libxmlmm" + TARGETS "libxmlmm" "LibXml2" EXPORT ${PROJECT_NAME}Targets DESTINATION ${CMAKE_INSTALL_LIBDIR}) install( DIRECTORY "libxmlmm" diff --git a/src/libdbcppp/CMakeLists.txt b/src/libdbcppp/CMakeLists.txt index 9f541b44..1365bf03 100644 --- a/src/libdbcppp/CMakeLists.txt +++ b/src/libdbcppp/CMakeLists.txt @@ -34,19 +34,52 @@ file(GLOB src target_sources(${PROJECT_NAME} PRIVATE ${header} - PUBLIC ${header_interface} + PRIVATE ${header_interface} PRIVATE ${src} DBCX3AdaptStructs.inl ) +set_target_properties(${PROJECT_NAME} PROPERTIES PUBLIC_HEADER "${header_interface}") include(GenerateExportHeader) generate_export_header(${PROJECT_NAME}) # install install( - TARGETS ${PROJECT_NAME} - DESTINATION ${CMAKE_INSTALL_LIBDIR}) + TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}Targets + DESTINATION ${CMAKE_INSTALL_LIBDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dbcppp) install( FILES - $ + $ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dbcppp) +include(CMakePackageConfigHelpers) +write_basic_package_version_file( + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}ConfigVersion.cmake" + VERSION ${Upstream_VERSION} + COMPATIBILITY AnyNewerVersion +) + +export(EXPORT ${PROJECT_NAME}Targets + FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}Targets.cmake" +) +configure_file(cmake/${PROJECT_NAME}Config.cmake + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}Config.cmake" + @ONLY +) + +set(ConfigPackageLocation lib/cmake/${PROJECT_NAME}) +install(EXPORT ${PROJECT_NAME}Targets + FILE + ${PROJECT_NAME}Targets.cmake + DESTINATION + ${ConfigPackageLocation} +) +install( + FILES + cmake/${PROJECT_NAME}Config.cmake + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}ConfigVersion.cmake" + DESTINATION + ${ConfigPackageLocation} + COMPONENT + Devel +) \ No newline at end of file diff --git a/src/libdbcppp/cmake/libdbcpppConfig.cmake b/src/libdbcppp/cmake/libdbcpppConfig.cmake new file mode 100644 index 00000000..814f20b0 --- /dev/null +++ b/src/libdbcppp/cmake/libdbcpppConfig.cmake @@ -0,0 +1 @@ +include("${CMAKE_CURRENT_LIST_DIR}/libdbcpppTargets.cmake") \ No newline at end of file