|
1 | 1 | #[=======================================================================[.rst: |
2 | | -python_callouts.cmake |
| 2 | +GodotCPPModule.cmake |
3 | 3 | --------------------- |
4 | 4 |
|
5 | | -This file contains functions which which rely on calling Python |
| 5 | +This file contains functions and tests which may be needed by consumers. |
6 | 6 |
|
7 | 7 | * Generate Trimmed API |
8 | 8 | * Generate File List |
9 | 9 | * Generate Bindings |
10 | | -]=======================================================================] |
11 | 10 |
|
| 11 | +If you want to use these functions in your project extend the CMAKE_MODULE_PATH |
| 12 | +by adding these two lines into your CMakeLists.txt after the inclusion |
| 13 | +godot-cpp |
| 14 | +
|
| 15 | +.. highlight:: cmake |
| 16 | +
|
| 17 | + list(APPEND CMAKE_MODULE_PATH "${godot-cpp_SOURCE_DIR}/cmake") |
| 18 | + include( GodotCPPModule ) |
| 19 | +
|
| 20 | +]=======================================================================] |
| 21 | +find_package(Python3 3.4 REQUIRED) # pathlib should be present |
12 | 22 |
|
13 | 23 | #[[ Generate Trimmed API |
14 | 24 |
|
@@ -106,22 +116,51 @@ endfunction( ) |
106 | 116 | The documentation displayed in the Godot editor is compiled into the extension. |
107 | 117 | It takes a list of XML source files, and transforms them into a cpp file that |
108 | 118 | is added to the sources list.]] |
109 | | -function( generate_doc_source OUTPUT_PATH XML_SOURCES ) |
110 | | - # Transform the CMake list into the content of a python list |
111 | | - # quote and join to form the interior of a python array |
112 | | - list( TRANSFORM XML_SOURCES REPLACE "(.*\.xml)" "'\\1'" ) |
113 | | - list( JOIN XML_SOURCES "," XML_SOURCES ) |
| 119 | +function( generate_doc_source OUTPUT_PATH SOURCES ) |
| 120 | + # Transform SOURCES CMake LIST |
| 121 | + # quote each path with '' |
| 122 | + # join with , to transform into a python list minus the surrounding [] |
| 123 | + set( PYTHON_LIST "${SOURCES}") |
| 124 | + list( TRANSFORM PYTHON_LIST REPLACE "(.*\.xml)" "'\\1'" ) |
| 125 | + list( JOIN PYTHON_LIST "," PYTHON_LIST ) |
114 | 126 |
|
115 | 127 | # Python one-liner to run our command |
116 | 128 | # lists in CMake are just strings delimited by ';', so this works. |
117 | 129 | set( PYTHON_SCRIPT "from doc_source_generator import generate_doc_source" |
118 | | - "generate_doc_source( '${OUTPUT_PATH}', [${XML_SOURCES}] )" ) |
| 130 | + "generate_doc_source( '${OUTPUT_PATH}', [${PYTHON_LIST}] )" ) |
119 | 131 |
|
120 | 132 | add_custom_command( OUTPUT "${OUTPUT_PATH}" |
121 | 133 | COMMAND "${Python3_EXECUTABLE}" "-c" "${PYTHON_SCRIPT}" |
122 | 134 | VERBATIM |
123 | 135 | WORKING_DIRECTORY "${godot-cpp_SOURCE_DIR}" |
124 | | - DEPENDS "${godot-cpp_SOURCE_DIR}/doc_source_generator.py" |
125 | | - COMMENT "Generating Doc Data" |
| 136 | + DEPENDS |
| 137 | + "${godot-cpp_SOURCE_DIR}/doc_source_generator.py" |
| 138 | + "${SOURCES}" |
| 139 | + COMMENT "Generating: ${OUTPUT_PATH}" |
126 | 140 | ) |
127 | 141 | endfunction() |
| 142 | + |
| 143 | +#[[ target_doc_sources |
| 144 | +A simpler interface to add xml files as doc source to a output target. |
| 145 | +TARGET: The gdexension library target |
| 146 | +SOURCES: a list of xml files to use for source generation and inclusion. |
| 147 | +This function also adds a doc_gen target to test source generation.]] |
| 148 | +function( target_doc_sources TARGET SOURCES ) |
| 149 | + # set the generated file name |
| 150 | + set( DOC_SOURCE_FILE "${CMAKE_CURRENT_BINARY_DIR}/gen/doc_source.cpp" ) |
| 151 | + |
| 152 | + # Create the file generation target, this won't be triggered unless a target |
| 153 | + # that depends on DOC_SOURCE_FILE is built |
| 154 | + generate_doc_source( "${DOC_SOURCE_FILE}" ${SOURCES} ) |
| 155 | + |
| 156 | + # Add DOC_SOURCE_FILE as a dependency to TARGET |
| 157 | + target_sources( ${TARGET} PRIVATE "${DOC_SOURCE_FILE}" ) |
| 158 | + |
| 159 | + # Create a dummy target that depends on the source so that users can |
| 160 | + # test the file generation task. |
| 161 | + if( TARGET doc_gen ) |
| 162 | + else() |
| 163 | + add_custom_target( doc_gen ) |
| 164 | + endif() |
| 165 | + target_sources( doc_gen PRIVATE "${DOC_SOURCE_FILE}" ) |
| 166 | +endfunction() |
0 commit comments