forked from cair/deep-rts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
299 lines (237 loc) · 8.6 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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
cmake_minimum_required(VERSION 3.17)
project(DeepRTS VERSION 1.1.0 LANGUAGES CXX)
set(BUILD_DOCS "OFF" CACHE STRING "Helpstring")
SET(ENABLE_LOCK "ON" CACHE STRING "If locking of cmake setup should be enabled. this should be disabled for third party builds.")
set(PYBIND11_FINDPYTHON "OFF")
# Lock this section so that parallel CMake runs won't clash on checkout in the same directory
if(ENABLE_LOCK)
file(LOCK ${CMAKE_SOURCE_DIR} DIRECTORY GUARD FILE)
endif()
# Includes
include(cmake/CMakeRC.cmake)
include(cmake/CPM.cmake)
include(cmake/pmm.cmake)
#############################################################################################
#####
##### C++ Compiler Setup
#####
#############################################################################################
set(CMAKE_CXX_STANDARD 17)
set(PYBIND11_CPP_STANDARD /std:c++17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_C_STANDARD 11)
if (LIBRARY_TYPE STREQUAL "SHARED")
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif ()
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_FOUND})
else()
message(WARNING "ccache not found, compilation will not be cached.")
endif()
if (WIN32)
set(OPTIMIZATIONS_RELEASE /Ox)
set(OPTIMIZATIONS_DEBUG /O0)
else ()
set(OPTIMIZATIONS_RELEASE -Ofast -ffast-math -Wall) # -march=native
set(OPTIMIZATIONS_DEBUG -Wall -O0)
endif ()
if (CMAKE_BUILD_TYPE STREQUAL "Release")
add_compile_options(${OPTIMIZATIONS_RELEASE})
else()
add_compile_options(${OPTIMIZATIONS_DEBUG})
add_compile_definitions(DEBUG=1)
add_compile_options(-gdwarf-4) # This allows per to debug with llvm
endif()
if (IS_PYBIND_BUILD)
set(LIBRARY_TYPE SHARED)
elseif (WIN32)
set(LIBRARY_TYPE STATIC)
endif ()
#############################################################################################
#####
##### VCPKG - Configuration
#####
#############################################################################################
if (WIN32)
set(VCPKG_TARGET_TRIPLET "x64-windows" CACHE STRING "" FORCE) # -static ?
set(VCPKG_STATIC_LINKING ON)
elseif (LINUX)
set(VCPKG_TARGET_TRIPLET x64-linux)
elseif(APPLE)
# Get the macOS version
execute_process(
COMMAND sw_vers -productVersion
OUTPUT_VARIABLE MACOS_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Extract the major and minor versions
string(REGEX REPLACE "^([0-9]+\\.[0-9]+).*" "\\1" MACOS_VERSION ${MACOS_VERSION})
# Set the deployment target
set(CMAKE_OSX_DEPLOYMENT_TARGET ${MACOS_VERSION} CACHE STRING "Minimum OS X deployment version")
endif()
#############################################################################################
#####
##### VCPKG - Dependencies
#####
#############################################################################################
# Read the contents of the file into a list
if(NOT (CMAKE_TOOLCHAIN_FILE MATCHES "vcpkg"))
file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/vcpkg_dependencies.txt" DEEPRTS_DEPENDENCIES)
# VCPKG - Install Dependencies
pmm(
VERBOSE
DEBUG
VCPKG
REVISION 2023.04.15
REQUIRES ${DEEPRTS_DEPENDENCIES}
TRIPLET ${VCPKG_TARGET_TRIPLET}
)
endif()
#############################################################################################
#####
##### CMAKE - Find Packages
#####
#############################################################################################
find_package(Python REQUIRED COMPONENTS Interpreter Development.Module)
set(PYTHON_EXECUTABLE ${Python_EXECUTABLE}) # xtensor has some troubles. fix
find_package(Python COMPONENTS NumPy)
if(NOT Python_NumPy_FOUND)
execute_process(
COMMAND bash -c "curl -L https://bootstrap.pypa.io/get-pip.py | ${Python_EXECUTABLE} && ${Python_EXECUTABLE} -m pip install numpy"
)
find_package(Python REQUIRED COMPONENTS NumPy)
endif()
find_package(spdlog CONFIG REQUIRED)
find_package(OpenCV CONFIG REQUIRED )
find_package(effolkronium_random CONFIG REQUIRED)
find_package(nlohmann_json CONFIG REQUIRED)
find_package(pybind11 CONFIG REQUIRED)
find_package(xtensor CONFIG REQUIRED)
find_library(blend2d blend2d REQUIRED)
find_path(blend2d_INCLUDES blend2d.h)
if (NOT TARGET xtensor-python)
CPMADDPackage(
NAME xtensor_py
GIT_REPOSITORY "https://github.com/xtensor-stack/xtensor-python"
GIT_TAG 0.25.3
)
endif()
set(DEEPRTS_LINK_TARGETS
spdlog::spdlog
DeepRTSAssets
effolkronium_random
xtensor::optimize
xtensor::use_xsimd
${blend2d}
opencv_core # todo remove
opencv_highgui # todo remove
)
#####################################
##
## CMRC - Assets for game
##
######################################
FILE(GLOB_RECURSE deeprts_assets RELATIVE ${PROJECT_SOURCE_DIR} DeepRTS/python/assets/*)
cmrc_add_resource_library(DeepRTSAssets ALIAS deeprts::assets
WHENCE
DeepRTS/python
${deeprts_assets}
)
set_property(TARGET DeepRTSAssets PROPERTY POSITION_INDEPENDENT_CODE ON)
file(GLOB_RECURSE DEEPRTS_SOURCE_FILES src/*.cpp)
set(DEEPRTS_PYBIND_SOURCES
bindings/Random.cpp
bindings/utilities/ndarray_converter.cpp
bindings/Scenarios.cpp
bindings/trampolines/PyScenarioCriteria.h
bindings/Constants.cpp
bindings/BaseState.cpp
bindings/UnitManager.cpp
bindings/Unit.cpp
bindings/Map.cpp
bindings/Tile.cpp
bindings/Tilemap.cpp
bindings/Game.cpp
bindings/Player.cpp
bindings/Config.cpp
bindings/DeepRTS.cpp
)
set(DEEPRTS_INCLUDES
${blend2d_INCLUDES}
include/DeepRTS
${xtensor_py_SOURCE_DIR}/include
)
if (NOT DEFINED PYTHON_BUILD)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/DeepRTS")
endif ()
if(PYTHON_BUILD)
pybind11_add_module(libdeeprts ${DEEPRTS_PYBIND_SOURCES} ${DEEPRTS_SOURCE_FILES})
target_link_libraries(libdeeprts
INTERFACE
xtensor-python
PRIVATE
Python::NumPy ${DEEPRTS_LINK_TARGETS}
)
target_include_directories(libdeeprts
PRIVATE
${DEEPRTS_INCLUDES}
)
endif()
# Dont create C++ Executable for Python builds (saves time)
if (NOT DEFINED PYTHON_BUILD)
add_library(DeepRTSLib STATIC ${DEEPRTS_SOURCE_FILES})
target_include_directories(
DeepRTSLib
PUBLIC
include/
include/DeepRTS
${DEEPRTS_INCLUDES}
)
target_compile_definitions(DeepRTSLib
PUBLIC
EMBEDDED=1
)
target_link_libraries(DeepRTSLib
PUBLIC
xtensor-python
pybind11::embed
${DEEPRTS_LINK_TARGETS}
)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/DeepRTS") # Creates Engine in DeepRTS package (instead of root)
add_executable(DeepRTSGame src/main.cpp)
#target_include_directories(DeepRTSGame
# PRIVATE
# DeepRTSLib
# )
target_link_libraries(DeepRTSGame
PRIVATE
DeepRTSLib
)
# make python source the build dir.
execute_process(
COMMAND ln -sf ${PROJECT_SOURCE_DIR}/DeepRTS ${CMAKE_BINARY_DIR}
)
endif()
#############################################################################################
#####
##### Documentation
#####
#############################################################################################
find_package(Doxygen)
if (DOXYGEN_FOUND AND NOT PYTHON_BUILD AND BUILD_DOCS)
# set input and output files
set(DOXYGEN_IN Doxyfile.in)
set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
# request to configure the file
configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)
message("Doxygen build started")
# note the option ALL which allows to build the docs together with the application
add_custom_target( doc_doxygen ALL
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen"
VERBATIM )
else ()
message(WARNING "Doxygen need to be installed to generate the doxygen documentation")
endif ()