-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
CMakeLists.txt
184 lines (159 loc) · 7.04 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
cmake_minimum_required(VERSION 3.15)
project(endstone LANGUAGES CXX)
# Check if the project is being used as dependency
if (NOT CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(EndstoneHeaders)
return()
endif ()
# =======
# options
# =======
option(CODE_COVERAGE "Enable code coverage reporting" false)
if (NOT BUILD_TESTING STREQUAL OFF)
enable_testing()
if (CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g --coverage")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g --coverage")
endif ()
endif ()
# ===================
# compile definitions
# ===================
add_compile_definitions(PYBIND11_DETAILED_ERROR_MESSAGES)
add_compile_definitions(ENTT_SPARSE_PAGE=2048)
add_compile_definitions(ENTT_PACKED_PAGE=128)
if (ENDSTONE_DEVTOOLS_ENABLED)
add_compile_definitions(ENDSTONE_DEVTOOLS)
endif ()
# ========
# packages
# ========
find_package(base64 CONFIG REQUIRED)
find_package(Boost CONFIG REQUIRED)
find_package(concurrentqueue CONFIG REQUIRED)
find_package(cpptrace CONFIG REQUIRED)
find_package(EnTT CONFIG REQUIRED)
find_package(expected-lite REQUIRED)
find_package(fmt CONFIG REQUIRED)
find_package(funchook CONFIG REQUIRED)
find_package(glm CONFIG REQUIRED)
find_package(magic_enum CONFIG REQUIRED)
find_package(Microsoft.GSL CONFIG REQUIRED)
find_package(nlohmann_json CONFIG REQUIRED)
find_package(Python COMPONENTS Interpreter Development.Module REQUIRED)
find_package(pybind11 CONFIG REQUIRED)
find_package(spdlog CONFIG REQUIRED)
find_package(tomlplusplus CONFIG REQUIRED)
if (UNIX)
find_package(libelf CONFIG REQUIRED)
endif ()
find_package(GTest CONFIG REQUIRED)
# =================
# endstone::headers
# =================
add_library(endstone_headers INTERFACE)
add_library(endstone::headers ALIAS endstone_headers)
target_include_directories(endstone_headers INTERFACE include)
target_link_libraries(endstone_headers INTERFACE fmt::fmt nonstd::expected-lite)
include(GNUInstallDirs)
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
# ================
# endstone::python
# ================
file(GLOB_RECURSE ENDSTONE_PYTHON_SOURCE_FILES CONFIGURE_DEPENDS "src/endstone_python/*.cpp")
pybind11_add_module(endstone_python MODULE ${ENDSTONE_PYTHON_SOURCE_FILES})
target_include_directories(endstone_python PUBLIC include)
target_link_libraries(endstone_python PRIVATE endstone::headers)
include(GNUInstallDirs)
install(TARGETS endstone_python DESTINATION "endstone/_internal/" COMPONENT endstone_wheel OPTIONAL)
# ==============
# endstone::core
# ==============
file(GLOB_RECURSE ENDSTONE_CORE_SOURCE_FILES CONFIGURE_DEPENDS "src/endstone_core/*.cpp")
add_library(endstone_core ${ENDSTONE_CORE_SOURCE_FILES})
add_library(endstone::core ALIAS endstone_core)
target_link_libraries(endstone_core PUBLIC endstone::headers aklomp::base64 boost::boost concurrentqueue::concurrentqueue
cpptrace::cpptrace EnTT::EnTT glm::glm magic_enum::magic_enum Microsoft.GSL::GSL nlohmann_json::nlohmann_json
pybind11::module spdlog::spdlog tomlplusplus::tomlplusplus)
if (UNIX)
target_link_libraries(endstone_core PUBLIC ${CMAKE_DL_LIBS})
target_compile_definitions(endstone_core PUBLIC ENDSTONE_DISABLE_DEVTOOLS)
endif ()
target_compile_definitions(endstone_core PUBLIC ENDSTONE_VERSION="${ENDSTONE_VERSION}")
include(GNUInstallDirs)
install(TARGETS endstone_core
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
# ==================
# endstone::devtools
# ==================
if (ENDSTONE_DEVTOOLS_ENABLED)
find_package(glew CONFIG REQUIRED)
find_package(glfw3 CONFIG REQUIRED)
find_package(imgui CONFIG REQUIRED)
find_package(zstr CONFIG REQUIRED)
file(GLOB_RECURSE ENDSTONE_DEVTOOLS_SOURCE_FILES CONFIGURE_DEPENDS "src/endstone_devtools/*.cpp")
add_library(endstone_devtools ${ENDSTONE_DEVTOOLS_SOURCE_FILES})
add_library(endstone::devtools ALIAS endstone_devtools)
target_include_directories(endstone_devtools PRIVATE "include/endstone/detail/devtools/imgui")
target_link_libraries(endstone_devtools PUBLIC endstone::core GLEW::GLEW glfw imgui::imgui zstr::zstr)
include(GNUInstallDirs)
install(TARGETS endstone_devtools
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
endif ()
# =================
# endstone::runtime
# =================
file(GLOB_RECURSE ENDSTONE_RUNTIME_SOURCE_FILES CONFIGURE_DEPENDS "src/endstone_runtime/*.cpp")
add_library(endstone_runtime SHARED ${ENDSTONE_RUNTIME_SOURCE_FILES})
add_library(endstone::runtime ALIAS endstone_runtime)
target_link_libraries(endstone_runtime PRIVATE endstone::core funchook::funchook)
if (ENDSTONE_DEVTOOLS_ENABLED)
target_link_libraries(endstone_runtime PRIVATE endstone::devtools)
endif ()
if (WIN32)
target_link_libraries(endstone_runtime PRIVATE dbghelp.lib ws2_32.lib)
target_link_options(endstone_runtime PRIVATE "/INCREMENTAL:NO")
endif ()
if (UNIX)
target_link_libraries(endstone_runtime PRIVATE libelf::libelf)
target_link_options(endstone_runtime PRIVATE "-Wl,--exclude-libs,ALL")
target_compile_options(endstone_runtime PRIVATE "-fvisibility=hidden" "-fms-extensions")
endif ()
include(GNUInstallDirs)
install(TARGETS endstone_runtime
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install(TARGETS endstone_runtime DESTINATION "endstone/_internal/" COMPONENT endstone_wheel OPTIONAL)
if (CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
if (MSVC)
install(FILES $<TARGET_PDB_FILE:endstone_runtime> DESTINATION "endstone/_internal/" COMPONENT endstone_wheel OPTIONAL)
elseif (UNIX)
add_custom_command(TARGET endstone_python POST_BUILD COMMAND ${CMAKE_STRIP} --strip-debug --strip-unneeded $<TARGET_FILE:endstone_python>)
endif ()
endif ()
if (WIN32)
add_library(endstone_runtime_loader SHARED "src/endstone_runtime/loader.cpp")
target_compile_definitions(endstone_runtime_loader PRIVATE _CRT_SECURE_NO_WARNINGS ENDSTONE_RUNTIME_LOADER)
install(TARGETS endstone_runtime_loader DESTINATION "endstone/_internal/" COMPONENT endstone_wheel OPTIONAL)
endif ()
# =====
# tests
# =====
if (NOT BUILD_TESTING STREQUAL OFF)
add_library(test_plugin SHARED tests/plugin/test_plugin.cpp)
target_link_libraries(test_plugin PRIVATE endstone::headers)
set_target_properties(test_plugin PROPERTIES LIBRARY_OUTPUT_DIRECTORY "plugins")
set_target_properties(test_plugin PROPERTIES RUNTIME_OUTPUT_DIRECTORY "plugins")
file(GLOB_RECURSE ENDSTONE_TEST_FILES CONFIGURE_DEPENDS "tests/*.cpp")
add_executable(endstone_test ${ENDSTONE_TEST_FILES})
add_dependencies(endstone_test test_plugin)
target_link_libraries(endstone_test PRIVATE endstone::core GTest::gtest_main GTest::gmock_main)
include(GoogleTest)
gtest_discover_tests(endstone_test)
endif ()