Skip to content

Commit 8cfc91c

Browse files
committed
Prepare CMakeLists.txt for external inclusion
* add options to make the project clean
1 parent b22d950 commit 8cfc91c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+408
-333
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ third_party/*/
1212
build/
1313
artifacts/
1414
CMakeUserPresets.json
15+
.qtcreator

CMakeLists.txt

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,42 @@
11
cmake_minimum_required(VERSION 3.24 FATAL_ERROR)
2-
project (co-cpp19 LANGUAGES CXX)
3-
enable_testing()
2+
project(co-cpp19 LANGUAGES CXX)
43

5-
include(GNUInstallDirs)
6-
include(CMakePackageConfigHelpers)
7-
set(COCPP19_CMAKE_CONFIG_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/CoCpp19")
4+
set(COCPP_MAIN_PROJECT OFF)
85

9-
find_package(GTest QUIET)
6+
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
7+
set(COCPP_MAIN_PROJECT ON)
8+
endif()
9+
10+
option(COCPP_BuildTests "Build the unit tests when BUILD_TESTING is enabled." ${COCPP_MAIN_PROJECT})
11+
option(COCPP_Install "Install CMake targets during install step." ${COCPP_MAIN_PROJECT})
12+
13+
if(COCPP_BuildTests)
14+
enable_testing()
15+
endif()
16+
17+
if(COCPP_Install)
18+
include(GNUInstallDirs)
19+
include(CMakePackageConfigHelpers)
20+
set(COCPP19_CMAKE_CONFIG_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/CoCpp19")
21+
endif()
1022

1123
add_subdirectory(third_party)
1224
add_subdirectory(src)
1325

14-
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/CoCpp19Config.cmake.in
15-
"${CMAKE_CURRENT_BINARY_DIR}/CoCpp19Config.cmake"
16-
INSTALL_DESTINATION ${COCPP19_CMAKE_CONFIG_DESTINATION}
17-
)
18-
write_basic_package_version_file(
19-
"${CMAKE_CURRENT_BINARY_DIR}/CoCpp19ConfigVersion.cmake"
20-
VERSION "1.0.0"
21-
COMPATIBILITY AnyNewerVersion
22-
)
23-
install(FILES
24-
"${CMAKE_CURRENT_BINARY_DIR}/CoCpp19Config.cmake"
25-
"${CMAKE_CURRENT_BINARY_DIR}/CoCpp19ConfigVersion.cmake"
26-
DESTINATION ${COCPP19_CMAKE_CONFIG_DESTINATION}
27-
COMPONENT cocpp19
28-
)
26+
if(COCPP_Install)
27+
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/CoCpp19Config.cmake.in
28+
"${CMAKE_CURRENT_BINARY_DIR}/CoCpp19Config.cmake"
29+
INSTALL_DESTINATION ${COCPP19_CMAKE_CONFIG_DESTINATION}
30+
)
31+
write_basic_package_version_file(
32+
"${CMAKE_CURRENT_BINARY_DIR}/CoCpp19ConfigVersion.cmake"
33+
VERSION "1.0.0"
34+
COMPATIBILITY AnyNewerVersion
35+
)
36+
install(FILES
37+
"${CMAKE_CURRENT_BINARY_DIR}/CoCpp19Config.cmake"
38+
"${CMAKE_CURRENT_BINARY_DIR}/CoCpp19ConfigVersion.cmake"
39+
DESTINATION ${COCPP19_CMAKE_CONFIG_DESTINATION}
40+
COMPONENT cocpp19
41+
)
42+
endif()

CMakePresets.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
"generator": "Ninja Multi-Config",
1313
"binaryDir": "${sourceDir}/build/${presetName}",
1414
"cacheVariables": {
15-
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
15+
"CMAKE_EXPORT_COMPILE_COMMANDS": true,
1616
"CMAKE_CTEST_ARGUMENTS": "--output-on-failure",
17-
"CMAKE_CONFIGURATION_TYPES": "Debug;Release"
17+
"CMAKE_CONFIGURATION_TYPES": "Debug;Release",
18+
"INSTALL_GTEST": false
1819
}
1920
},
2021
{

src/array19.lib/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11

22
include("array19/array19.cmake")
3-
include("array19/array19.tests.cmake")
3+
4+
if(COCPP_BuildTests)
5+
include("array19/array19.tests.cmake")
6+
endif()
Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,33 @@
11

22
add_library(array19 INTERFACE)
33
target_compile_features(array19
4-
INTERFACE cxx_std_20
4+
INTERFACE cxx_std_20
55
)
66
target_include_directories(array19
7-
INTERFACE
7+
INTERFACE
88
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/>
99
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
1010
)
1111
file(GLOB array19_headers "${CMAKE_CURRENT_LIST_DIR}/*.h")
1212
target_sources(array19
13-
INTERFACE FILE_SET public_headers
13+
INTERFACE FILE_SET public_headers
1414
TYPE HEADERS
1515
FILES ${array19_headers}
1616
)
1717

1818
add_library(CoCpp19::array19 ALIAS array19)
19-
install(TARGETS array19
20-
EXPORT array19Targets
21-
FILE_SET public_headers
22-
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
23-
COMPONENT "array19"
24-
)
25-
install(EXPORT array19Targets
26-
FILE "CoCpp19-array19-targets.cmake"
27-
NAMESPACE "CoCpp19::"
28-
DESTINATION ${COCPP19_CMAKE_CONFIG_DESTINATION}
29-
COMPONENT "array19"
30-
)
19+
20+
if(COCPP_Install)
21+
install(TARGETS array19
22+
EXPORT array19Targets
23+
FILE_SET public_headers
24+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
25+
COMPONENT "array19"
26+
)
27+
install(EXPORT array19Targets
28+
FILE "CoCpp19-array19-targets.cmake"
29+
NAMESPACE "CoCpp19::"
30+
DESTINATION ${COCPP19_CMAKE_CONFIG_DESTINATION}
31+
COMPONENT "array19"
32+
)
33+
endif()

src/array19.lib/array19/array19.tests.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
add_executable(array19-test)
33
file(GLOB array19_test_sources "${CMAKE_CURRENT_LIST_DIR}/*.test.cpp")
44
target_sources(array19-test
5-
PRIVATE ${array19_test_sources}
5+
PRIVATE ${array19_test_sources}
66
)
77
target_link_libraries(array19-test
8-
PRIVATE GTest::gtest_main
9-
PRIVATE CoCpp19::array19
8+
PRIVATE GTest::gtest_main
9+
PRIVATE CoCpp19::array19
1010
)
1111
add_test(NAME array19 COMMAND array19-test)

src/coro19.lib/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11

22
include(coro19/coro19.cmake)
3-
include(coro19/coro19.tests.cmake)
3+
4+
if(COCPP_BuildTests)
5+
include(coro19/coro19.tests.cmake)
6+
endif()

src/coro19.lib/coro19/coro19.cmake

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,36 @@
11
add_library(coro19 STATIC)
22
target_link_libraries(coro19
3-
PUBLIC CoCpp19::array19
3+
PUBLIC CoCpp19::array19
44
)
55
target_include_directories(coro19
6-
PUBLIC
6+
PUBLIC
77
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/>
88
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
99
)
1010
file(GLOB coro19_headers "${CMAKE_CURRENT_LIST_DIR}/*.h")
1111
target_sources(coro19
12-
PRIVATE "coro19/coroutine.cpp"
13-
PUBLIC FILE_SET public_headers
12+
PRIVATE "coro19/coroutine.cpp"
13+
PUBLIC FILE_SET public_headers
1414
TYPE HEADERS
1515
FILES ${coro19_headers}
1616
)
1717

1818
add_library(CoCpp19::coro19 ALIAS coro19)
19-
install(TARGETS coro19
20-
EXPORT coro19Targets
21-
LIBRARY COMPONENT "coro19"
22-
ARCHIVE COMPONENT "coro19"
23-
RUNTIME COMPONENT "coro19"
24-
FILE_SET public_headers
25-
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
26-
COMPONENT "coro19"
27-
)
28-
install(EXPORT coro19Targets
29-
FILE "CoCpp19-coro19-targets.cmake"
30-
NAMESPACE "CoCpp19::"
31-
DESTINATION ${COCPP19_CMAKE_CONFIG_DESTINATION}
32-
COMPONENT "coro19"
33-
)
19+
20+
if(COCPP_Install)
21+
install(TARGETS coro19
22+
EXPORT coro19Targets
23+
LIBRARY COMPONENT "coro19"
24+
ARCHIVE COMPONENT "coro19"
25+
RUNTIME COMPONENT "coro19"
26+
FILE_SET public_headers
27+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
28+
COMPONENT "coro19"
29+
)
30+
install(EXPORT coro19Targets
31+
FILE "CoCpp19-coro19-targets.cmake"
32+
NAMESPACE "CoCpp19::"
33+
DESTINATION ${COCPP19_CMAKE_CONFIG_DESTINATION}
34+
COMPONENT "coro19"
35+
)
36+
endif()

src/coro19.lib/coro19/coro19.tests.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
add_executable(coro19-test)
33
file(GLOB coro19_test_sources "${CMAKE_CURRENT_LIST_DIR}/*.test.cpp")
44
target_sources(coro19-test
5-
PRIVATE ${coro19_test_sources}
5+
PRIVATE ${coro19_test_sources}
66
)
77
target_link_libraries(coro19-test
8-
PRIVATE GTest::gtest_main
9-
PRIVATE CoCpp19::coro19
8+
PRIVATE GTest::gtest_main
9+
PRIVATE CoCpp19::coro19
1010
)
1111
add_test(NAME coro19 COMMAND coro19-test)

src/enum19.lib/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11

22
include(enum19/enum19.cmake)
3-
include(enum19/enum19.tests.cmake)
3+
4+
if(COCPP_BuildTests)
5+
include(enum19/enum19.tests.cmake)
6+
endif()

0 commit comments

Comments
 (0)