-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
107 lines (89 loc) · 4.66 KB
/
Copy pathCMakeLists.txt
File metadata and controls
107 lines (89 loc) · 4.66 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
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
cmake_minimum_required(VERSION 3.31.6 FATAL_ERROR)
project(DataStructuresAlgorithms CXX)
set(CMAKE_CXX_STANDARD 26)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_BUILD_TYPE "Debug")
# ###############################################################################
# Global compiler options
# https://stackoverflow.com/questions/79444534/vscode-cmake-configure-does-not-generate-cmakecache-txt-from-cmakelists-txt
# CMAKE_CXX_COMPILER_ID is set only at the project() call, when CMake actually detect compilers.
# ###############################################################################
if(MSVC)
# remove default flags provided with CMake for MSVC
set(CMAKE_CXX_FLAGS "")
set(CMAKE_CXX_FLAGS_DEBUG "")
set(CMAKE_CXX_FLAGS_RELEASE "")
elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
message("-- Setting GNU options from CMakeLists.txt")
# set(CMAKE_CXX_FLAGS "-std=gnu++26 -fdiagnostics-color=always" CACHE STRING "CXX build flags" FORCE)
set(CMAKE_CXX_FLAGS "-std=gnu++26 -fdiagnostics-color=always -fsanitize=address,undefined -Wall -Wextra -Wfatal-errors" CACHE STRING "CXX build flags" FORCE)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -ggdb3 -O0 -g3" CACHE STRING "Debug build flags" FORCE)
# set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -ggdb3 -O0 -g3" CACHE STRING "Debug build flags" FORCE)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3 -DNDEBUG" CACHE STRING "Release build flags" FORCE)
endif()
# ###############################################################################
# Set target arch type if empty. Visual studio solution generator provides it.
# ###############################################################################
if(NOT CMAKE_VS_PLATFORM_NAME)
set(CMAKE_VS_PLATFORM_NAME "x64")
endif()
message("${CMAKE_VS_PLATFORM_NAME} architecture in use")
if(NOT("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "Win32"
OR "${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64"))
message(FATAL_ERROR "${CMAKE_VS_PLATFORM_NAME} arch is not supported!")
endif()
# ###############################################################################
# Global configuration types
# ###############################################################################
set(CMAKE_CONFIGURATION_TYPES
"Debug"
"Release"
CACHE STRING "Configuration" FORCE
)
# ###############################################################################
# Global linker options
# ###############################################################################
if(MSVC)
# remove default flags provided with CMake for MSVC
set(CMAKE_EXE_LINKER_FLAGS "")
set(CMAKE_MODULE_LINKER_FLAGS "")
set(CMAKE_SHARED_LINKER_FLAGS "")
set(CMAKE_STATIC_LINKER_FLAGS "")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS}")
set(CMAKE_MODULE_LINKER_FLAGS_DEBUG "${CMAKE_MODULE_LINKER_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS}")
set(CMAKE_STATIC_LINKER_FLAGS_DEBUG "${CMAKE_STATIC_LINKER_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS}")
set(CMAKE_MODULE_LINKER_FLAGS_RELEASE "${CMAKE_MODULE_LINKER_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS}")
set(CMAKE_STATIC_LINKER_FLAGS_RELEASE "${CMAKE_STATIC_LINKER_FLAGS}")
endif()
# ###############################################################################
# Nuget packages function stub.
# ###############################################################################
function(use_package TARGET PACKAGE VERSION)
message(WARNING "No implementation of use_package. Create yours. "
"Package \"${PACKAGE}\" with version \"${VERSION}\" "
"for target \"${TARGET}\" is ignored!")
endfunction()
# ###############################################################################
# Common utils
# ###############################################################################
include(CMake/Utils.cmake)
# ###############################################################################
# Additional Global Settings(add specific info there)
# ###############################################################################
include(CMake/GlobalSettingsInclude.cmake OPTIONAL)
include(CTest)
enable_testing()
# ###############################################################################
# Use solution folders feature
# ###############################################################################
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# set(BUILD_STATIC_LIBS ON)
# ###############################################################################
# Sub-projects
# ###############################################################################
add_subdirectory(Console)
add_subdirectory(src)
add_subdirectory(test)