-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
141 lines (119 loc) · 4.01 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
cmake_minimum_required(VERSION 3.21)
if(PROJECT_IS_TOP_LEVEL)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "" FORCE)
endif()
endif()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Directory to build executable into
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/game")
# set project name and version
project(Game
LANGUAGES CXX
VERSION 0.1
)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Prefer new GLVND over OLD
set(OpenGL_GL_PREFERENCE GLVND)
add_executable(Game)
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
file(GLOB RESOURCES
"Assets/SFX/*.ogg"
"Assets/Sprites/*.png"
"maps/*.png"
)
target_sources(Game PRIVATE
src/macos/platform_macos.mm
src/macos/platform_macos.h
${RESOURCES})
target_compile_definitions(Game PRIVATE
"PLATFORM_MACOS"
)
set_target_properties(Game PROPERTIES
MACOSX_BUNDLE TRUE
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_SOURCE_DIR}/src/macos/Info.plist.in"
XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER com.moonburnt.fortune-crawler
XCODE_ATTRIBUTE_COMBINE_HIDPI_IMAGES YES
XCODE_ATTRIBUTE_CURRENT_PROJECT_VERSION 0.0.1
XCODE_ATTRIBUTE_MARKETING_VERSION 0.0.1
RESOURCE "${RESOURCES}"
)
elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows")
target_sources(Game PRIVATE
src/windows/platform_windows.hpp
src/windows/platform_windows.cpp
)
target_compile_definitions(Game PRIVATE
"PLATFORM_WINDOWS"
)
elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_sources(Game PRIVATE
src/linux/platform_linux.hpp
src/linux/platform_linux.cpp
)
target_compile_definitions(Game PRIVATE
"PLATFORM_LINUX"
)
else()
message(FATAL_ERROR "Unsupported OS")
endif()
target_sources(Game PRIVATE
src/app.cpp
src/app.hpp
src/event_screens.cpp
src/event_screens.hpp
src/common.cpp
src/common.hpp
src/entity.cpp
src/entity.hpp
src/level.cpp
src/level.hpp
src/loader.cpp
src/loader.hpp
src/menus.cpp
src/menus.hpp
src/mapgen.cpp
src/mapgen.hpp
src/main.cpp
src/platform.hpp
src/platform.cpp
)
target_compile_options(Game PRIVATE
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:GNU>>:-Wall -Wextra -Wpedantic -Werror -Wextra-semi -Wsuggest-override -Wno-missing-field-initializers>
$<$<CXX_COMPILER_ID:MSVC>:/Wall /w34263 /w34266>
$<$<AND:$<CONFIG:Debug>,$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:GNU>>>:-fsanitize=address>
)
target_link_options(Game PRIVATE
$<$<AND:$<CONFIG:Debug>,$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:GNU>>>:-fsanitize=address>)
if (CMAKE_SYSTEM_NAME STREQUAL "Windows" OR CMAKE_SYSTEM_NAME STREQUAL "Linux")
# Custom command to be used after Game is built
# This should copy assets into the directory with game's binary
add_custom_command(TARGET Game POST_BUILD
COMMAND cp -r ./Assets ./maps "${CMAKE_BINARY_DIR}/game"
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
COMMENT "Copying assets to ${CMAKE_BINARY_DIR}/game"
)
endif()
target_include_directories(Game PRIVATE
"${CMAKE_SOURCE_DIR}/src"
)
# Setup engine
add_subdirectory("${CMAKE_SOURCE_DIR}/dependencies/engine")
target_link_libraries(Game engine)
target_include_directories(Game PRIVATE ${engine_INCLUDE_DIRS})
# Setup nlohmann_json
add_subdirectory("${CMAKE_SOURCE_DIR}/dependencies/nlohmann_json")
set_target_properties(nlohmann_json PROPERTIES LINKER_LANGUAGE CXX)
target_link_libraries(Game nlohmann_json::nlohmann_json)
# Custom targets to be used instead of --build
add_custom_target(compile_commands
WORKING_DIRECTORY ${CMAKE_BUILD_DIR}
BYPRODUCTS ${CMAKE_SOURCE_DIR}/compile_commands.json
COMMAND cp -f ./compile_commands.json ${CMAKE_SOURCE_DIR}/compile_commands.json
VERBATIM)
add_custom_target(format
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMAND find src \( -name '*.cpp' -o -name '*.hpp' \) -exec clang-format -style=file -i {} \;
VERBATIM)