forked from Lactozilla/HatchGameEngine
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
218 lines (184 loc) · 6.08 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
cmake_minimum_required(VERSION 3.10)
# set the project name and version
project(HatchGameEngine VERSION 1.2.2)
# specify the C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
set(CMAKE_CXX_FLAGS "/wd4244 /wd4267 /wd4305 /wd4717 /EHsc")
else()
set(CMAKE_CXX_FLAGS_RELEASE "-Ofast -march=nocona")
endif()
# Set up CMake modules path
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
file(GLOB_RECURSE C_SOURCES RELATIVE ${CMAKE_SOURCE_DIR} "source/*.c")
file(GLOB_RECURSE CPP_SOURCES RELATIVE ${CMAKE_SOURCE_DIR} "source/*.cpp")
set(HATCH_SOURCES ${C_SOURCES} ${CPP_SOURCES})
set(HATCH_TARGET_NAME ${PROJECT_NAME})
if(TARGET_NAME)
set(HATCH_TARGET_NAME ${TARGET_NAME})
endif()
if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows")
add_definitions(-DLINUX -DTARGET_NAME=\"${HATCH_TARGET_NAME}\"
-DNO_LIBAV
)
else()
# Cross compiling a Windows executable
add_definitions(-DWIN32 -DTARGET_NAME=\"${HATCH_TARGET_NAME}\"
-DNO_LIBAV
-DGLEW_STATIC
-D_WINDOWS
)
endif()
# Build options
option(ENABLE_SCRIPT_COMPILING "Enable script compiling" ON)
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
option(WINDOWS_USE_RESOURCE_FILE "Use resource file (Windows)" ON)
endif()
option(USE_OPEN_ASSET_IMPORT_LIBRARY "Use Open Asset Import Library" ON)
option(USE_FREETYPE_LIBRARY "Use FreeType" OFF)
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
set(USE_OPEN_ASSET_IMPORT_LIBRARY OFF)
endif()
# Renderers
option(USING_OPENGL "Use OpenGL" ON)
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
option(USING_DIRECT3D "Use Direct3D" OFF)
endif()
if(USE_FREETYPE_LIBRARY)
add_definitions(-DUSING_FREETYPE)
endif()
if(USING_OPENGL)
add_definitions(-DUSING_OPENGL)
endif()
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows" AND USING_DIRECT3D)
add_definitions(-DUSING_DIRECT3D)
endif()
if(NOT ENABLE_SCRIPT_COMPILING)
add_definitions(-DNO_SCRIPT_COMPILING)
endif()
add_definitions(-DMINIZ_NO_ARCHIVE_APIS -DMINIZ_NO_ARCHIVE_WRITING_APIS -DMINIZ_NO_TIME )
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set(MAKEHEADERS_BINARY makeheaders.exe)
else()
set(MAKEHEADERS_BINARY makeheaders)
endif()
add_custom_target(makeheaders ALL
COMMAND ${CMAKE_SOURCE_DIR}/tools/${MAKEHEADERS_BINARY} source/
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
BYPRODUCTS "${CMAKE_SOURCE_DIR}/include/makeheaders.bin" "${CMAKE_SOURCE_DIR}/include/Engine"
COMMENT "Generating header files")
find_file(REPO_DIR NAMES .git PATHS ${CMAKE_SOURCE_DIR} NO_DEFAULT_PATH)
if (REPO_DIR)
execute_process(
COMMAND git log -1 --format=%H
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE)
add_definitions("-DGIT_COMMIT_HASH=\"${GIT_COMMIT_HASH}\"")
endif()
add_executable(${PROJECT_NAME} ${HATCH_SOURCES})
add_dependencies(${PROJECT_NAME} makeheaders)
set(OUT_EXEC_NAME ${PROJECT_NAME})
# Change executable name
if(EXECUTABLE_NAME)
set(OUT_EXEC_NAME ${EXECUTABLE_NAME})
endif()
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "${OUT_EXEC_NAME}-${CMAKE_BUILD_TYPE}")
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set(WIN_RES_FILE meta/win/icon.rc)
if(RESOURCE_FILE)
set(WIN_RES_FILE ${RESOURCE_FILE})
endif()
endif()
# Find the includes
if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows")
find_package(SDL2 REQUIRED)
if(USE_FREETYPE_LIBRARY)
find_package(Freetype REQUIRED)
endif()
find_package(PNG)
if(PNG_FOUND)
add_definitions(-DUSING_LIBPNG)
endif()
if(USE_OPEN_ASSET_IMPORT_LIBRARY)
find_package(assimp)
if(assimp_FOUND)
add_definitions(-DUSING_ASSIMP)
set(ASSIMP_INCLUDE_DIRS assimp_INCLUDE_DIRS)
set(ASSIMP_LIBRARIES assimp)
endif()
endif()
if(USING_OPENGL)
set(OPENGL_LIBRARIES "-lGL -lGLEW")
endif()
else()
set(SDL2_INCLUDE_DIRS "${CMAKE_CURRENT_LIST_DIR}/meta/win/include/SDL2/")
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
if(USING_OPENGL)
set(OPENGL_LIBRARIES "${CMAKE_CURRENT_LIST_DIR}/meta/win/lib/msvc/x64/glew32s.lib")
endif()
else()
if(USE_OPEN_ASSET_IMPORT_LIBRARY)
set(ASSIMP_INCLUDE_DIRS "${CMAKE_CURRENT_LIST_DIR}/meta/win/include/assimp/")
set(ASSIMP_LIBRARIES "${CMAKE_CURRENT_LIST_DIR}/meta/win/lib/mingw/${TOOLCHAIN_PREFIX}/libassimp.a;${CMAKE_CURRENT_LIST_DIR}/meta/win/lib/mingw/${TOOLCHAIN_PREFIX}/libzlibstatic.a")
endif()
if(USING_OPENGL)
set(OPENGL_LIBRARIES "${CMAKE_CURRENT_LIST_DIR}/meta/win/lib/mingw/${TOOLCHAIN_PREFIX}/libglew32.a;-lgdi32;-lopengl32")
endif()
endif()
endif()
# Add needed directories
include_directories(
include
source
${SDL2_INCLUDE_DIRS}
${ASSIMP_INCLUDE_DIRS}
)
if(USE_OPEN_ASSET_IMPORT_LIBRARY)
include_directories(${ASSIMP_INCLUDE_DIRS})
endif()
# Include libraries
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
# Add all of the Windows include files
include_directories(
meta/win/include
)
if(WINDOWS_USE_RESOURCE_FILE)
target_sources(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_LIST_DIR}/${WIN_RES_FILE})
endif()
else()
if(USE_FREETYPE_LIBRARY)
include_directories(
${FREETYPE_INCLUDE_DIRS}
)
endif()
endif()
# Add libraries
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
target_link_libraries(${PROJECT_NAME} "${CMAKE_CURRENT_LIST_DIR}/meta/win/lib/msvc/x64/SDL2.lib"
Ws2_32.lib opengl32.lib)
else()
target_link_libraries(${PROJECT_NAME}
"${CMAKE_CURRENT_LIST_DIR}/meta/win/lib/mingw/${TOOLCHAIN_PREFIX}/libSDL2.a"
-static -mwindows -lmingw32 -lm -ldinput8 -ldxguid -ldxerr8
-luser32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32
-lversion -luuid -lhid -lsetupapi -lws2_32)
endif()
add_definitions(-DSDL_MAIN_HANDLED)
else()
target_link_libraries(${PROJECT_NAME} ${SDL2_LIBRARIES})
endif()
if(USE_FREETYPE_LIBRARY)
target_link_libraries(${PROJECT_NAME} ${FREETYPE_LIBRARIES})
endif()
if(PNG_FOUND)
target_link_libraries(${PROJECT_NAME} ${PNG_LIBRARIES})
endif()
if(USE_OPEN_ASSET_IMPORT_LIBRARY)
target_link_libraries(${PROJECT_NAME} ${ASSIMP_LIBRARIES})
endif()
if(USING_OPENGL)
target_link_libraries(${PROJECT_NAME} ${OPENGL_LIBRARIES})
endif()