generated from cpp-best-practices/cmake_conan_boilerplate_template
-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
CMakeLists.txt
149 lines (127 loc) · 4.2 KB
/
CMakeLists.txt
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
cmake_minimum_required(VERSION 3.21...3.28)
# set a default CXX standard for the tools and targets that do not specify them.
# If commented, the latest supported standard for your compiler is automatically set.
# set(CMAKE_CXX_STANDARD 20)
# Set to `ON` if using C++20 modules
set(CMAKE_CXX_SCAN_FOR_MODULES OFF)
include(FetchContent)
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
cmake_policy(SET CMP0135 NEW)
endif()
# Add project_options from https://github.com/aminya/project_options
# Change the version in the following URL to update the package (watch the releases of the repository for future updates)
set(PROJECT_OPTIONS_VERSION "v0.41.0")
FetchContent_Declare(
_project_options
URL https://github.com/aminya/project_options/archive/refs/tags/${PROJECT_OPTIONS_VERSION}.zip)
FetchContent_MakeAvailable(_project_options)
include(${_project_options_SOURCE_DIR}/Index.cmake)
# Define the features of the project
include("./Features.cmake")
# enable cross-compiling: - should be called before run_vcpkg()
if(ENABLE_CROSS_COMPILING)
enable_cross_compiler()
endif()
# install vcpkg dependencies: - should be called before defining project()
run_vcpkg(
VCPKG_URL
"https://github.com/microsoft/vcpkg.git"
VCPKG_REV
"ee2d2a100103e0f3613c60655dcf15be7d5157b8")
# Set the project name and language
project(
cpp_vcpkg_project
VERSION 1.1.0
DESCRIPTION ""
HOMEPAGE_URL "https://github.com/aminya/cpp_vcpkg_project"
LANGUAGES CXX C)
if(FEATURE_TESTS)
# enable sanitizers and analyzers if running the tests
if(NOT
CMAKE_CXX_COMPILER_ID
STREQUAL
"GNU"
AND NOT
CMAKE_C_COMPILER_ID
STREQUAL
"GNU")
set(ENABLE_CLANG_TIDY "ENABLE_CLANG_TIDY")
endif()
set(ENABLE_CPPCHECK "ENABLE_CPPCHECK")
set(ENABLE_COVERAGE "ENABLE_COVERAGE")
set(ENABLE_VS_ANALYSIS "ENABLE_VS_ANALYSIS")
# generate a main function for the test executable
enable_testing()
find_package(Catch2 REQUIRED)
add_library(catch2_test_common INTERFACE)
target_find_dependencies(catch2_test_common INTERFACE_CONFIG Catch2)
target_link_libraries(catch2_test_common INTERFACE Catch2::Catch2 Catch2::Catch2WithMain)
target_compile_definitions(catch2_test_common INTERFACE DO_NOT_USE_WMAIN)
include(Catch)
endif()
if(FEATURE_DOCS)
set(ENABLE_DOXYGEN "ENABLE_DOXYGEN")
endif()
# Initialize project_options variable related to this project
# This overwrites `project_options` and sets `project_warnings`
# uncomment to enable the options. Some of them accept one or more inputs:
project_options(
# defines my_project_options/my_project_warnings
PREFIX
"my"
ENABLE_CACHE
${ENABLE_CPPCHECK}
${ENABLE_CLANG_TIDY}
${ENABLE_VS_ANALYSIS}
# ENABLE_CONAN
# ENABLE_INTERPROCEDURAL_OPTIMIZATION
# ENABLE_NATIVE_OPTIMIZATION
${ENABLE_DOXYGEN}
${ENABLE_COVERAGE}
${ENABLE_SANITIZER_ADDRESS}
${ENABLE_SANITIZER_UNDEFINED_BEHAVIOR}
# ${ENABLE_SANITIZER_THREAD}
# ${ENABLE_SANITIZER_MEMORY}
# ENABLE_CONTROL_FLOW_PROTECTION
# ENABLE_STACK_PROTECTION
# ENABLE_OVERFLOW_PROTECTION
# ENABLE_ELF_PROTECTION
# ENABLE_RUNTIME_SYMBOLS_RESOLUTION
# ENABLE_COMPILE_COMMANDS_SYMLINK
# ENABLE_PCH
# PCH_HEADERS
# WARNINGS_AS_ERRORS
# ENABLE_INCLUDE_WHAT_YOU_USE
# ENABLE_GCC_ANALYZER
# ENABLE_BUILD_WITH_TIME_TRACE
# ENABLE_UNITY
# LINKER "lld"
# CONAN_PROFILE ${profile_path}
)
add_subdirectory(./my_exe)
add_subdirectory(./my_lib)
add_subdirectory(./my_header_lib)
if(FEATURE_FUZZ_TESTS)
add_subdirectory(fuzz_test)
endif()
# set the startup project for the "play" button in MSVC
set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT my_exe)
if(CMAKE_SKIP_INSTALL_RULES)
return()
endif()
# the variables set using CACHE STRING "" are passed to package_project
# Package the project
package_project(
TARGETS
my_exe
my_lib
my_header_lib
my_project_options
my_project_warnings)
# Experience shows that explicit package naming can help make it easier to sort
# out potential ABI related issues before they start, while helping you
# track a build to a specific GIT SHA
set(CPACK_PACKAGE_FILE_NAME
"${CMAKE_PROJECT_NAME}-${CMAKE_PROJECT_VERSION}-${GIT_SHORT_SHA}-${CMAKE_SYSTEM_NAME}-${CMAKE_BUILD_TYPE}-${CMAKE_CXX_COMPILER_ID}-${CMAKE_CXX_COMPILER_VERSION}"
)
include(CPack)