Skip to content

Commit

Permalink
Merge pull request #73 from steve-downey/install_sets
Browse files Browse the repository at this point in the history
Install sets
  • Loading branch information
steve-downey authored Nov 10, 2024
2 parents 31c4462 + 50ded6a commit 9847480
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 70 deletions.
60 changes: 29 additions & 31 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,51 +12,49 @@ include(FetchContent)

set(TARGETS_EXPORT_NAME ${CMAKE_PROJECT_NAME}Targets)

# Build the tests only if enabled via the CLI flag: BUILD_TESTING.
if(BUILD_TESTING)
option(
OPTIONAL26_ENABLE_TESTING
"Enable building tests and test infrastructure"
${PROJECT_IS_TOP_LEVEL}
)

# Build the tests if enabled via the option OPTIONAL26_ENABLE_TESTING
if(OPTIONAL26_ENABLE_TESTING)
# Fetch GoogleTest
FetchContent_Declare(
googletest
EXCLUDE_FROM_ALL
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG
e39786088138f2749d64e9e90e0f9902daa77c40 # release-1.15.0
)
FetchContent_MakeAvailable(googletest)
endif()

add_subdirectory(src/beman/optional26)
add_subdirectory(examples)

include(GNUInstallDirs)

set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake)

install(
EXPORT ${TARGETS_EXPORT_NAME}
NAMESPACE ${CMAKE_PROJECT_NAME}
DESTINATION ${INSTALL_CONFIGDIR}
# Create the library target and named header set for beman_optional26
add_library(beman_optional26 STATIC)
target_sources(
beman_optional26
PUBLIC FILE_SET beman_optional26_headers TYPE HEADERS BASE_DIRS src include
)

include(CMakePackageConfigHelpers)

write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}ConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
if(OPTIONAL26_ENABLE_TESTING)
# Create the library target and named header set for testing beman_optional26
# and mark the set private
add_executable(beman_optional26_test)
target_sources(
beman_optional26_test
PRIVATE
FILE_SET beman_optional26_test_headers
TYPE HEADERS
BASE_DIRS src
)
endif()

configure_package_config_file(
"cmake/Config.cmake.in"
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake
INSTALL_DESTINATION ${INSTALL_CONFIGDIR}
)
add_subdirectory(src/beman/optional26)
add_subdirectory(include/beman/optional26)

install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}ConfigVersion.cmake
DESTINATION ${INSTALL_CONFIGDIR}
)
add_subdirectory(examples)

# Coverage
configure_file("cmake/gcovr.cfg.in" gcovr.cfg @ONLY)
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ TARGET:=all
compile: $(_build_path)/CMakeCache.txt ## Compile the project
cmake --build $(_build_path) --config $(CONFIG) --target all -- -k 0

install: $(_build_path)/CMakeCache.txt ## Install the project
DESTDIR=$(abspath $(DEST)) ninja -C $(_build_path) -k 0 install
install: $(_build_path)/CMakeCache.txt compile ## Install the project
cmake --install $(_build_path) --config $(CONFIG) --component beman_optional26_development --verbose

ctest: $(_build_path)/CMakeCache.txt ## Run CTest on current build
cd $(_build_path) && ctest --output-on-failure -C $(CONFIG)
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ This should build and run the tests with GCC 14 with the address and undefined b
CI current build and test flows:

```shell
# Configure build: default build production code + tests (BUILD_TESTING=ON by default).
# Configure build: default build production code + tests (OPTIONAL26_ENABLE_TESTING=ON by default).
$ cmake -G "Ninja Multi-Config" \
-DCMAKE_CONFIGURATION_TYPES="RelWithDebInfo;Asan" \
-DCMAKE_TOOLCHAIN_FILE=etc/clang-19-toolchain.cmake \
Expand All @@ -228,14 +228,14 @@ Total Test time (real) = 0.67 sec

##### Build Production, but Skip Tests

By default, we build and run tests. You can provide `-DBUILD_TESTING=OFF` and completely disable building tests:
By default, we build and run tests. You can provide `-DOPTIONAL26_ENABLE_TESTING=OFF` and completely disable building tests:

```shell
# Configure build: build production code, skip tests (BUILD_TESTING=OFF).
# Configure build: build production code, skip tests (OPTIONAL26_ENABLE_TESTING=OFF).
$ cmake -G "Ninja Multi-Config" \
-DCMAKE_CONFIGURATION_TYPES="RelWithDebInfo;Asan" \
-DCMAKE_TOOLCHAIN_FILE=etc/clang-19-toolchain.cmake \
-DBUILD_TESTING=OFF \
-DOPTIONAL26_ENABLE_TESTING=OFF \
-B .build -S .
-- The CXX compiler identification is Clang 19.0.0
...
Expand Down
10 changes: 6 additions & 4 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ foreach(example ${EXAMPLES})

