From 5f3c39b657b20f42018d5abd572c207c0a471c93 Mon Sep 17 00:00:00 2001 From: Lars Melchior Date: Tue, 14 Apr 2020 12:08:30 +0200 Subject: [PATCH] add PackageProject.cmake as a CPM dependency --- CMakeLists.txt | 18 +++++++++++++++--- cmake/Config.cmake.in | 5 ----- cmake/packaging.cmake | 43 ------------------------------------------- 3 files changed, 15 insertions(+), 51 deletions(-) delete mode 100644 cmake/Config.cmake.in delete mode 100644 cmake/packaging.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 136a2b9..adeebf1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,7 @@ FILE(GLOB_RECURSE sources "${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp") # ---- Add dependencies via CPM (if required) ---- # see https://github.com/TheLartians/CPM.cmake for more info -# include(cmake/CPM.cmake) +include(cmake/CPM.cmake) # CPMAddPackage( # NAME cxxopts @@ -56,6 +56,18 @@ target_include_directories(Greeter ) # ---- Create an installable target ---- -# this allows users install and find the library via `find_package(Greeter)`. +# this allows users to install and find the library via `find_package()`. -include(cmake/packaging.cmake) +CPMAddPackage( + NAME PackageProject.cmake + GITHUB_REPOSITORY TheLartians/PackageProject.cmake + VERSION 1.0 +) + +packageProject( + NAME ${PROJECT_NAME} + VERSION ${PROJECT_VERSION} + BINARY_DIR ${PROJECT_BINARY_DIR} + INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include + INCLUDE_DESTINATION include/${PROJECT_NAME}-${PROJECT_VERSION} +) diff --git a/cmake/Config.cmake.in b/cmake/Config.cmake.in deleted file mode 100644 index d9f8a9c..0000000 --- a/cmake/Config.cmake.in +++ /dev/null @@ -1,5 +0,0 @@ -@PACKAGE_INIT@ - -include(CMakeFindDependencyMacro) -include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") -check_required_components("@PROJECT_NAME@") diff --git a/cmake/packaging.cmake b/cmake/packaging.cmake deleted file mode 100644 index bd0fdc7..0000000 --- a/cmake/packaging.cmake +++ /dev/null @@ -1,43 +0,0 @@ -include(CMakePackageConfigHelpers) - -write_basic_package_version_file( - "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" - VERSION ${PROJECT_VERSION} - COMPATIBILITY AnyNewerVersion -) - -install( - TARGETS ${PROJECT_NAME} - EXPORT ${PROJECT_NAME}Targets - LIBRARY DESTINATION lib/${PROJECT_NAME}-${PROJECT_VERSION} COMPONENT Runtime - ARCHIVE DESTINATION lib/${PROJECT_NAME}-${PROJECT_VERSION} COMPONENT Development - RUNTIME DESTINATION bin/${PROJECT_NAME}-${PROJECT_VERSION} COMPONENT Runtime - PUBLIC_HEADER DESTINATION include/${PROJECT_NAME}-${PROJECT_VERSION} COMPONENT Development - BUNDLE DESTINATION bin COMPONENT Runtime -) - -include(CMakePackageConfigHelpers) - -configure_package_config_file( - "${CMAKE_CURRENT_LIST_DIR}/Config.cmake.in" - "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" - INSTALL_DESTINATION lib/cmake/${PROJECT_NAME}-${PROJECT_VERSION} -) - -install( - EXPORT ${PROJECT_NAME}Targets - DESTINATION lib/cmake/${PROJECT_NAME}-${PROJECT_VERSION} -) - -install( - FILES - "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" - "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" - DESTINATION - lib/cmake/${PROJECT_NAME}-${PROJECT_VERSION} -) - -install( - DIRECTORY ${PROJECT_SOURCE_DIR}/include/ - DESTINATION include/${PROJECT_NAME}-${PROJECT_VERSION} -)