From c695721b4f7d3ef4b814beb54c493e3fb62a82d0 Mon Sep 17 00:00:00 2001 From: DNKpp Date: Sun, 6 Oct 2024 02:15:07 +0200 Subject: [PATCH] env: add basic installing support --- CMakeLists.txt | 17 +++++-- cmake/InstallRules.cmake | 47 ++++++++++++++++++++ cmake/mimic++-configuration-options.cmake | 10 ++--- cmake/mimicpp-config.cmake.in | 5 +++ test/adapter-tests/boost-test/CMakeLists.txt | 9 ++-- test/adapter-tests/gtest/CMakeLists.txt | 2 + 6 files changed, 78 insertions(+), 12 deletions(-) create mode 100644 cmake/InstallRules.cmake create mode 100644 cmake/mimicpp-config.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 6185e289a..843323392 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,16 +5,21 @@ include(get_cpm) project( mimicpp - LANGUAGES CXX - VERSION 2 + LANGUAGES CXX + VERSION 2 + DESCRIPTION "A modern and (mostly) macro free mocking-framework" + HOMEPAGE_URL "https://github.com/DNKpp/mimicpp" ) +include(GNUInstallDirs) + add_library(mimicpp INTERFACE) add_library(mimicpp::mimicpp ALIAS mimicpp) target_include_directories( mimicpp INTERFACE - "include" + "$" + "$" ) target_compile_options( @@ -70,3 +75,9 @@ if (MIMICPP_ENABLE_AMALGAMATE_HEADERS) add_subdirectory("tools/amalgamate-headers") endif() + +if(NOT CMAKE_SKIP_INSTALL_RULES) + + include(InstallRules) + +endif() diff --git a/cmake/InstallRules.cmake b/cmake/InstallRules.cmake new file mode 100644 index 000000000..a0808be96 --- /dev/null +++ b/cmake/InstallRules.cmake @@ -0,0 +1,47 @@ +# many thanks to jeremy rifkin, from which I took most of the following code +# https://github.com/jeremy-rifkin/libassert/blob/main/cmake/InstallRules.cmake + +include(CMakePackageConfigHelpers) + +set(MIMICPP_LIB_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/mimipp") +set(MIMICPP_CMAKE_INSTALL_DIR "${MIMICPP_LIB_INSTALL_DIR}/cmake") +set(MIMICPP_INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/mimipp") + +write_basic_package_version_file( + "mimicpp-version.cmake" + VERSION ${PROJECT_VERSION} + COMPATIBILITY AnyNewerVersion + ARCH_INDEPENDENT +) + +configure_package_config_file( + "${PROJECT_SOURCE_DIR}/cmake/mimicpp-config.cmake.in" + "mimicpp-config.cmake" + INSTALL_DESTINATION "${MIMICPP_CMAKE_INSTALL_DIR}" +) + +install( + TARGETS mimicpp + EXPORT mimicpp-targets + PUBLIC_HEADER DESTINATION "${MIMICPP_INCLUDE_INSTALL_DIR}" +) + +install( + DIRECTORY "include/" + TYPE INCLUDE + FILES_MATCHING PATTERN "*.hpp" +) + +install( + EXPORT mimicpp-targets + FILE mimicpp-targets.cmake + DESTINATION "${MIMICPP_CMAKE_INSTALL_DIR}" + NAMESPACE mimipp:: +) + +install( + FILES + "${PROJECT_BINARY_DIR}/mimicpp-config.cmake" + "${PROJECT_BINARY_DIR}/mimicpp-version.cmake" + DESTINATION "${MIMICPP_CMAKE_INSTALL_DIR}" +) diff --git a/cmake/mimic++-configuration-options.cmake b/cmake/mimic++-configuration-options.cmake index 3d36ed826..02f68960e 100644 --- a/cmake/mimic++-configuration-options.cmake +++ b/cmake/mimic++-configuration-options.cmake @@ -52,11 +52,11 @@ OPTION(MIMICPP_CONFIG_EXPERIMENTAL_UNICODE_STR_MATCHER "When enabled, all case-i if (MIMICPP_CONFIG_EXPERIMENTAL_UNICODE_STR_MATCHER) CPMAddPackage( - NAME cpp-unicodelib - GITHUB_REPOSITORY yhirose/cpp-unicodelib - GIT_TAG 797b1f0f1592ce13afabf3576f51ef26db5e884d - DOWNLOAD_ONLY YES - SYSTEM YES + NAME cpp-unicodelib + GITHUB_REPOSITORY yhirose/cpp-unicodelib + GIT_TAG 797b1f0f1592ce13afabf3576f51ef26db5e884d + DOWNLOAD_ONLY YES + SYSTEM YES ) if (cpp-unicodelib_ADDED) diff --git a/cmake/mimicpp-config.cmake.in b/cmake/mimicpp-config.cmake.in new file mode 100644 index 000000000..987176ddb --- /dev/null +++ b/cmake/mimicpp-config.cmake.in @@ -0,0 +1,5 @@ +@PACKAGE_INIT@ + +set(mimicpp_VERSION "@PROJECT_VERSION@") +include("${CMAKE_CURRENT_LIST_DIR}/mimicpp-targets.cmake") +check_required_components("@PROJECT_NAME@") diff --git a/test/adapter-tests/boost-test/CMakeLists.txt b/test/adapter-tests/boost-test/CMakeLists.txt index 6fa59d6da..38ce2a613 100644 --- a/test/adapter-tests/boost-test/CMakeLists.txt +++ b/test/adapter-tests/boost-test/CMakeLists.txt @@ -13,10 +13,11 @@ else() endif() CPMAddPackage( - NAME Boost - URL ${BOOST_ARCHIVE_URL} - VERSION 1.85.0 - SYSTEM YES + NAME Boost + URL ${BOOST_ARCHIVE_URL} + VERSION 1.85.0 + EXCLUDE_FROM_ALL YES + SYSTEM YES ) target_link_libraries( diff --git a/test/adapter-tests/gtest/CMakeLists.txt b/test/adapter-tests/gtest/CMakeLists.txt index 22e6c9e46..abda9b695 100644 --- a/test/adapter-tests/gtest/CMakeLists.txt +++ b/test/adapter-tests/gtest/CMakeLists.txt @@ -10,6 +10,8 @@ CPMAddPackage( NAME GTest GITHUB_REPOSITORY "google/googletest" GIT_TAG "v1.15.2" + EXCLUDE_FROM_ALL YES + SYSTEM YES OPTIONS "gtest_force_shared_crt ON" )