|
@@ -1,14 +1,24 @@
|
|
|
#[=======================================================================[.rst:
|
|
|
-python_callouts.cmake
|
|
|
+GodotCPPModule.cmake
|
|
|
---------------------
|
|
|
|
|
|
-This file contains functions which which rely on calling Python
|
|
|
+This file contains functions and tests which may be needed by consumers.
|
|
|
|
|
|
* Generate Trimmed API
|
|
|
* Generate File List
|
|
|
* Generate Bindings
|
|
|
-]=======================================================================]
|
|
|
|
|
|
+If you want to use these functions in your project extend the CMAKE_MODULE_PATH
|
|
|
+by adding these two lines into your CMakeLists.txt after the inclusion
|
|
|
+godot-cpp
|
|
|
+
|
|
|
+.. highlight:: cmake
|
|
|
+
|
|
|
+ list(APPEND CMAKE_MODULE_PATH "${godot-cpp_SOURCE_DIR}/cmake")
|
|
|
+ include( GodotCPPModule )
|
|
|
+
|
|
|
+]=======================================================================]
|
|
|
+find_package(Python3 3.4 REQUIRED) # pathlib should be present
|
|
|
|
|
|
#[[ Generate Trimmed API
|
|
|
|
|
@@ -106,22 +116,51 @@ endfunction( )
|
|
|
The documentation displayed in the Godot editor is compiled into the extension.
|
|
|
It takes a list of XML source files, and transforms them into a cpp file that
|
|
|
is added to the sources list.]]
|
|
|
-function( generate_doc_source OUTPUT_PATH XML_SOURCES )
|
|
|
- # Transform the CMake list into the content of a python list
|
|
|
- # quote and join to form the interior of a python array
|
|
|
- list( TRANSFORM XML_SOURCES REPLACE "(.*\.xml)" "'\\1'" )
|
|
|
- list( JOIN XML_SOURCES "," XML_SOURCES )
|
|
|
+function( generate_doc_source OUTPUT_PATH SOURCES )
|
|
|
+ # Transform SOURCES CMake LIST
|
|
|
+ # quote each path with ''
|
|
|
+ # join with , to transform into a python list minus the surrounding []
|
|
|
+ set( PYTHON_LIST "${SOURCES}")
|
|
|
+ list( TRANSFORM PYTHON_LIST REPLACE "(.*\.xml)" "'\\1'" )
|
|
|
+ list( JOIN PYTHON_LIST "," PYTHON_LIST )
|
|
|
|
|
|
# Python one-liner to run our command
|
|
|
# lists in CMake are just strings delimited by ';', so this works.
|
|
|
set( PYTHON_SCRIPT "from doc_source_generator import generate_doc_source"
|
|
|
- "generate_doc_source( '${OUTPUT_PATH}', [${XML_SOURCES}] )" )
|
|
|
+ "generate_doc_source( '${OUTPUT_PATH}', [${PYTHON_LIST}] )" )
|
|
|
|
|
|
add_custom_command( OUTPUT "${OUTPUT_PATH}"
|
|
|
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"
|
|
|
+ DEPENDS
|
|
|
+ "${godot-cpp_SOURCE_DIR}/doc_source_generator.py"
|
|
|
+ "${SOURCES}"
|
|
|
+ COMMENT "Generating: ${OUTPUT_PATH}"
|
|
|
)
|
|
|
endfunction()
|
|
|
+
|
|
|
+#[[ target_doc_sources
|
|
|
+A simpler interface to add xml files as doc source to a output target.
|
|
|
+TARGET: The gdexension library target
|
|
|
+SOURCES: a list of xml files to use for source generation and inclusion.
|
|
|
+This function also adds a doc_gen target to test source generation.]]
|
|
|
+function( target_doc_sources TARGET SOURCES )
|
|
|
+ # set the generated file name
|
|
|
+ set( DOC_SOURCE_FILE "${CMAKE_CURRENT_BINARY_DIR}/gen/doc_source.cpp" )
|
|
|
+
|
|
|
+ # Create the file generation target, this won't be triggered unless a target
|
|
|
+ # that depends on DOC_SOURCE_FILE is built
|
|
|
+ generate_doc_source( "${DOC_SOURCE_FILE}" ${SOURCES} )
|
|
|
+
|
|
|
+ # Add DOC_SOURCE_FILE as a dependency to TARGET
|
|
|
+ target_sources( ${TARGET} PRIVATE "${DOC_SOURCE_FILE}" )
|
|
|
+
|
|
|
+ # Create a dummy target that depends on the source so that users can
|
|
|
+ # test the file generation task.
|
|
|
+ if( TARGET doc_gen )
|
|
|
+ else()
|
|
|
+ add_custom_target( doc_gen )
|
|
|
+ endif()
|
|
|
+ target_sources( doc_gen PRIVATE "${DOC_SOURCE_FILE}" )
|
|
|
+endfunction()
|