Skip to content

Commit 0b4314c

Browse files
committed
Update CMakeLists, prepare for packaging
* Converts beman::scope to interface library * Adds CMake config packaging routines * Removes vestigal non-header source file * Tests/examples link to library instead of raw source include
1 parent 3c68113 commit 0b4314c

File tree

7 files changed

+79
-40
lines changed

7 files changed

+79
-40
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@
55
# ignore emacs temp files
66
*~
77
\#*\#
8+
9+
# ignore vscode settings
10+
.vscode

CMakeLists.txt

Lines changed: 65 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,87 @@
22

33
cmake_minimum_required(VERSION 3.25)
44

5-
project(beman.scope DESCRIPTION "Generic Scope Guard" LANGUAGES CXX)
6-
7-
enable_testing()
5+
project(
6+
beman.scope
7+
DESCRIPTION "Generic Scope Guard"
8+
LANGUAGES CXX
9+
VERSION 0.0.1
10+
)
811

912
# [CMAKE.SKIP_TESTS]
1013
option(
1114
BEMAN_SCOPE_BUILD_TESTS
12-
"Enable building tests and test infrastructure. Default: ON. Values: { ON, OFF }."
15+
"Enable building tests and test infrastructure. Default: ${PROJECT_IS_TOP_LEVEL}. Values: { ON, OFF }."
1316
${PROJECT_IS_TOP_LEVEL}
1417
)
1518

1619
# [CMAKE.SKIP_EXAMPLES]
1720
option(
1821
BEMAN_SCOPE_BUILD_EXAMPLES
19-
"Enable building examples. Default: ON. Values: { ON, OFF }."
22+
"Enable building examples. Default: ${PROJECT_IS_TOP_LEVEL}. Values: { ON, OFF }."
23+
${PROJECT_IS_TOP_LEVEL}
24+
)
25+
26+
option(
27+
BEMAN_SCOPE_INSTALL_CONFIG_FILE_PACKAGE
28+
"Enable creating and installing a CMake config-file package. Default: ${PROJECT_IS_TOP_LEVEL}. Values: { ON, OFF }."
2029
${PROJECT_IS_TOP_LEVEL}
2130
)
2231

23-
include(GNUInstallDirs)
32+
add_library(beman.scope INTERFACE)
33+
add_library(beman::scope ALIAS beman.scope)
34+
35+
# gersemi: off
36+
set_target_properties(
37+
beman.scope
38+
PROPERTIES
39+
VERIFY_INTERFACE_HEADER_SETS ON
40+
EXPORT_NAME scope
41+
)
42+
43+
target_sources(
44+
beman.scope
45+
INTERFACE
46+
FILE_SET HEADERS
47+
BASE_DIRS include
48+
FILES include/beman/scope/scope.hpp
49+
)
50+
51+
install(
52+
TARGETS beman.scope
53+
EXPORT beman.scope-targets
54+
COMPONENT beman.scope
55+
FILE_SET HEADERS
56+
)
57+
# gersemi: on
58+
59+
if(BEMAN_SCOPE_INSTALL_CONFIG_FILE_PACKAGE)
60+
include(GNUInstallDirs)
61+
include(CMakePackageConfigHelpers)
62+
63+
write_basic_package_version_file(
64+
${CMAKE_CURRENT_BINARY_DIR}/beman.scope-config-version.cmake
65+
COMPATIBILITY ExactVersion
66+
)
2467

25-
# todo rm add_subdirectory(src/beman/scope)
68+
install(
69+
FILES
70+
cmake/beman.scope-config.cmake
71+
${CMAKE_CURRENT_BINARY_DIR}/beman.scope-config-version.cmake
72+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/beman.scope
73+
COMPONENT beman.scope
74+
)
75+
76+
install(
77+
EXPORT beman.scope-targets
78+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/beman.scope
79+
NAMESPACE beman::
80+
COMPONENT beman.scope
81+
)
82+
endif()
2683

2784
if(BEMAN_SCOPE_BUILD_TESTS)
85+
enable_testing()
2886
add_subdirectory(tests)
2987
endif()
3088

cmake/beman.scope-config.cmake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
include(${CMAKE_CURRENT_LIST_DIR}/beman.scope-targets.cmake)
2+
3+
foreach(comp IN LISTS beman.scope_FIND_COMPONENTS)
4+
if(beman.scope_FIND_REQUIRED_${comp})
5+
set(beman.scope_FOUND FALSE)
6+
return()
7+
endif()
8+
endforeach()

examples/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ message("Examples to be built: ${ALL_EXAMPLES}")
77
foreach(example ${ALL_EXAMPLES})
88
add_executable(${example})
99
target_sources(${example} PRIVATE ${example}.cpp)
10-
target_include_directories(${example} PRIVATE ${CMAKE_SOURCE_DIR}/include)
10+
target_link_libraries(${example} PRIVATE beman::scope)
1111
endforeach()

src/beman/scope/CMakeLists.txt

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/beman/scope/scope.cpp

Lines changed: 0 additions & 3 deletions
This file was deleted.

tests/CMakeLists.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,14 @@ set(ALL_TESTNAMES scope_success scope_exit scope_fail unique_resource)
1313

1414
message("Tests to be built: ${ALL_TESTNAMES}")
1515

16-
include(CTest)
1716
include(Catch)
1817

1918
foreach(testname ${ALL_TESTNAMES})
2019
add_executable(test.${testname})
2120
target_sources(test.${testname} PRIVATE ${testname}.test.cpp)
22-
target_include_directories(
21+
target_link_libraries(
2322
test.${testname}
24-
PRIVATE ${CMAKE_SOURCE_DIR}/include
23+
PRIVATE Catch2::Catch2WithMain beman::scope
2524
)
26-
target_link_libraries(test.${testname} PRIVATE Catch2::Catch2WithMain)
2725
catch_discover_tests(test.${testname})
2826
endforeach()

0 commit comments

Comments
 (0)