Skip to content

Commit e4e8e55

Browse files
committed
CMake: XCode dependency chain fixes
When attempting to generate XCode projects it would fail due to the target dependency chain not meeting expectations. This PR simplifies the target dependencies And adds control over the GODOTCPP_TARGETS generated.
1 parent a3f8921 commit e4e8e55

File tree

3 files changed

+32
-28
lines changed

3 files changed

+32
-28
lines changed

cmake/GodotCPPModule.cmake

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -107,22 +107,23 @@ function(
107107
# Strip newlines and whitespace to make it a one-liner.
108108
string(REGEX REPLACE "\n *" " " PYTHON_SCRIPT "${PYTHON_SCRIPT}")
109109

110-
add_custom_command(
111-
OUTPUT ${GENERATED_FILES_LIST}
110+
add_custom_target(
111+
godot-cpp.generate_bindings
112112
COMMAND "${Python3_EXECUTABLE}" "-c" "${PYTHON_SCRIPT}"
113-
VERBATIM
113+
BYPRODUCTS ${GENERATED_FILES_LIST}
114114
WORKING_DIRECTORY ${godot-cpp_SOURCE_DIR}
115-
MAIN_DEPENDENCY ${GODOTCPP_GDEXTENSION_API_FILE}
116-
DEPENDS ${godot-cpp_SOURCE_DIR}/binding_generator.py
117115
COMMENT "Generating bindings"
116+
VERBATIM
117+
SOURCES ${godot-cpp_SOURCE_DIR}/binding_generator.py ${GODOTCPP_GDEXTENSION_API_FILE}
118118
)
119+
set_target_properties(godot-cpp.generate_bindings PROPERTIES FOLDER "godot-cpp")
119120
endfunction()
120121

121122
#[[ Generate doc_data.cpp
122123
The documentation displayed in the Godot editor is compiled into the extension.
123124
It takes a list of XML source files, and transforms them into a cpp file that
124125
is added to the sources list.]]
125-
function(generate_doc_source OUTPUT_PATH SOURCES)
126+
function(generate_doc_source TARGET OUTPUT_PATH SOURCES)
126127
# Transform SOURCES CMake LIST
127128
# quote each path with ''
128129
# join with , to transform into a python list minus the surrounding []
@@ -140,16 +141,14 @@ function(generate_doc_source OUTPUT_PATH SOURCES)
140141
"generate_doc_source( '${OUTPUT_PATH}', [${PYTHON_LIST}] )"
141142
)
142143

