Skip to content

Commit

Permalink
Implement generate_doc_source for cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
enetheru committed Jan 10, 2025
1 parent 0bdab2c commit ffdb78b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
25 changes: 25 additions & 0 deletions cmake/godotcpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,31 @@ function( godotcpp_options )
windows_options()
endfunction()

#[[ Generate doc_data.gen.cpp]]
function( generate_doc_source OUT_VAR_NAME XML_SOURCES )

set( OUTPUT_FILE "${CMAKE_CURRENT_BINARY_DIR}/gen/doc_data.gen.cpp" )

# quote and join to form the interior of a python array.
list( TRANSFORM XML_SOURCES REPLACE "(.*\.xml)" "'\\1'" )
list( JOIN XML_SOURCES "," XML_SOURCES )

# Lists in CMake are delimited by ';', so this works.
set( PYTHON_SCRIPT "from doc_source_generator import generate_doc_source"
"generate_doc_source( '${OUTPUT_FILE}', [${XML_SOURCES}] )" )

add_custom_command( OUTPUT ${OUTPUT_FILE}
COMMAND "${Python3_EXECUTABLE}" "-c" "${PYTHON_SCRIPT}"
VERBATIM
WORKING_DIRECTORY ${godot-cpp_SOURCE_DIR}
DEPENDS ${godot-cpp_SOURCE_DIR}/doc_source_generator.py
COMMENT "Generating Doc Data"
)

# Propagate generated file to caller scope
set( ${OUT_VAR_NAME} ${OUTPUT_FILE} PARENT_SCOPE )
endfunction()

# Function to configure and generate the targets
function( godotcpp_generate )
#[[ Multi-Threaded MSVC Compilation
Expand Down
14 changes: 13 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@ Integration Testing
-------------------
The Test target used to validate changes in the GitHub CI.
]=======================================================================]

message( STATUS "Testing Integration targets are enabled.")

# Generate Doc Data
file( GLOB_RECURSE DOC_XML
LIST_DIRECTORIES NO
CONFIGURE_DEPENDS
${CMAKE_CURRENT_SOURCE_DIR}/doc_classes/*.xml )

generate_doc_source( DOC_DATA "${DOC_XML}" )

foreach( TARGET_ALIAS template_debug template_release editor )
set( TARGET_NAME "godot-cpp.test.${TARGET_ALIAS}" )
set( LINK_TARGET "godot-cpp::${TARGET_ALIAS}" )
Expand All @@ -23,6 +30,11 @@ foreach( TARGET_ALIAS template_debug template_release editor )
src/tests.h
)

# conditionally add doc data to compile output
if( TARGET_ALIAS MATCHES "editor|template_debug" )
target_sources( ${TARGET_NAME} PRIVATE ${DOC_DATA} )
endif( )

target_link_libraries( ${TARGET_NAME} PRIVATE ${LINK_TARGET} )

### Get useful properties of the library
Expand Down

0 comments on commit ffdb78b

Please sign in to comment.