Skip to content

Commit bd19dfd

Browse files
author
Sebastian Hahn
committed
add CMake build system
* add a own CMake file for each sub library * add a CMake file to handle google test * add a preset to build and execute the tests on Windows and Linux * add a CMake file for clang specific compiler flag -fsized-deallocation
1 parent b3036d5 commit bd19dfd

File tree

21 files changed

+465
-0
lines changed

21 files changed

+465
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ thirdparty/*/
99
.vagrant/
1010
.vscode/
1111
.vs/
12+
CMakeUserPresets.json

CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
cmake_minimum_required(VERSION 3.21 FATAL_ERROR)
2+
project (co-cpp19 LANGUAGES CXX)
3+
4+
set(CMAKE_CXX_STANDARD 20)
5+
6+
option(co-cpp19-enable-tests "Build the tests" OFF)
7+
add_subdirectory(third_party)
8+
add_subdirectory(cmake)
9+
if(${co-cpp19-enable-tests})
10+
enable_testing()
11+
endif()
12+
13+
add_subdirectory(src/)

CMakePresets.json

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
{
2+
"version": 3,
3+
"cmakeMinimumRequired": {
4+
"major": 3,
5+
"minor": 21,
6+
"patch": 0
7+
},
8+
"configurePresets": [
9+
{
10+
"name": "Base-Configure",
11+
"generator": "Ninja Multi-Config",
12+
"binaryDir": "${sourceDir}/build/${presetName}",
13+
"cacheVariables": {
14+
"co-cpp19-enable-tests": {
15+
"type": "BOOL",
16+
"value": "ON"
17+
},
18+
"CMAKE_CONFIGURATION_TYPES": "Debug;Release"
19+
},
20+
"hidden": true
21+
},
22+
{
23+
"name": "Windows-MSVC",
24+
"inherits": "Base-Configure",
25+
"displayName": "Tests on Windows",
26+
"description": "Used to configure the tests on Windows",
27+
"cacheVariables": {
28+
"CMAKE_CXX_COMPILER": "cl.exe",
29+
"CMAKE_CXX_FLAGS": "/permissive- /Zc:__cplusplus /Zc:externConstexpr /Zc:inline /Zc:preprocessor /Zc:throwingNew /diagnostics:caret /wd4068 /D_ENABLE_EXTENDED_ALIGNED_STORAGE"
30+
}
31+
},
32+
{
33+
"name": "Linux-Clang",
34+
"inherits": "Base-Configure",
35+
"displayName": "Tests on Linux",
36+
"description": "Used to configure the tests on Linux",
37+
"cacheVariables": {
38+
"CMAKE_CXX_COMPILER": "clang++-12",
39+
"CMAKE_CXX_FLAGS": "-fsized-deallocation -Wall -Wextra -Werror --pedantic -ftemplate-backtrace-limit=0 -Wno-gnu-zero-variadic-macro-arguments"
40+
}
41+
},
42+
{
43+
"name": "Clang-Static-Analyser",
44+
"inherits": "Base-Configure",
45+
"displayName": "Clang Static Analyser on Linux",
46+
"description": "Used to run clang static analyser",
47+
"cacheVariables": {
48+
"CMAKE_CXX_COMPILER": "clang++-12",
49+
"CMAKE_CXX_FLAGS": "-fsized-deallocation --analyze"
50+
}
51+
}
52+
],
53+
"buildPresets": [
54+
{
55+
"name": "Windows-MSVC-Debug",
56+
"displayName": "Tests on Windows in debug mode",
57+
"description": "Used to build the tests on windows. The cl compiler is used. It build in debug mode.",
58+
"configurePreset": "Windows-MSVC",
59+
"configuration": "Debug"
60+
},
61+
{
62+
"name": "Windows-MSVC-Release",
63+
"displayName": "Tests on Windows in release mode",
64+
"description": "Used to build the tests on windows. The cl compiler is used. It build in release mode.",
65+
"configurePreset": "Windows-MSVC",
66+
"configuration": "Release"
67+
},
68+
{
69+
"name": "Linux-Clang-Debug",
70+
"displayName": "Tests on Linux in debug mode",
71+
"description": "Used to build the tests on linux. The clang compiler is used. It build in debug mode.",
72+
"configurePreset": "Linux-Clang",
73+
"configuration": "Debug"
74+
},
75+
{
76+
"name": "Linux-Clang-Release",
77+
"displayName": "Tests on Linux in release mode",
78+
"description": "Used to build the tests on linux. The Clang compiler is used. It build in release mode.",
79+
"configurePreset": "Linux-Clang",
80+
"configuration": "Release"
81+
},
82+
{
83+
"name": "Clang-Static-Analyser",
84+
"displayName": "Analyse on linux",
85+
"description": "Used to build the tests on linux. The clang compiler is used. It is build with analyse",
86+
"configurePreset": "Clang-Static-Analyser",
87+
"configuration": "Debug"
88+
}
89+
],
90+
"testPresets": [
91+
{
92+
"name": "Base-Test",
93+
"output": {
94+
"outputOnFailure": true,
95+
"debug": false
96+
},
97+
"execution": {
98+
"noTestsAction": "error",
99+
"stopOnFailure": true
100+
},
101+
"hidden": true
102+
},
103+
104+
{
105+
"name": "Test-Windows-MSVC-Debug",
106+
"inherits": "Base-Test",
107+
"displayName": "Tests on Windows",
108+
"description": "Used to test on Windows",
109+
"configurePreset": "Windows-MSVC",
110+
"configuration": "Debug"
111+
},
112+
{
113+
"name": "Test-Windows-MSVC-Release",
114+
"inherits": "Base-Test",
115+
"displayName": "Tests on Windows",
116+
"description": "Used to test on Windows",
117+
"configurePreset": "Windows-MSVC",
118+
"configuration": "Release"
119+
},
120+
{
121+
"name": "Test-Linux-Clang-Debug",
122+
"inherits": "Base-Test",
123+
"displayName": "Tests on Linux",
124+
"description": "Used to test on Linux",
125+
"configurePreset": "Linux-Clang",
126+
"configuration": "Debug"
127+
},
128+
{
129+
"name": "Test-Linux-Clang-Release",
130+
"inherits": "Base-Test",
131+
"displayName": "Tests on Linux",
132+
"description": "Used to test on Linux",
133+
"configurePreset": "Linux-Clang",
134+
"configuration": "Release"
135+
}
136+
]
137+
}

cmake/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include(Clang.cmake)

cmake/Clang.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
message(INFO "CMAKE COMPILER: ${CMAKE_CXX_COMPILER_ID}")
2+
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
3+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsized-deallocation")
4+
endif()
5+
message(INFO "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")

src/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
add_subdirectory(array19.lib/)
2+
add_subdirectory(coro19.lib/)
3+
add_subdirectory(enum19.lib/)
4+
add_subdirectory(lookup19.lib/)
5+
add_subdirectory(meta19.lib/)
6+
add_subdirectory(optional19.lib/)
7+
add_subdirectory(partial19.lib/)
8+
add_subdirectory(serialize19.lib/)
9+
add_subdirectory(signal19.lib/)
10+
add_subdirectory(string19.lib/)
11+
add_subdirectory(strong19.lib/)
12+
add_subdirectory(tuple19.lib/)
13+
add_subdirectory(variant19.lib/)
14+

src/array19.lib/CMakeLists.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
cmake_minimum_required(VERSION 3.21 FATAL_ERROR)
2+
3+
add_library(array19 INTERFACE)
4+
5+
target_include_directories(array19 INTERFACE
6+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/>
7+
)
8+
9+
if(${co-cpp19-enable-tests})
10+
file(
11+
GLOB_RECURSE
12+
array19-tests
13+
"*.test.cpp")
14+
15+
add_executable(Array19Test ${array19-tests})
16+
target_link_libraries(Array19Test gtest_main array19)
17+
add_test(Array19Test Array19Test)
18+
endif()
19+

src/coro19.lib/CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
cmake_minimum_required(VERSION 3.21 FATAL_ERROR)
2+
3+
add_library(coro19 STATIC)
4+
5+
target_include_directories(coro19 PUBLIC
6+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/>
7+
)
8+
9+
target_sources(coro19 PRIVATE
10+
coro19/coroutine.cpp
11+
)
12+
13+
if(${co-cpp19-enable-tests})
14+
file(
15+
GLOB_RECURSE
16+
coro19-tests
17+
"*.test.cpp")
18+
19+
add_executable(Coro19Test ${coro19-tests})
20+
target_link_libraries(Coro19Test gtest_main coro19)
21+
add_test(Coro19Test Coro19Test)
22+
endif()

src/enum19.lib/CMakeLists.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
cmake_minimum_required(VERSION 3.21 FATAL_ERROR)
2+
3+
add_library(enum19 INTERFACE)
4+
5+
target_include_directories(enum19 INTERFACE
6+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/>
7+
)
8+
target_link_libraries(enum19 INTERFACE array19 meta19 string19)
9+
10+
if(${co-cpp19-enable-tests})
11+
file(
12+
GLOB_RECURSE
13+
enum19-tests
14+
"*.test.cpp")
15+
16+
add_executable(Enum19Test ${enum19-tests})
17+
target_link_libraries(Enum19Test gtest_main enum19)
18+
add_test(Enum19Test Enum19Test)
19+
endif()

src/lookup19.lib/CMakeLists.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
cmake_minimum_required(VERSION 3.21 FATAL_ERROR)
2+
3+
add_library(lookup19 INTERFACE)
4+
5+
target_include_directories(lookup19 INTERFACE
6+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/>
7+
)
8+
target_link_libraries(lookup19 INTERFACE array19)
9+
10+
if(${co-cpp19-enable-tests})
11+
file(
12+
GLOB_RECURSE
13+
lookup19-tests
14+
"*.test.cpp")
15+
16+
add_executable(lookup19Test ${lookup19-tests})
17+
target_link_libraries(lookup19Test gtest_main lookup19)
18+
add_test(lookup19Test lookup19Test)
19+
endif()

0 commit comments

Comments
 (0)