diff --git a/CMakeLists.txt b/CMakeLists.txt index 6c1642a..f53f1cc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,18 +4,22 @@ cmake_minimum_required(VERSION 3.23) project( - beman.exemplar # CMake Project Name, which is also the name of the top-level - # targets (e.g., library, executable, etc.). + beman.exemplar DESCRIPTION "A Beman library exemplar" + VERSION 0.0.0 LANGUAGES CXX) +include(CMakePackageConfigHelpers) include(CTest) include(FetchContent) +include(GNUInstallDirs) + +set(TARGETS_EXPORT_NAME ${CMAKE_PROJECT_NAME}Targets) +set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake) if(BUILD_TESTING) enable_testing() - # Fetch GoogleTest FetchContent_Declare( googletest GIT_REPOSITORY https://github.com/google/googletest.git @@ -25,5 +29,19 @@ if(BUILD_TESTING) endif() add_subdirectory(src/beman/exemplar) - add_subdirectory(examples) + +write_basic_package_version_file( + ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}ConfigVersion.cmake + VERSION ${PROJECT_VERSION} + COMPATIBILITY AnyNewerVersion) + +configure_package_config_file( + "cmake/Config.cmake.in" + ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake + INSTALL_DESTINATION ${INSTALL_CONFIGDIR}) + +install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake + ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}ConfigVersion.cmake + DESTINATION ${INSTALL_CONFIGDIR}) diff --git a/README.md b/README.md index aeac13b..b84f73e 100644 --- a/README.md +++ b/README.md @@ -152,9 +152,10 @@ $ cmake -B build -S . -DCMAKE_CXX_STANDARD=20 -- Check for working CXX compiler: /usr/bin/c++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done --- Configuring done (0.1s) +... +-- Configuring done (2.9s) -- Generating done (0.0s) --- Build files have been written to: /path/to/repo/build +-- Build files have been written to: /home/dariusn/git/Beman/exemplar/build # Build beman.exemplar. $ cmake --build build @@ -167,17 +168,17 @@ $ cmake --build build [ 50%] Building CXX object _deps/googletest-build/googletest/CMakeFiles/gtest_main.dir/src/gtest_main.cc.o [ 60%] Linking CXX static library ../../../lib/libgtest_main.a [ 60%] Built target gtest_main -[ 70%] Building CXX object src/beman/exemplar/tests/CMakeFiles/beman.exemplar.Test.dir/identity.t.cpp.o -[ 80%] Linking CXX executable beman.exemplar.Test -[ 80%] Built target beman.exemplar.Test -[ 90%] Building CXX object examples/CMakeFiles/identity_usage.dir/identity_usage.cpp.o -[100%] Linking CXX executable identity_usage -[100%] Built target identity_usage +[ 70%] Building CXX object src/beman/exemplar/CMakeFiles/beman.exemplar.tests.dir/identity.t.cpp.o +[ 80%] Linking CXX executable beman.exemplar.tests +[ 80%] Built target beman.exemplar.tests +[ 90%] Building CXX object examples/CMakeFiles/beman.exemplar.examples.identity_direct_usage.dir/identity_direct_usage.cpp.o +[100%] Linking CXX executable beman.exemplar.examples.identity_direct_usage +[100%] Built target beman.exemplar.examples.identity_direct_usage # Run beman.exemplar tests. $ ctest --test-dir build -Internal ctest changing into directory: /path/to/your/repo/build -Test project /path/to/your/repo/build +Internal ctest changing into directory: /home/dariusn/git/Beman/exemplar/build +Test project /home/dariusn/git/Beman/exemplar/build Start 1: IdentityTest.call_identity_with_int 1/4 Test #1: IdentityTest.call_identity_with_int ........... Passed 0.00 sec Start 2: IdentityTest.call_identity_with_custom_type @@ -193,7 +194,7 @@ Total Test time (real) = 0.01 sec # Run examples. -$ build/exemplar/beman.exemplar.examples.identity_direct_usage +$ build/examples/beman.exemplar.examples.identity_direct_usage 2024 ``` @@ -207,11 +208,13 @@ $ build/exemplar/beman.exemplar.examples.identity_direct_usage # Install build artifacts from `build` directory into `opt/beman.exemplar` path. $ cmake --install build --prefix /opt/beman.exemplar -- Install configuration: "" --- Up-to-date: /opt/beman.exemplar/lib/libbeman.exemplar.a --- Up-to-date: /opt/beman.exemplar/include --- Up-to-date: /opt/beman.exemplar/include/beman --- Up-to-date: /opt/beman.exemplar/include/beman/exemplar --- Up-to-date: /opt/beman.exemplar/include/beman/exemplar/identity.hpp +-- Installing: /opt/beman.exemplar/lib/libbeman.exemplar.a +-- Installing: /opt/beman.exemplar/include +-- Installing: /opt/beman.exemplar/include/beman +-- Installing: /opt/beman.exemplar/include/beman/exemplar +-- Installing: /opt/beman.exemplar/include/beman/exemplar/identity.hpp +-- Installing: /opt/beman.exemplar/lib/cmake/beman.exemplarConfig.cmake +-- Installing: /opt/beman.exemplar/lib/cmake/beman.exemplarConfigVersion.cmak # Check tree. $ tree /opt/beman.exemplar @@ -221,9 +224,12 @@ $ tree /opt/beman.exemplar │   └── exemplar │   └── identity.hpp └── lib + ├── cmake + │   ├── beman.exemplarConfig.cmake + │   └── beman.exemplarConfigVersion.cmake └── libbeman.exemplar.a -5 directories, 2 files +6 directories, 4 files ``` diff --git a/cmake/Config.cmake.in b/cmake/Config.cmake.in new file mode 100644 index 0000000..fce1d0d --- /dev/null +++ b/cmake/Config.cmake.in @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake") +check_required_components("@PROJECT_NAME@")