Skip to content

Commit

Permalink
Apply Beman standard: CMAKE.CONFIG
Browse files Browse the repository at this point in the history
  • Loading branch information
neatudarius committed Sep 25, 2024
1 parent 1fc7388 commit c04aadb
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 21 deletions.
26 changes: 22 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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})
40 changes: 23 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

```
Expand All @@ -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
Expand All @@ -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
```

</details>
Expand Down
6 changes: 6 additions & 0 deletions cmake/Config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")
check_required_components("@PROJECT_NAME@")

0 comments on commit c04aadb

Please sign in to comment.