Repository navigation
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
153 lines (138 loc) · 7.16 KB
/
Copy pathCMakeLists.txt
File metadata and controls
153 lines (138 loc) · 7.16 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
cmake_minimum_required(VERSION 3.20)
project(RbfxScript)
# The demo targets (the editor plugin, the demo application, the launcher and the custom editor).
# They build by default only when this project is the top-level project.
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(_RBFX_SCRIPT_IS_TOP_LEVEL ON)
else()
set(_RBFX_SCRIPT_IS_TOP_LEVEL OFF)
endif()
option(RBFX_SCRIPT_BUILD_DEMO "Build the editor plugin, the demo application, the launcher and the editor"
${_RBFX_SCRIPT_IS_TOP_LEVEL})
# A host project that embeds this project (add_subdirectory) or that has the engine target already
# owns the C++ standard, the output folders and the engine. Then skip the setup of them.
if(_RBFX_SCRIPT_IS_TOP_LEVEL AND NOT TARGET Urho3D)
# C++17 is required for this project.
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Setup output directories.
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
# Configure engine options. This is required for in-source engine builds.
set(URHO3D_SAMPLES OFF)
# Find the engine. The user can set CMAKE_PREFIX_PATH to override the default.
# The default is the sibling rbfx checkout, or a fixed path as a last resort.
if(NOT CMAKE_PREFIX_PATH)
get_filename_component(_RBFX_SCRIPT_SIBLING_CMAKE "${CMAKE_CURRENT_SOURCE_DIR}/../rbfx/CMake" ABSOLUTE)
if(EXISTS "${_RBFX_SCRIPT_SIBLING_CMAKE}")
set(_RBFX_SCRIPT_DEFAULT_PREFIX "${_RBFX_SCRIPT_SIBLING_CMAKE}")
endif()
set(RBFX_SCRIPT_ENGINE_PREFIX "${_RBFX_SCRIPT_DEFAULT_PREFIX}" CACHE PATH
"Default engine prefix path. It applies only when CMAKE_PREFIX_PATH is empty.")
list(APPEND CMAKE_PREFIX_PATH "${RBFX_SCRIPT_ENGINE_PREFIX}")
endif()
find_package(Urho3D REQUIRED)
endif()
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/RbfxScriptBuildConfig.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/RbfxScriptAot.cmake)
# Hot++ options. Set them before add_subdirectory. HOT_ENABLE_JIT stays at AUTO.
set(HOT_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(HOT_BUILD_SAMPLES OFF CACHE BOOL "" FORCE)
set(HOT_INSTALL OFF CACHE BOOL "" FORCE)
# No run-time compile: Hot++ builds no run-time backend. The translator (hotc) still builds for the AOT step.
if(NOT RBFX_SCRIPT_RUNTIME_COMPILE)
set(HOT_ENABLE_CLANG_FILES OFF CACHE BOOL "" FORCE)
set(HOT_ENABLE_JIT OFF CACHE STRING "" FORCE)
endif()
# Script call stacks are on by default in the plugin. -DHOT_TRACEBACK=OFF turns them off.
set(HOT_TRACEBACK ON CACHE BOOL "Record the script call stack for the error report")
set(HOT_BUILD_LS OFF CACHE BOOL "" FORCE)
set(HOT_BUILD_VSCODE OFF CACHE BOOL "" FORCE)
# Use the sibling checkout ../hotpp when it exists. Else use the hotpp submodule.
get_filename_component(_RBFX_SCRIPT_SIBLING_HOTPP "${CMAKE_CURRENT_SOURCE_DIR}/../hotpp" ABSOLUTE)
if(EXISTS "${_RBFX_SCRIPT_SIBLING_HOTPP}/CMakeLists.txt")
set(RBFX_SCRIPT_HOTPP_DIR "${_RBFX_SCRIPT_SIBLING_HOTPP}")
elseif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/hotpp/CMakeLists.txt")
set(RBFX_SCRIPT_HOTPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/hotpp")
else()
message(FATAL_ERROR
"Missing ../hotpp and hotpp/CMakeLists.txt. Run: git submodule update --init --recursive")
endif()
message(STATUS "Hot++ source: ${RBFX_SCRIPT_HOTPP_DIR}")
# CPM caches the folder of its script. A build folder that used another Hot++ copy keeps the old
# folder. Then CPM.cmake of the new copy returns early and CPMAddPackage stays undefined.
if(CPM_DIRECTORY AND NOT COMMAND CPMAddPackage)
unset(CPM_DIRECTORY CACHE)
unset(CPM_FILE CACHE)
endif()
# The Hot++ translator uses libclang, and libclang needs the Clang resource folder (stddef.h and
# the other compiler headers). Hot++ asks the compiler of the build for the folder, but only a
# Clang build can answer. For a GCC build, ask the clang++ of the system.
# The backend also gives the script compiler the flag -resource-dir, and GCC does not know it.
# So a GCC build compiles the scripts with clang++. It uses the same C++ library as GCC.
if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT MSVC)
find_program(RBFX_SCRIPT_CLANGXX NAMES clang++)
if(RBFX_SCRIPT_CLANGXX)
if(NOT HOT_CLANG_RESOURCE_DIR)
execute_process(COMMAND ${RBFX_SCRIPT_CLANGXX} -print-resource-dir
OUTPUT_VARIABLE _rbfx_script_resource_dir OUTPUT_STRIP_TRAILING_WHITESPACE)
set(HOT_CLANG_RESOURCE_DIR "${_rbfx_script_resource_dir}" CACHE PATH "The Clang resource directory")
endif()
if(NOT HOT_SCRIPT_COMPILER OR HOT_SCRIPT_COMPILER STREQUAL CMAKE_CXX_COMPILER)
set(HOT_SCRIPT_COMPILER "${RBFX_SCRIPT_CLANGXX}" CACHE STRING
"The compiler of the script modules at run time" FORCE)
endif()
else()
message(WARNING "clang++ is not found. The run-time compile of the scripts needs it.")
endif()
endif()
# The plugins are shared libraries when the engine is shared. They link the Hot++ static
# libraries, so these libraries need position independent code.
if(BUILD_SHARED_LIBS)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()
add_subdirectory("${RBFX_SCRIPT_HOTPP_DIR}" hotpp)
# A script module reads the call depth of Hot++ (a thread-local variable) with the initial-exec
# model. The engine opens a plugin with dlopen. Then glibc gives the plugin static TLS only when
# the plugin itself uses the initial-exec model. This flag marks the plugin STATIC_TLS.
if(BUILD_SHARED_LIBS AND CMAKE_SYSTEM_NAME STREQUAL "Linux")
foreach(target hot_runtime_core hot_runtime)
if(TARGET ${target})
target_compile_options(${target} PRIVATE -ftls-model=initial-exec)
endif()
endforeach()
endif()
# Shared script core. The game plugin and the editor plugin link it.
add_subdirectory(Plugins/Rbfx.Script.Core)
# Game plugin.
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/Plugins/Rbfx.Script/CMakeLists.txt")
add_subdirectory(Plugins/Rbfx.Script)
endif()
# End-to-end test of the game plugin.
option(RBFX_SCRIPT_BUILD_TESTS "Build the end-to-end test of the game plugin" OFF)
if(RBFX_SCRIPT_BUILD_TESTS)
add_subdirectory(Tests/ScriptSmokeTest)
add_subdirectory(Tests/DependentsRuleTest)
if(URHO3D_RMLUI)
add_subdirectory(Tests/RmlInvokeTest)
add_subdirectory(Tests/RmlScriptSourceTest)
add_subdirectory(Tests/RmlBridgeTest)
add_subdirectory(Tests/RmlMaskStepTest)
endif()
endif()
# Editor plugin.
if(RBFX_SCRIPT_BUILD_DEMO AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/Plugins/Rbfx.Script.Editor/CMakeLists.txt")
add_subdirectory(Plugins/Rbfx.Script.Editor)
endif()
# Main plugin of the demo project and its player.
if(RBFX_SCRIPT_BUILD_DEMO AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/Source/Application/CMakeLists.txt")
add_subdirectory(Source/Application)
endif()
if(RBFX_SCRIPT_BUILD_DEMO AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/Source/Launcher/CMakeLists.txt")
add_subdirectory(Source/Launcher)
endif()
# Custom editor linked with the plugins.
if(RBFX_SCRIPT_BUILD_DEMO AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/Source/Editor/CMakeLists.txt")
add_subdirectory(Source/Editor)
endif()