-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
143 lines (114 loc) · 4.76 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
cmake_minimum_required(VERSION 3.30.5)
#[=======================[ Global CMake Configuration ]=======================]
if( CMAKE_C_COMPILER )
#Do nothing, just shut up the build because clion adds this from the toolchain
endif ()
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
### Cmake options to expose
option( CMAKE_EXPORT_COMPILE_COMMANDS
"Generate compilation DB (`compile_commands.json`) for external tools"
ON )
# So that I can condifgure for the flatc compiler, and not the extension.
option( BUILD_EXTENSION
"build the extension"
ON)
## Target options
set( GDE_NAME "gdflatbuffers" )
### Information regarding the godot executable
set( GODOT_EXECUTABLE ""
CACHE FILEPATH "Path to the godot executable you are targeting" )
set( GODOT_PROJECT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/project"
CACHE PATH "Path to a demo project that can test the gdextension" )
#[==============================[ Dependencies ]==============================]
include(FetchContent)
include(CMakePrintHelpers)
include(cmake/findGodotExecutable.cmake)
include(cmake/godot-dump.cmake)
#[==============[ Git ]==============]
find_program(GIT_EXECUTABLE NAMES "git" DOC "" NO_CACHE REQUIRED)
if( NOT EXISTS "${GIT_EXECUTABLE}" )
message( FATAL_ERROR "Unable to find Git at: '${GIT_EXECUTABLE}'")
endif()
#[==========[ Flatbuffers ]==========]
set( FLATBUFFERS_GIT_URL "https://github.com/enetheru/flatbuffers.git"
CACHE STRING "Location of the godot-cpp git repository" )
set( FLATBUFFERS_GIT_TAG "gdscript"
CACHE STRING "git hash, branch or tag to fetch" )
# Configuration Options
set( FLATBUFFERS_BUILD_FLATHASH NO )
set( FLATBUFFERS_BUILD_SHAREDLIB NO )
set( FLATBUFFERS_BUILD_TESTS NO )
set( FLATBUFFERS_INSTALL NO )
set( FLATBUFFERS_STATIC_FLATC YES )
set( FLATBUFFERS_BUILD_FLATC YES )
FetchContent_Declare( FlatBuffers
GIT_REPOSITORY "${FLATBUFFERS_GIT_URL}"
GIT_TAG "${FLATBUFFERS_GIT_TAG}"
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/lib/flatbuffers"
SYSTEM
EXCLUDE_FROM_ALL
)
FetchContent_MakeAvailable( FlatBuffers )
set_target_properties( flatc PROPERTIES EXCLUDE_FROM_ALL ON )
set_target_properties( flatbuffers PROPERTIES EXCLUDE_FROM_ALL ON )
# If we dont want to build the extension then we can stop here
# This does break any other targets for this configuration
# so currently only useful for building flatc.
if( NOT BUILD_EXTENSION )
return()
endif ()
#[============[ godot-cpp ]============]
set( GODOTCPP_GIT_URL "https://github.com/enetheru/godot-cpp.git" CACHE STRING "Location of the godot-cpp git repository" )
set( GODOTCPP_GIT_TAG "master" CACHE STRING "git hash, branch or tag to fetch" )
set( GODOT_BUILD_PROFILE "${CMAKE_CURRENT_SOURCE_DIR}/lib/godot-cpp.build_profile.json" )
#if( GODOT_GIT_TAG STREQUAL "" )
# include( godot-cpp-git-tag )
#endif()
FetchContent_Declare( godot-cpp
GIT_REPOSITORY "${GODOTCPP_GIT_URL}"
GIT_TAG "${GODOTCPP_GIT_TAG}"
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/lib/godot-cpp"
SYSTEM
EXCLUDE_FROM_ALL
)
FetchContent_MakeAvailable( godot-cpp )
#[===========================[ Project Definition ]===========================]
project( godot-flatbuffers-extension
VERSION 1.0
DESCRIPTION ""
LANGUAGES CXX)
### Global options
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Output Directory
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "$<1:${CMAKE_CURRENT_SOURCE_DIR}/addons/${GDE_NAME}/bin>" )
add_subdirectory( src )
### separate CMakeLists for our gdextension sources.
foreach ( TARGET_TYPE template_debug template_release editor )
set( LIBNAME "${GDE_NAME}.${TARGET_TYPE}" )
add_library( ${LIBNAME} SHARED EXCLUDE_FROM_ALL )
target_sources( ${LIBNAME}
PRIVATE
${SOURCES}
)
target_link_libraries( ${LIBNAME} PRIVATE godot-cpp::${TARGET_TYPE} FlatBuffers::FlatBuffers )
### Get useful properties of the library
get_target_property( GODOT_PLATFORM godot-cpp::${TARGET_TYPE} GODOT_PLATFORM )
get_target_property( GODOT_TARGET godot-cpp::${TARGET_TYPE} GODOT_TARGET )
get_target_property( GODOT_ARCH godot-cpp::${TARGET_TYPE} GODOT_ARCH )
string( CONCAT OUTPUT_NAME "${GDE_NAME}"
".${GODOT_PLATFORM}"
".${GODOT_TARGET}"
$<$<STREQUAL:double,${GODOT_PRECISION}>:".double">
".${GODOT_ARCH}"
)
set_target_properties( ${LIBNAME}
PROPERTIES
FOLDER "gdflatbuffers"
#The generator expression here prevents a subdir from being created.
RUNTIME_OUTPUT_DIRECTORY "$<1:${CMAKE_RUNTIME_OUTPUT_DIRECTORY}>"
OUTPUT_NAME "${OUTPUT_NAME}"
PREFIX "lib"
)
endforeach ()