-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
161 lines (118 loc) · 3.73 KB
/
CMakeLists.txt
File metadata and controls
161 lines (118 loc) · 3.73 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
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
cmake_minimum_required(VERSION 3.14)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Uncomment these to put the dlls in the same directory as the executable (useful if you don't have SDL2 installed and you're building from source)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
# Uncomment if you need to do some debugging :)
# set(CMAKE_FIND_DEBUG_MODE TRUE)
# Uncomment if no console should be created
# set(WINDOWS_NO_CONSOLE)
# Change your project name here
project(YourGame)
# Add your sources here (adding headers is optional, but helps some CMake generators)
set(GAME_SOURCES
"Application.cpp"
"Game.cpp"
"MenuStages.cpp"
"GameStages.cpp"
)
# To be used instead of set(GAME_SOURCES ...)
# set(USE_GLOB)
set(FRAMEWORK_SOURCES
"BaseGame.cpp"
"BaseStage.cpp"
"BaseTransition.cpp"
"FadeTransition.cpp"
"Input.cpp"
"Keys.cpp"
"Mouse.cpp"
"Button.cpp"
"Audio.cpp"
"Graphics.cpp"
"Window.cpp"
"Font.cpp"
"Image.cpp"
"Spritesheet.cpp"
"Animation.cpp"
"Colour.cpp"
"Maths.cpp"
"Transform.cpp"
"Timer.cpp"
"Curves.cpp"
"File.cpp"
"URL.cpp"
"SDLUtils.cpp"
)
list(TRANSFORM GAME_SOURCES PREPEND src/game/)
list(TRANSFORM FRAMEWORK_SOURCES PREPEND src/framework/)
if (USE_GLOB)
# Alternatively, let glob find all the .cpp files in the src directory and subdirectories... (CMake won't detect when new files are added)
file(GLOB GAME_SOURCES RELATIVE ${CMAKE_SOURCE_DIR} "src/game/*.cpp")
# file(GLOB FRAMEWORK_SOURCES RELATIVE ${CMAKE_SOURCE_DIR} "src/framework/*.cpp")
endif()
set(PROJECT_SOURCES ${FRAMEWORK_SOURCES};${GAME_SOURCES})
# Add any other files you want in the release here
set(PROJECT_DISTRIBS LICENSE README.md)
set(PROJECT_ASSETS assets)
if(APPLE)
# Need to put the asssets inside the bundle (this is where SDL_GetBasePath points to)
set(ASSETS_DEST bin/$<TARGET_FILE_NAME:${PROJECT_NAME}>.app/Contents/Resources)
else()
set(ASSETS_DEST .)
endif()
set(CONSOLE_FLAG)
if (WINDOWS_NO_CONSOLE)
set(CONSOLE_FLAG WIN32)
endif()
add_executable(${PROJECT_NAME} ${CONSOLE_FLAG} MACOSX_BUNDLE ${PROJECT_SOURCES})
include(fetch/get_json.cmake)
include(fetch/get_sdl2.cmake)
include_directories(${PROJECT_SOURCE_DIR}/include/framework)
include_directories(${PROJECT_SOURCE_DIR}/include/game)
include_directories(${PROJECT_SOURCE_DIR}/include/external)
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
# Link
target_link_libraries(${PROJECT_NAME} SDL2::SDL2main SDL2::SDL2 SDL2_image::SDL2_image SDL2_mixer::SDL2_mixer nlohmann_json::nlohmann_json)
# Setup release packages
install(TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION bin
BUNDLE DESTINATION bin
)
install(FILES ${PROJECT_DISTRIBS}
DESTINATION .
)
install(DIRECTORY ${PROJECT_ASSETS}
DESTINATION ${ASSETS_DEST}
FILES_MATCHING
PATTERN "*.png"
PATTERN "*.json"
)
if (UNIX AND NOT APPLE)
# Todo: auto-gen this file using current PROJECT_NAME
install(FILES extras/Launcher_Linux.sh
DESTINATION .
)
endif()
if (NOT EMSCRIPTEN)
# Install dependencies
set(DEP_SEARCH_DIRS)
# We built these, so we're installing them
if(TARGET SDL2)
list(APPEND DEP_SEARCH_DIRS $<TARGET_FILE_DIR:SDL2>)
endif()
if(TARGET SDL2_image)
list(APPEND DEP_SEARCH_DIRS $<TARGET_FILE_DIR:SDL2_image>)# $<TARGET_FILE_DIR:png> $<TARGET_FILE_DIR:zlib>)
endif()
set(EXE_SUFFIX)
if(APPLE)
set(EXE_SUFFIX ".app")
endif()
install(CODE "
include(BundleUtilities)
fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/bin/$<TARGET_FILE_NAME:${PROJECT_NAME}>${EXE_SUFFIX}\" \"\" \"${DEP_SEARCH_DIRS}\")
")
endif()
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY OFF)
set(CPACK_GENERATOR "ZIP" "TGZ")
include(CPack)