143-
add_custom_command(
144-
OUTPUT "${OUTPUT_PATH}"
144+
add_custom_target(
145+
${TARGET}
145146
COMMAND "${Python3_EXECUTABLE}" "-c" "${PYTHON_SCRIPT}"
146-
VERBATIM
147+
BYPRODUCTS "${OUTPUT_PATH}"
147148
WORKING_DIRECTORY "${godot-cpp_SOURCE_DIR}"
148-
DEPENDS
149-
DEPENDS #
150-
"${godot-cpp_SOURCE_DIR}/doc_source_generator.py"
151-
"${SOURCES}"
152149
COMMENT "Generating: ${OUTPUT_PATH}"
150+
VERBATIM
151+
SOURCES "${godot-cpp_SOURCE_DIR}/doc_source_generator.py" ${SOURCES}
153152
)
154153
endfunction()
155154

@@ -164,16 +163,8 @@ function(target_doc_sources TARGET SOURCES)
164163

165164
# Create the file generation target, this won't be triggered unless a target
166165
# that depends on DOC_SOURCE_FILE is built
167-
generate_doc_source( "${DOC_SOURCE_FILE}" ${SOURCES} )
166+
generate_doc_source( ${TARGET}_doc_gen "${DOC_SOURCE_FILE}" ${SOURCES} )
168167

169168
# Add DOC_SOURCE_FILE as a dependency to TARGET
170169
target_sources(${TARGET} PRIVATE "${DOC_SOURCE_FILE}")
171-
172-
# Create a dummy target that depends on the source so that users can
173-
# test the file generation task.
174-
if(TARGET doc_gen)
175-
else()
176-
add_custom_target(doc_gen)
177-
endif()
178-
target_sources(doc_gen PRIVATE "${DOC_SOURCE_FILE}")
179170
endfunction()

cmake/godotcpp.cmake

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,18 @@ function(godotcpp_options)
106106
#NOTE: arch is managed by using toolchain files.
107107
# To create a universal build for macos, set CMAKE_OSX_ARCHITECTURES
108108

109+
set(GODOTCPP_VALID_TARGETS "template_debug;template_release;editor")
110+
set(GODOTCPP_TARGETS
111+
${GODOTCPP_VALID_TARGETS}
112+
CACHE STRING
113+
"Which targets to generate, must be a semicolon separated list. valid values are: template_debug, template_release, and editor"
114+
)
115+
foreach(TARGET ${GODOTCPP_TARGETS})
116+
if(NOT ${TARGET} IN_LIST GODOTCPP_VALID_TARGETS)
117+
message(FATAL_ERROR "invalid GODOTCPP_TARGETS valid values are ${GODOTCPP_VALID_TARGETS} ")
118+
endif()
119+
endforeach()
120+
109121
# Input from user for GDExtension interface header and the API JSON file
110122
set(GODOTCPP_GDEXTENSION_DIR
111123
"gdextension"
@@ -264,9 +276,6 @@ function(godotcpp_generate)
264276
"${CMAKE_CURRENT_BINARY_DIR}"
265277
)
266278

267-
add_custom_target(godot-cpp.generate_bindings DEPENDS ${GENERATED_FILES_LIST})
268-
set_target_properties(godot-cpp.generate_bindings PROPERTIES FOLDER "godot-cpp")
269-
270279
### Platform is derived from the toolchain target
271280
# See GeneratorExpressions PLATFORM_ID and CMAKE_SYSTEM_NAME
272281
string(
@@ -305,7 +314,7 @@ function(godotcpp_generate)
305314
set(IS_DEV_BUILD "$<BOOL:${GODOTCPP_DEV_BUILD}>")
306315

307316
### Define our godot-cpp library targets
308-
foreach(TARGET_ALIAS template_debug template_release editor)
317+
foreach(TARGET_ALIAS ${GODOTCPP_TARGETS})
309318
set(TARGET_NAME "godot-cpp.${TARGET_ALIAS}")
310319

311320
# Generator Expressions that rely on the target

test/CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ message(STATUS "Testing Integration targets are enabled.")
1010
# Generate Doc Data
1111
file(GLOB_RECURSE DOC_XML LIST_DIRECTORIES NO CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/doc_classes/*.xml")
1212

13-
foreach(TARGET_ALIAS template_debug template_release editor)
13+
set(DOC_SOURCE_FILE "${CMAKE_CURRENT_BINARY_DIR}/gen/doc_source.cpp")
14+
15+
generate_doc_source( doc_gen "${DOC_SOURCE_FILE}" ${DOC_XML} )
16+
17+
foreach(TARGET_ALIAS ${GODOTCPP_TARGETS})
1418
set(TARGET_NAME "godot-cpp.test.${TARGET_ALIAS}")
1519

1620
add_library(${TARGET_NAME} SHARED EXCLUDE_FROM_ALL)
@@ -22,7 +26,7 @@ foreach(TARGET_ALIAS template_debug template_release editor)
2226

2327
# conditionally add doc data to compile output
2428
if(TARGET_ALIAS MATCHES "editor|template_debug")
25-
target_doc_sources( ${TARGET_NAME} ${DOC_XML} )
29+
target_sources(${TARGET_NAME} PRIVATE "${DOC_SOURCE_FILE}")
2630
endif()
2731

2832
set(OUTPUT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/project/bin/")

0 commit comments

Comments
 (0)