generated from mcmarius/oop-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
146 lines (113 loc) · 6.63 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
139
140
141
142
143
144
145
146
cmake_minimum_required(VERSION 3.24)
# NOTE: update executable name in .github/workflows/cmake.yml:25 when changing executable name in this file
# for now, the project name is used as the executable name
project(oop)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
option(WARNINGS_AS_ERRORS "Treat warnings as errors" OFF)
# disable sanitizers when releasing executables without explicitly requested debug info
# use generator expressions to set flags correctly in both single and multi config generators
set(is_debug "$<CONFIG:Debug>")
set(is_rel_with_deb "$<CONFIG:RelWithDebInfo>")
set(debug_mode "$<OR:${is_debug},${is_rel_with_deb}>")
###############################################################################
# custom functions
function(set_custom_stdlib_and_sanitizers target add_apple_asan)
if(MSVC)
set_target_properties(${target} PROPERTIES VS_USER_PROPS "${CMAKE_SOURCE_DIR}/disable_modules.props")
target_compile_options(${target} PRIVATE "$<${debug_mode}:/fsanitize=address>" /experimental:module-)
return()
endif()
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
target_compile_options(${target} PRIVATE -stdlib=libc++)
target_link_options(${target} PRIVATE -stdlib=libc++)
endif()
if(APPLE)
# first check Apple since Apple is also a kind of Unix
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" AND add_apple_asan MATCHES true)
target_compile_options(${target} PRIVATE "$<${debug_mode}:-fsanitize=address,undefined>")
target_link_options(${target} PRIVATE "$<${debug_mode}:-fsanitize=address,undefined>")
endif()
elseif(UNIX)
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
if("${CMAKE_CXX_COMPILER_VERSION}" MATCHES "12.")
# check leaks on Linux since macOS does not support the leaks sanitizer yet
# leaks sanitizer is enabled by default on Linux, so we do not need to enable it explicitly
target_compile_options(${target} PRIVATE "$<${debug_mode}:-fsanitize=address,undefined>")
target_link_options(${target} PRIVATE "$<${debug_mode}:-fsanitize=address,undefined>")
elseif("${CMAKE_CXX_COMPILER_VERSION}" MATCHES "13.")
# use semi-colons instead of spaces to separate arguments
# it is recommended to quote generator expressions in order to avoid unintentional splitting
target_compile_options(${target} PRIVATE "$<${debug_mode}:-fsanitize=memory,undefined;-fsanitize-recover=memory,undefined;-fsanitize-memory-track-origins>")
target_link_options(${target} PRIVATE "$<${debug_mode}:-fsanitize=memory,undefined;-fsanitize-recover=memory,undefined;-fsanitize-memory-track-origins;-Wl,-rpath,tools/llvm-project/build/lib>")
else()
message("No matching Clang version to add sanitizer flags!")
endif()
endif()
endif()
endfunction()
###############################################################################
# external dependencies with FetchContent
include(FetchContent)
# NOTE: Also update SFML_VERSION env var in .github/workflows/cmake.yml:122
FetchContent_Declare(
SFML
GIT_REPOSITORY https://github.com/SFML/SFML.git
GIT_TAG 863fef024619da7f59b6404087b454337a172ac1 # 2.6.x as of 2022-08-30
# GIT_TAG 72d88033e2f24be0fb1e9df614a56f3d5274154c # master as of 2022-08-30
# GIT_TAG f7c88ee7ef4e1c705531cd614efb7dcff1f873cb # last commit merged in master before API breakage (2022-04-21)
# GIT_TAG origin/master
# GIT_TAG origin/2.6.x
# GIT_SHALLOW 1 # works only with branches or tags, not with arbitrary commit hashes
)
FetchContent_MakeAvailable(SFML)
set_custom_stdlib_and_sanitizers(sfml-system false)
set_custom_stdlib_and_sanitizers(sfml-window false)
set_custom_stdlib_and_sanitizers(sfml-graphics false)
###############################################################################
# external dependencies with find_package
find_package(Threads REQUIRED)
if(APPLE)
elseif(UNIX)
find_package(X11)
endif()
###############################################################################
# NOTE: update executable name in .github/workflows/cmake.yml:25 when changing name here
add_executable(${PROJECT_NAME} main.cpp Rating.cpp Rating.h Point.cpp Point.h Button.cpp Button.h Attraction.cpp Attraction.h Destination.cpp Destination.h Characteristics.h Frame.cpp Frame.h startFrame.cpp startFrame.h TextBox.cpp TextBox.h Question.cpp Question.h ratingQuestion.cpp ratingQuestion.h User.cpp User.h QFrame.cpp QFrame.h tfQuestion.cpp tfQuestion.h FrameErr.cpp FrameErr.h destinationFrame.cpp destinationFrame.h boxQuestion.cpp boxQuestion.h Button_builder.cpp Button_builder.h Button_factory.cpp Button_factory.h Characteristics.cpp)
###############################################################################
# target definitions
if(GITHUB_ACTIONS)
message("NOTE: GITHUB_ACTIONS defined")
target_compile_definitions(${PROJECT_NAME} PRIVATE GITHUB_ACTIONS)
endif()
###############################################################################
if(WARNINGS_AS_ERRORS)
set_property(TARGET ${PROJECT_NAME} PROPERTY COMPILE_WARNING_AS_ERROR ON)
endif()
# custom compiler flags
message("Compiler: ${CMAKE_CXX_COMPILER_ID} version ${CMAKE_CXX_COMPILER_VERSION}")
if(MSVC)
target_compile_options(${PROJECT_NAME} PRIVATE /W4 /permissive- /wd4244 /wd4267 /wd4996 /external:anglebrackets /external:W0)
else()
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -pedantic)
endif()
###############################################################################
# sanitizers
set_custom_stdlib_and_sanitizers(${PROJECT_NAME} true)
###############################################################################
# use SYSTEM so clang-tidy does not report warnings from these directories
#target_include_directories(${PROJECT_NAME} SYSTEM PRIVATE ext/<SomeHppLib>/include)
target_include_directories(${PROJECT_NAME} SYSTEM PRIVATE ${SFML_SOURCE_DIR}/include)
target_link_directories(${PROJECT_NAME} PRIVATE ${SFML_BINARY_DIR}/lib)
target_link_libraries(${PROJECT_NAME} sfml-graphics sfml-window sfml-system Threads::Threads)
if(APPLE)
elseif(UNIX)
target_link_libraries(${PROJECT_NAME} X11)
endif()
###############################################################################
# copy binaries to "bin" folder; these are uploaded as artifacts on each release
# update name in .github/workflows/cmake.yml:29 when changing "bin" name here
install(TARGETS ${PROJECT_NAME} DESTINATION bin)
install(DIRECTORY fonts DESTINATION bin)
install(FILES destinations.txt questions.txt DESTINATION bin)