# Install .
install(
TARGETS ${example}
EXPORT ${TARGETS_EXPORT_NAME}
DESTINATION
${CMAKE_INSTALL_BINDIR}
TARGETS
${example}
COMPONENT
beman_optional26_examples
DESTINATION
${CMAKE_INSTALL_BINDIR}
)
endforeach()
15 changes: 15 additions & 0 deletions include/beman/optional26/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# include/beman/optional26/CMakeLists.txt -*-cmake-*-
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

target_sources(
beman_optional26
PUBLIC
FILE_SET beman_optional26_headers
TYPE HEADERS
FILES
optional.hpp
detail/iterator.hpp
detail/stl_interfaces/config.hpp
detail/stl_interfaces/fwd.hpp
detail/stl_interfaces/iterator_interface.hpp
)
40 changes: 13 additions & 27 deletions src/beman/optional26/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,40 +1,26 @@
# cmake-format: off
# src/beman/optional26/CMakeLists.txt -*-makefile-*-
# src/beman/optional26/CMakeLists.txt -*-cmake-*-
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
# cmake-format: on

add_library(beman_optional26 STATIC optional.cpp detail/iterator.cpp)

include(GNUInstallDirs)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})

target_include_directories(
beman_optional26
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../../include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../../src/>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${CMAKE_LOWER_PROJECT_NAME}>
)
# Ensure that optional and iterator get compiled at least once
target_sources(beman_optional26 PUBLIC optional.cpp detail/iterator.cpp)

# The library is empty -- exclude it
install(
TARGETS beman_optional26
EXPORT ${TARGETS_EXPORT_NAME}
DESTINATION
${CMAKE_INSTALL_LIBDIR}
ARCHIVE
DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT beman_optional26_library
EXCLUDE_FROM_ALL
)

string(TOLOWER ${CMAKE_PROJECT_NAME} CMAKE_LOWER_PROJECT_NAME)

install(
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${CMAKE_LOWER_PROJECT_NAME}
FILES_MATCHING
PATTERN "*.hpp"
TARGETS beman_optional26
FILE_SET beman_optional26_headers
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
COMPONENT beman_optional26_development
)

target_link_libraries(beman_optional26)

# Tests
if(BUILD_TESTING)
if(OPTIONAL26_ENABLE_TESTING)
add_subdirectory(tests)
endif()
10 changes: 9 additions & 1 deletion src/beman/optional26/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
include(GoogleTest)

# Tests
add_executable(beman_optional26_test)
# add_executable(beman_optional26_test)

target_sources(
beman_optional26_test
Expand All @@ -21,6 +21,14 @@ target_sources(
test_utilities.cpp
)

target_sources(
beman_optional26_test
PRIVATE
FILE_SET beman_optional26_test_headers
TYPE HEADERS
FILES test_types.hpp test_utilities.hpp
)

target_link_libraries(
beman_optional26_test
PRIVATE beman_optional26 GTest::gtest GTest::gtest_main
Expand Down
2 changes: 1 addition & 1 deletion src/beman/optional26/tests/test_constructor_fail.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// src/Beman/Optional26/tests/test_constructor_fail.t.cpp -*-C++-*-
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <Beman/Optional26/optional.hpp>
#include <beman/optional26/optional.hpp>
#include <string>
#include <utility>

Expand Down

0 comments on commit 9847480

Please sign in to comment.