Turn python_callouts.cmake into GodotCPPModule.cmake
Move the find_package for python into it. Recommend adding godot-cpp/cmake to CMAKE_MODULE_PATH and using include( GodotCPPModule ) to use functions. Add target_doc_sources function to simplify the addition of documentation to a binary.pull/1707/head
parent
f398ebb8ce
commit
35469fd839
|
@ -41,9 +41,6 @@ include( cmake/godotcpp.cmake )
|
||||||
|
|
||||||
godotcpp_options()
|
godotcpp_options()
|
||||||
|
|
||||||
#[[ Python is required for code generation ]]
|
|
||||||
find_package(Python3 3.4 REQUIRED) # pathlib should be present
|
|
||||||
|
|
||||||
# Define our project.
|
# Define our project.
|
||||||
project( godot-cpp
|
project( godot-cpp
|
||||||
VERSION 4.4
|
VERSION 4.4
|
||||||
|
|
|
@ -1,14 +1,24 @@
|
||||||
#[=======================================================================[.rst:
|
#[=======================================================================[.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 Trimmed API
|
||||||
* Generate File List
|
* Generate File List
|
||||||
* Generate Bindings
|
* 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
|
#[[ Generate Trimmed API
|
||||||
|
|
||||||
|
@ -106,22 +116,51 @@ endfunction( )
|
||||||
The documentation displayed in the Godot editor is compiled into the extension.
|
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
|
It takes a list of XML source files, and transforms them into a cpp file that
|
||||||
is added to the sources list.]]
|
is added to the sources list.]]
|
||||||
function( generate_doc_source OUTPUT_PATH XML_SOURCES )
|
function( generate_doc_source OUTPUT_PATH SOURCES )
|
||||||
# Transform the CMake list into the content of a python list
|
# Transform SOURCES CMake LIST
|
||||||
# quote and join to form the interior of a python array
|
# quote each path with ''
|
||||||
list( TRANSFORM XML_SOURCES REPLACE "(.*\.xml)" "'\\1'" )
|
# join with , to transform into a python list minus the surrounding []
|
||||||
list( JOIN XML_SOURCES "," XML_SOURCES )
|
set( PYTHON_LIST "${SOURCES}")
|
||||||
|
list( TRANSFORM PYTHON_LIST REPLACE "(.*\.xml)" "'\\1'" )
|
||||||
|
list( JOIN PYTHON_LIST "," PYTHON_LIST )
|
||||||
|
|
||||||
# Python one-liner to run our command
|
# Python one-liner to run our command
|
||||||
# lists in CMake are just strings delimited by ';', so this works.
|
# lists in CMake are just strings delimited by ';', so this works.
|
||||||
set( PYTHON_SCRIPT "from doc_source_generator import generate_doc_source"
|
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}"
|
add_custom_command( OUTPUT "${OUTPUT_PATH}"
|
||||||
COMMAND "${Python3_EXECUTABLE}" "-c" "${PYTHON_SCRIPT}"
|
COMMAND "${Python3_EXECUTABLE}" "-c" "${PYTHON_SCRIPT}"
|
||||||
VERBATIM
|
VERBATIM
|
||||||
WORKING_DIRECTORY "${godot-cpp_SOURCE_DIR}"
|
WORKING_DIRECTORY "${godot-cpp_SOURCE_DIR}"
|
||||||
DEPENDS "${godot-cpp_SOURCE_DIR}/doc_source_generator.py"
|
DEPENDS
|
||||||
COMMENT "Generating Doc Data"
|
"${godot-cpp_SOURCE_DIR}/doc_source_generator.py"
|
||||||
|
"${SOURCES}"
|
||||||
|
COMMENT "Generating: ${OUTPUT_PATH}"
|
||||||
)
|
)
|
||||||
endfunction()
|
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()
|
|
@ -23,6 +23,7 @@ project directive, it means that
|
||||||
directive was
|
directive was
|
||||||
|
|
||||||
]=======================================================================]
|
]=======================================================================]
|
||||||
|
include( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/GodotCPPModule.cmake)
|
||||||
include( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/common_compiler_flags.cmake)
|
include( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/common_compiler_flags.cmake)
|
||||||
include( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/android.cmake)
|
include( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/android.cmake)
|
||||||
include( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/ios.cmake)
|
include( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/ios.cmake)
|
||||||
|
@ -30,7 +31,7 @@ include( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/linux.cmake)
|
||||||
include( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/macos.cmake)
|
include( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/macos.cmake)
|
||||||
include( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/web.cmake)
|
include( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/web.cmake)
|
||||||
include( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/windows.cmake)
|
include( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/windows.cmake)
|
||||||
include( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/python_callouts.cmake)
|
|
||||||
|
|
||||||
# Detect number of processors
|
# Detect number of processors
|
||||||
include(ProcessorCount)
|
include(ProcessorCount)
|
||||||
|
|
|
@ -13,9 +13,6 @@ file( GLOB_RECURSE DOC_XML
|
||||||
CONFIGURE_DEPENDS
|
CONFIGURE_DEPENDS
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/doc_classes/*.xml" )
|
"${CMAKE_CURRENT_SOURCE_DIR}/doc_classes/*.xml" )
|
||||||
|
|
||||||
set( DOC_DATA_SOURCE "${CMAKE_CURRENT_BINARY_DIR}/src/gen/doc_data.gen.cpp" )
|
|
||||||
generate_doc_source( "${DOC_DATA_SOURCE}" "${DOC_XML}" )
|
|
||||||
|
|
||||||
foreach( TARGET_ALIAS template_debug template_release editor )
|
foreach( TARGET_ALIAS template_debug template_release editor )
|
||||||
set( TARGET_NAME "godot-cpp.test.${TARGET_ALIAS}" )
|
set( TARGET_NAME "godot-cpp.test.${TARGET_ALIAS}" )
|
||||||
|
|
||||||
|
@ -30,13 +27,13 @@ foreach( TARGET_ALIAS template_debug template_release editor )
|
||||||
src/tests.h
|
src/tests.h
|
||||||
)
|
)
|
||||||
|
|
||||||
set( OUTPUT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/project/bin/" )
|
|
||||||
|
|
||||||
# conditionally add doc data to compile output
|
# conditionally add doc data to compile output
|
||||||
if( TARGET_ALIAS MATCHES "editor|template_debug" )
|
if( TARGET_ALIAS MATCHES "editor|template_debug" )
|
||||||
target_sources( ${TARGET_NAME} PRIVATE "${DOC_DATA_SOURCE}" )
|
target_doc_sources( ${TARGET_NAME} ${DOC_XML} )
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
set( OUTPUT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/project/bin/" )
|
||||||
|
|
||||||
# Link to godot-cpp target
|
# Link to godot-cpp target
|
||||||
set( LINK_TARGET "godot-cpp::${TARGET_ALIAS}" )
|
set( LINK_TARGET "godot-cpp::${TARGET_ALIAS}" )
|
||||||
target_link_libraries( ${TARGET_NAME} PRIVATE ${LINK_TARGET} )
|
target_link_libraries( ${TARGET_NAME} PRIVATE ${LINK_TARGET} )
|
||||||
|
|
Loading…
Reference in New Issue