-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
173 lines (137 loc) · 7.06 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
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(doodle_jump)
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)
option(BUILD_SHARED_LIBS "Build SFML as shared library" FALSE)
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "install_dir" CACHE PATH "..." FORCE)
endif()
# 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)
# see https://gitlab.kitware.com/cmake/cmake/-/issues/24922
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 "GNU")
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>")
endif()
elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
if("${CMAKE_CXX_COMPILER_VERSION}" MATCHES "14.")
# 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:124
FetchContent_Declare(
SFML
GIT_REPOSITORY https://github.com/SFML/SFML.git
GIT_TAG 2.6.0
# GIT_TAG 11b73743c42cf7ecd7c596ba83fdbf1150ffa96c # 2.6.0
# GIT_TAG b8f72c7cf2a7f770fed6955d5cdc14b11b9af365 # master as of 2023-07-29
# GIT_TAG origin/master
GIT_SHALLOW 1 # works only with branches or tags, not with arbitrary commit hashes
)
FetchContent_MakeAvailable(SFML)
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
else()
set_custom_stdlib_and_sanitizers(sfml-system false)
set_custom_stdlib_and_sanitizers(sfml-window false)
set_custom_stdlib_and_sanitizers(sfml-graphics false)
endif()
# set_property(TARGET sfml-system PROPERTY CXX_STANDARD 17)
# set_property(TARGET sfml-window PROPERTY CXX_STANDARD 17)
# set_property(TARGET sfml-graphics PROPERTY CXX_STANDARD 17)
###############################################################################
# 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
doodle_jump/player/Player.cpp
doodle_jump/game/Game.cpp
doodle_jump/game_object/GameObject.cpp
doodle_jump/platform/Platform.cpp
doodle_jump/powerups/Powerups.cpp
doodle_jump/screen/GameOver.cpp
doodle_jump/screen/GameScreen.cpp
doodle_jump/screen/MainMenu.cpp
doodle_jump/screen/PlayScreen.cpp
doodle_jump/exceptions/Exceptions.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()
# set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 23)
###############################################################################
# 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} PRIVATE sfml-graphics sfml-window sfml-system Threads::Threads)
if(APPLE)
elseif(UNIX)
target_link_libraries(${PROJECT_NAME} PRIVATE 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 assets fonts DESTINATION bin)
# install(FILES some_file1.txt some_file2.md DESTINATION bin)