@@ -4,12 +4,20 @@ cmake_minimum_required(VERSION 3.16)
44# and the targets that do not specify a standard.
55# If not set, the latest supported standard for your compiler is used
66# You can later set fine-grained standards for each target using `target_compile_features`
7- # set(CMAKE_CXX_STANDARD 17)
7+ # Note: linking together projects compiled with different C++ standards may work, but
8+ # it is not recommended because of possible issues with ABI
9+ set (CMAKE_CXX_STANDARD 20)
810
9- # Add project_options v0.13.1
11+ # strongly encouraged to enable this globally to avoid conflicts between
12+ # -Wpedantic being enabled and -std=c++20 and -std=gnu++20 for example
13+ # when compiling with PCH enabled
14+ set (CMAKE_CXX_EXTENSIONS OFF )
15+
16+ # Add project_options v0.14.2
1017# https://github.com/cpp-best-practices/project_options
1118include (FetchContent )
12- FetchContent_Declare (_project_options URL https://github.com/cpp-best-practices/project_options/archive/refs/tags/v0.13.1.zip)
19+ FetchContent_Declare (_project_options
20+ URL https://github.com/cpp-best-practices/project_options/archive/refs/tags/v0.14.2.zip)
1321FetchContent_MakeAvailable (_project_options)
1422include (${_project_options_SOURCE_DIR } /Index.cmake )
1523
@@ -18,34 +26,58 @@ include(${_project_options_SOURCE_DIR}/Index.cmake)
1826# run_vcpkg()
1927
2028# Set the project name and language
21- project (myproject LANGUAGES CXX )
29+ project (myproject LANGUAGES CXX C )
30+
31+ get_property (BUILDING_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
32+ if (BUILDING_MULTI_CONFIG)
33+ if (NOT CMAKE_BUILD_TYPE )
34+ # Make sure that all supported configuration types have their
35+ # associated conan packages available. You can reduce this
36+ # list to only the configuration types you use, but only if one
37+ # is not forced-set on the command line for VS
38+ message (TRACE "Setting up multi-config build types" )
39+ set (CMAKE_CONFIGURATION_TYPES
40+ Debug
41+ Release
42+ RelWithDebInfo
43+ MinSizeRel
44+ CACHE STRING "Enabled build types" FORCE )
45+ else ()
46+ message (TRACE "User chose a specific build type, so we are using that" )
47+ set (CMAKE_CONFIGURATION_TYPES
48+ ${CMAKE_BUILD_TYPE }
49+ CACHE STRING "Enabled build types" FORCE )
50+ endif ()
51+ endif ()
52+
53+ include (${_project_options_SOURCE_DIR } /src/DynamicProjectOptions.cmake )
54+
55+ # defaulted_project_options sets recommended defaults and provides user and developer
56+ # modes and full GUI support for choosing options at configure time
57+
58+ # for more flexibility, look into project_options() macro
59+
60+ # Any default can be overridden
61+ # set(<feature_name>_DEFAULT <value>) - set default for both user and developer modes
62+ # set(<feature_name>_DEVELOPER_DEFAULT <value>) - set default for developer mode
63+ # set(<feature_name>_USER_DEFAULT <value>) - set default for user mode
2264
2365# Initialize project_options variable related to this project
2466# This overwrites `project_options` and sets `project_warnings`
2567# uncomment the options to enable them:
26- project_options (
27- ENABLE_CACHE
28- # WARNINGS_AS_ERRORS
29- ENABLE_CPPCHECK
30- ENABLE_CLANG_TIDY
31- ENABLE_CONAN
32- ENABLE_COVERAGE
33- # ENABLE_IPO
34- # ENABLE_INCLUDE_WHAT_YOU_USE
35- # ENABLE_PCH
36- # PCH_HEADERS
37- # ENABLE_DOXYGEN
38- # ENABLE_USER_LINKER
39- # ENABLE_BUILD_WITH_TIME_TRACE
40- # ENABLE_UNITY
41- # ENABLE_SANITIZER_ADDRESS
42- # ENABLE_SANITIZER_LEAK
43- # ENABLE_SANITIZER_UNDEFINED_BEHAVIOR
44- # ENABLE_SANITIZER_THREAD
45- # ENABLE_SANITIZER_MEMORY
46- # CONAN_OPTIONS
68+ dynamic_project_options (
69+ # Note: PCH is disabled by default in developer mode because these headers become
70+ # globally included and they can mask other errors
71+ PCH_HEADERS
72+ <vector>
73+ <string> # This is a list of headers to pre-compile, here are some common ones
74+ # CONAN_OPTIONS # Extra options to pass to conan
75+ # MSVC_WARNINGS # Override the defaults for the MSVC warnings
76+ # CLANG_WARNINGS # Override the defaults for the CLANG warnings
77+ # GCC_WARNINGS # Override the defaults for the GCC warnings
4778)
48- target_compile_features (project_options INTERFACE cxx_std_17 )
79+
80+ target_compile_features (project_options INTERFACE cxx_std_${CMAKE_CXX_STANDARD} )
4981
5082# Adding the src:
5183add_subdirectory (src )
@@ -64,3 +96,13 @@ if(ENABLE_FUZZING)
6496 message ("Building Fuzz Tests, using fuzzing sanitizer https://www.llvm.org/docs/LibFuzzer.html" )
6597 add_subdirectory (fuzz_test )
6698endif ()
99+
100+ # If MSVC is being used, and ASAN is enabled, we need to set the debugger environment
101+ # so that it behaves well with MSVC's debugger, and we can run the target from visual studio
102+ if (MSVC )
103+ get_all_targets (all_targets )
104+ set_target_properties (${all_targets} PROPERTIES VS_DEBUGGER_ENVIRONMENT "PATH=$(VC_ExecutablePath_x64);%PATH%" )
105+ endif ()
106+
107+ # set the startup project for the "play" button in MSVC
108+ set_property (DIRECTORY PROPERTY VS_STARTUP_PROJECT intro)
0 commit comments