-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
139 lines (114 loc) · 3.59 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
cmake_minimum_required(VERSION 3.19)
file(READ chalet.json CHALET_JSON_STRING)
string(JSON CHALET_NAME GET ${CHALET_JSON_STRING} "name")
string(JSON CHALET_VERSION GET ${CHALET_JSON_STRING} "version")
string(JSON CHALET_DESCRIPTION GET ${CHALET_JSON_STRING} "description")
string(JSON CHALET_HOMEPAGE_URL GET ${CHALET_JSON_STRING} "homepage")
project(${CHALET_NAME}
VERSION ${CHALET_VERSION}
DESCRIPTION ${CHALET_DESCRIPTION}
HOMEPAGE_URL ${CHALET_HOMEPAGE_URL}
LANGUAGES CXX
)
if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
message(FATAL_ERROR "Build must be Debug")
endif()
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(TARGET_NAME chalet-debug)
configure_file(src/ChaletConfig.hpp.in ${PROJECT_BINARY_DIR}/ChaletConfig.hpp)
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CLANG ON)
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(GNU ON)
endif()
if (MSVC)
foreach(config DEBUG RELEASE MINSIZEREL RELWITHDEBINFO)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${config} ${CMAKE_BINARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${config} ${CMAKE_BINARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${config} ${CMAKE_BINARY_DIR})
endforeach()
else()
set(CMAKE_CXX_FLAGS_DEBUG "-g3")
endif()
file(GLOB_RECURSE JSONSV_SOURCES
external/json-schema-validator/src/*.cpp
)
add_library(json-schema-validator STATIC ${JSONSV_SOURCES})
target_compile_definitions(json-schema-validator
PRIVATE
JSON_NOEXCEPTION
JSONSV_NOEXCEPTION
)
target_include_directories(json-schema-validator PRIVATE
external/json-schema-validator/src/
external/nlohmann/single_include/
)
file(GLOB_RECURSE TARGET_SOURCES
src/*.cpp
src/*.rc
)
add_executable(${TARGET_NAME} ${TARGET_SOURCES})
target_compile_definitions(${TARGET_NAME}
PRIVATE
JSON_NOEXCEPTION
JSONSV_NOEXCEPTION
)
target_precompile_headers(${TARGET_NAME} PRIVATE src/PCH.hpp)
target_include_directories(${TARGET_NAME}
PRIVATE
src/
external/fmt/include/
external/json-schema-validator/src/
external/nlohmann/single_include/
external/stduuid/include/
external/stduuid/gsl/
external/
)
if (${CMAKE_BUILD_TYPE} STREQUAL Debug)
set_directory_properties(PROPERTIES COMPILE_DEFINITIONS "_DEBUG")
else()
set_directory_properties(PROPERTIES COMPILE_DEFINITIONS "NDEBUG")
endif()
if (UNIX)
set(THREADS_PREFER_PTHREAD_FLAG ON)
endif()
find_package(Threads REQUIRED)
set(STATIC_LINKS
json-schema-validator
)
# imagehlp
if(WIN32)
if (MSVC)
target_link_libraries(${TARGET_NAME} Threads::Threads ${STATIC_LINKS} DbgHelp)
else()
target_link_libraries(${TARGET_NAME} -static Threads::Threads ${STATIC_LINKS} stdc++fs imagehlp)
endif()
elseif (CLANG)
target_link_libraries(${TARGET_NAME} Threads::Threads ${STATIC_LINKS})
else()
target_link_libraries(${TARGET_NAME} Threads::Threads ${STATIC_LINKS} stdc++fs uuid)
endif()
if(MSVC)
target_compile_definitions(${TARGET_NAME}
PRIVATE
_CRT_SECURE_NO_WARNINGS
_SILENCE_CXX17_RESULT_OF_DEPRECATION_WARNING
NOMINMAX
)
target_compile_options(${TARGET_NAME}
PRIVATE
/W4 /WX /utf-8 /GR- /MP
)
else()
target_compile_options(${TARGET_NAME}
PRIVATE
-Wall -Werror -Wextra -Wpedantic -Wshadow -Wunreachable-code -Wunused -Wignored-qualifiers -Wcast-align -Wdouble-promotion -Wformat-nonliteral -Wformat=2 -Winvalid-pch -Wmissing-declarations -Wmissing-include-dirs -Wredundant-decls -Wodr -fno-rtti -fdiagnostics-color=always
)
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "AppleClang")
target_link_libraries(${TARGET_NAME} "-framework CoreFoundation")
set_target_properties(${TARGET_NAME} PROPERTIES LINK_FLAGS "-Wl,-F/Library/Frameworks")
endif()