forked from aminya/cpp_vcpkg_project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
126 lines (109 loc) · 3.75 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
cmake_minimum_required(VERSION 3.16)
# 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)
# 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)
include(FetchContent)
FetchContent_Declare(_project_options
URL https://github.com/aminya/project_options/archive/refs/tags/v0.27.0.zip)
FetchContent_MakeAvailable(_project_options)
include(${_project_options_SOURCE_DIR}/Index.cmake)
# Define the features of the project
include("./Features.cmake")
# install vcpkg dependencies: - should be called before defining project()
run_vcpkg()
# Set the project name and language
project(
cpp_vcpkg_project
VERSION 0.0.0
DESCRIPTION ""
HOMEPAGE_URL "https://github.com/cpp-best-practices/cpp_vcpkg_project"
LANGUAGES CXX C)
# enable sanitizers and clang-tidy if running the tests
set(ENABLE_CLANG_TIDY OFF)
set(ENABLE_CPPCHECK OFF)
set(ENABLE_SANITIZER_ADDRESS OFF)
set(ENABLE_SANITIZER_UNDEFINED_BEHAVIOR OFF)
set(ENABLE_COVERAGE OFF)
if(FEATURE_TESTS)
set(ENABLE_CLANG_TIDY "ENABLE_CLANG_TIDY")
set(ENABLE_CPPCHECK "ENABLE_CPPCHECK")
set(ENABLE_COVERAGE "ENABLE_COVERAGE")
enable_testing()
if(NOT
"${CMAKE_SYSTEM_NAME}"
STREQUAL
"Windows")
set(ENABLE_SANITIZER_ADDRESS "ENABLE_SANITIZER_ADDRESS")
set(ENABLE_SANITIZER_UNDEFINED_BEHAVIOR "ENABLE_SANITIZER_UNDEFINED_BEHAVIOR")
else()
# or it is MSVC and has run vcvarsall
string(FIND "$ENV{PATH}" "$ENV{VSINSTALLDIR}" index_of_vs_install_dir)
if(MSVC AND "${index_of_vs_install_dir}" STREQUAL "-1")
set(ENABLE_SANITIZER_ADDRESS "ENABLE_SANITIZER_ADDRESS")
endif()
endif()
endif()
if(FEATURE_DOCS)
set(ENABLE_DOXYGEN "ENABLE_DOXYGEN")
else()
set(ENABLE_DOXYGEN OFF)
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(
# a unique prefix to be added before the project_options and project_warnings name
PREFIX
"my"
ENABLE_CACHE
${ENABLE_CPPCHECK}
${ENABLE_CLANG_TIDY}
# ENABLE_INTERPROCEDURAL_OPTIMIZATION
# ENABLE_NATIVE_OPTIMIZATION
${ENABLE_DOXYGEN}
${ENABLE_COVERAGE}
${ENABLE_SANITIZER_ADDRESS}
# ENABLE_SANITIZER_UNDEFINED_BEHAVIOR
# ENABLE_SANITIZER_LEAK
# ENABLE_SANITIZER_THREAD
# ENABLE_SANITIZER_MEMORY
# ENABLE_PCH
# PCH_HEADERS
# WARNINGS_AS_ERRORS
# ENABLE_INCLUDE_WHAT_YOU_USE
# ENABLE_USER_LINKER
# ENABLE_BUILD_WITH_TIME_TRACE
# ENABLE_UNITY
)
add_subdirectory(./my_exe)
add_subdirectory(./my_lib)
add_subdirectory(./my_header_lib)
# 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
INTERFACE_DEPENDENCIES_CONFIGURED
${my_header_lib_DEPENDENCIES_CONFIGURED}
INTERFACE_INCLUDES
${my_header_lib_INCLUDE_DIR}
PUBLIC_INCLUDES
${my_lib_INCLUDE_DIR})
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)
# 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)