-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
56 lines (46 loc) · 1.71 KB
/
Copy pathCMakeLists.txt
File metadata and controls
56 lines (46 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
cmake_minimum_required(VERSION 3.20)
project(cpp-project-template VERSION 0.1.0 LANGUAGES CXX)
option(BUILD_TESTING "Build unit tests" OFF)
option(ENABLE_COVERAGE "Instrument src/ targets for code coverage" OFF)
option(ENABLE_CLANG_TIDY "Add clang-tidy static analysis target" OFF)
if(ENABLE_CLANG_TIDY)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
endif()
add_library(project_options INTERFACE)
target_compile_options(project_options INTERFACE -Wall -Wextra -Wpedantic -Werror)
if(ENABLE_COVERAGE)
target_compile_options(project_options INTERFACE --coverage -fprofile-update=atomic)
target_link_options(project_options INTERFACE --coverage)
endif()
add_library(project_features INTERFACE)
target_compile_features(project_features INTERFACE cxx_std_20)
add_subdirectory(src)
if(BUILD_TESTING)
enable_testing()
add_subdirectory(tests)
endif()
if(ENABLE_COVERAGE AND BUILD_TESTING)
add_custom_target(coverage-report
COMMAND "${CMAKE_COMMAND}"
-DCOVERAGE_BINARY_DIR=${CMAKE_BINARY_DIR}
-P ${CMAKE_SOURCE_DIR}/cmake/coverage_report.cmake
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
COMMENT "Generating src/ coverage report (lcov CLI + HTML)"
USES_TERMINAL
VERBATIM
)
endif()
if(ENABLE_CLANG_TIDY)
set(CLANG_TIDY_JOBS 0 CACHE STRING "Parallel clang-tidy jobs (0 = auto-detect CPU count)")
add_custom_target(clang-tidy
COMMAND "${CMAKE_COMMAND}"
-DCLANG_TIDY_BINARY_DIR=${CMAKE_BINARY_DIR}
-DCLANG_TIDY_SOURCE_DIR=${CMAKE_SOURCE_DIR}
-DCLANG_TIDY_JOBS=${CLANG_TIDY_JOBS}
-P ${CMAKE_SOURCE_DIR}/cmake/clang_tidy.cmake
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
COMMENT "Running clang-tidy on src/"
USES_TERMINAL
VERBATIM
)
endif()