Repository navigation
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
194 lines (169 loc) · 6.58 KB
/
Copy pathCMakeLists.txt
File metadata and controls
194 lines (169 loc) · 6.58 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
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
cmake_minimum_required(VERSION 3.21)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
if ("${CMAKE_SYSTEM_NAME}" STREQUAL "iOS" OR IOS)
set(CMAKE_OSX_ARCHITECTURES "arm64")
else()
set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64")
endif()
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
project(LuauAPI)
include(FetchContent)
include(CTest)
option(LUAUAPI_BUILD_TESTS "Build LuauAPI host unit tests" OFF)
option(LUAUAPI_HOST_ONLY "Host-only configure without Geode SDK or configure-time codegen listing" OFF)
include(cmake/Helpers.cmake)
include(cmake/Luau.cmake)
include(cmake/Glm.cmake)
if (NOT LUAUAPI_HOST_ONLY)
include(cmake/GeodeBindings.cmake)
if (NOT DEFINED ENV{GEODE_SDK})
message(FATAL_ERROR "Unable to find Geode SDK! Please define GEODE_SDK environment variable to point to Geode")
else()
message(STATUS "Found Geode: $ENV{GEODE_SDK}")
endif()
if (NOT DEFINED ENV{GEODE_BINDINGS_REPO_PATH} AND NOT GEODE_BINDINGS_REPO_PATH)
set(GEODE_BINDINGS_REPO_PATH "${geode_bindings_SOURCE_DIR}"
CACHE PATH "Geode bindings repo (LuauAPI LUAUAPI_BINDINGS_GIT_TAG pin)" FORCE)
message(STATUS "LuauAPI GEODE_BINDINGS_REPO_PATH: ${GEODE_BINDINGS_REPO_PATH}")
endif()
add_subdirectory($ENV{GEODE_SDK} ${CMAKE_CURRENT_BINARY_DIR}/geode)
include(cmake/ImGui.cmake)
add_subdirectory(
"${PROJECT_SOURCE_DIR}/gd-imgui-cocos"
"${CMAKE_CURRENT_BINARY_DIR}/gd-imgui-cocos"
)
target_include_directories(imgui-cocos INTERFACE "${PROJECT_SOURCE_DIR}/src")
endif()
if(NOT LUAUAPI_HOST_ONLY OR LUAUAPI_BUILD_TESTS)
include(cmake/WebSocketDeps.cmake)
endif()
find_package(Python3 3.11 REQUIRED COMPONENTS Interpreter)
if (LUAUAPI_HOST_ONLY)
message(STATUS "LuauAPI host-only configure: skipping Geode SDK and configure-time codegen listing")
if (LUAUAPI_BUILD_TESTS)
include(cmake/GeodeBindings.cmake)
endif()
endif()
if (NOT LUAUAPI_HOST_ONLY)
include(cmake/Codegen.cmake)
luauapi_setup_codegen()
file(GLOB_RECURSE LUAUAPI_HANDWRITTEN_SOURCES CONFIGURE_DEPENDS src/*.cpp)
list(FILTER LUAUAPI_HANDWRITTEN_SOURCES EXCLUDE REGEX "LuaDelegates\\.gen\\.cpp$")
set(LUAUAPI_RUNTIME_SOURCES ${LUAUAPI_HANDWRITTEN_SOURCES})
list(FILTER LUAUAPI_RUNTIME_SOURCES EXCLUDE REGEX "[/\\\\]main\\.cpp$")
add_library(LuauAPI_Runtime OBJECT ${LUAUAPI_RUNTIME_SOURCES})
luauapi_apply_compile_settings(LuauAPI_Runtime)
set_target_properties(LuauAPI_Runtime PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_include_directories(LuauAPI_Runtime PUBLIC
include
src
vendor
${LUAUAPI_GEN_DIR}/src
"${CMAKE_CURRENT_BINARY_DIR}/geode-deps"
$<TARGET_PROPERTY:imgui-cocos,INTERFACE_INCLUDE_DIRECTORIES>
)
add_dependencies(LuauAPI_Runtime luauapi_codegen)
target_compile_definitions(LuauAPI_Runtime PUBLIC
$<TARGET_PROPERTY:imgui-cocos,INTERFACE_COMPILE_DEFINITIONS>
)
target_link_libraries(LuauAPI_Runtime PUBLIC
${LUAUAPI_LUAU_LINK_LIBS}
GeodeBindings
ixwebsocket
glm::glm
)
add_library(LuauAPI_GeneratedBindings OBJECT ${LUAUAPI_GENERATED_BINDING_SOURCES})
add_dependencies(LuauAPI_GeneratedBindings luauapi_codegen)
luauapi_apply_compile_settings(LuauAPI_GeneratedBindings)
set_target_properties(LuauAPI_GeneratedBindings PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_include_directories(LuauAPI_GeneratedBindings PUBLIC ${LUAUAPI_GEN_DIR}/src)
target_link_libraries(LuauAPI_GeneratedBindings PUBLIC LuauAPI_Runtime)
luauapi_apply_generated_binding_compile_settings(LuauAPI_GeneratedBindings)
add_library(${PROJECT_NAME} SHARED
src/main.cpp
$<TARGET_OBJECTS:LuauAPI_Runtime>
$<TARGET_OBJECTS:LuauAPI_GeneratedBindings>
)
target_include_directories(${PROJECT_NAME} PRIVATE include src ${LUAUAPI_GEN_DIR}/src)
target_link_libraries(${PROJECT_NAME}
${LUAUAPI_LUAU_LINK_LIBS}
imgui-cocos
geode-sdk
ixwebsocket
)
luauapi_apply_compile_settings(${PROJECT_NAME})
setup_geode_mod(${PROJECT_NAME})
if(WIN32)
target_link_options(${PROJECT_NAME} PRIVATE
$<$<NOT:$<CONFIG:Debug>>:LINKER:/OPT:REF>
$<$<NOT:$<CONFIG:Debug>>:LINKER:/OPT:ICF>)
endif()
endif()
if(LUAUAPI_BUILD_TESTS)
include(cmake/TestSources.cmake)
include(cmake/ImGuiHeadless.cmake)
include(cmake/MoveOnlyFunction.cmake)
enable_testing()
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.15.1
)
FetchContent_MakeAvailable(Catch2)
FetchContent_Declare(
fmt
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
GIT_TAG 12.2.0
)
FetchContent_MakeAvailable(fmt)
file(GLOB_RECURSE LUAUAPI_TEST_SOURCES CONFIGURE_DEPENDS
${CMAKE_CURRENT_SOURCE_DIR}/tests/cpp/*.cpp)
add_executable(luauapi_tests
${LUAUAPI_HOST_TEST_SOURCES}
${LUAUAPI_TEST_SOURCES}
)
luauapi_force_msvc_idl0(luauapi_tests Catch2 Catch2WithMain luauapi_imgui_headless)
target_compile_features(luauapi_tests PRIVATE cxx_std_23)
target_include_directories(luauapi_tests PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/tests
${CMAKE_CURRENT_SOURCE_DIR}/tests/host/include
${CMAKE_CURRENT_SOURCE_DIR}/tests/host
src
include
vendor
)
target_compile_definitions(luauapi_tests PRIVATE LUAUAPI_HOST_TESTS=1)
target_compile_definitions(luauapi_tests PRIVATE
"LUAUAPI_TEST_FONT_PATH=\"${imgui_SOURCE_DIR}/misc/fonts/DroidSans.ttf\""
"LEDIT_SOURCE_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}/mod/ledit\"")
target_link_libraries(luauapi_tests PRIVATE
Catch2::Catch2WithMain
fmt::fmt-header-only
glm::glm
Luau.VM
Luau.Compiler
Luau.CodeGen
Luau.Require
luauapi_imgui_headless
ixwebsocket
mbedtls
mbedx509
mbedcrypto
)
luauapi_link_move_only_function(luauapi_tests)
if(WIN32)
target_link_libraries(luauapi_tests PRIVATE ws2_32)
endif()
list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/extras)
include(Catch)
catch_discover_tests(luauapi_tests DISCOVERY_MODE PRE_TEST)
add_test(
NAME luauapi_codegen_tests
COMMAND ${Python3_EXECUTABLE} -m unittest discover -s tests/luau_codegen -p "test_*.py"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
set_tests_properties(luauapi_codegen_tests PROPERTIES
ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_SOURCE_DIR}/tools")
endif()