-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
74 lines (63 loc) · 2.75 KB
/
CMakeLists.txt
File metadata and controls
74 lines (63 loc) · 2.75 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
cmake_minimum_required(VERSION 3.20)
project(cppsample)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF) # Use -std=c++17 instead of -std=gnu++17
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN YES)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
option(USE_LTO "Enable Link-Time Optimization for Release builds" ON)
option(USE_LIBC++ "Add the compilation flag -stdlib=libc++" OFF)
option(BUILD_TESTS "Build the tests" ON)
# https://www.kitware.com/cmake-and-the-default-build-type/
# Set a default build type if none was specified
set(default_build_type "Release")
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to '${default_build_type}' as none was specified.")
set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE
STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
# Enable colored warnings in Ninja's output, if the compiler has -fdiagnostics-color support.
# https://github.com/ninja-build/ninja/issues/174
if(CMAKE_GENERATOR STREQUAL "Ninja")
add_compile_options($<$<COMPILE_LANG_AND_ID:C,GNU>:$<$<VERSION_GREATER_EQUAL:$<C_COMPILER_VERSION>,4.9>:-fdiagnostics-color=always>>)
add_compile_options($<$<COMPILE_LANG_AND_ID:CXX,GNU>:$<$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,4.9>:-fdiagnostics-color=always>>)
add_compile_options($<$<COMPILE_LANG_AND_ID:C,Clang>:$<$<VERSION_GREATER_EQUAL:$<C_COMPILER_VERSION>,3.5>:-fcolor-diagnostics>>)
add_compile_options($<$<COMPILE_LANG_AND_ID:CXX,Clang>:$<$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,3.5>:-fcolor-diagnostics>>)
endif()
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
if(MSVC)
add_compile_options(/utf-8 /W4 /WX)
add_compile_options($<$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,19.10>:/permissive->)
else()
add_compile_options(-Wall -Wextra -Wpedantic)
if(USE_LIBC++)
add_compile_options(-stdlib=libc++)
add_link_options(-stdlib=libc++)
endif()
endif()
if(USE_LTO)
include(CheckIPOSupported)
check_ipo_supported(RESULT ipo_result OUTPUT ipo_output)
if(ipo_result)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_DEBUG FALSE)
message(STATUS "Link-time Optimization enabled for release builds")
else()
message(FATAL_ERROR "IPO is not supported: ${ipo_output}")
endif()
else()
message(STATUS "Link-time Optimization disabled")
endif()
add_subdirectory(src)
if(BUILD_TESTS)
find_package(GTest CONFIG REQUIRED
NO_DEFAULT_PATH
PATHS ${CMAKE_BINARY_DIR}
)
add_subdirectory(test)
endif()