Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] Add CMake support for XML documentation #1499

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dsnopek
Copy link
Collaborator

@dsnopek dsnopek commented Jun 19, 2024

I forgot to add CMake support in PR #1374

So far this PR is just refactoring the scons code so that CMake can generate the code via the doc_source_generator.py script. However, I haven't yet figured out how to add that to CMake yet. If anyone who knows CMake can help out, that'd be great! Otherwise, I will work something eventually. :-)

@dsnopek dsnopek added cmake topic:buildsystem Related to the buildsystem or CI setup labels Jun 19, 2024
@dsnopek dsnopek added this to the 4.x milestone Jun 19, 2024
@dsnopek dsnopek requested a review from a team as a code owner June 19, 2024 20:49
@dsnopek dsnopek marked this pull request as draft June 19, 2024 21:00
@Naros
Copy link
Contributor

Naros commented Jun 20, 2024

Hi @dsnopek so this is what I did to hack this for cmake:

  1. Defined a simple godot-docs-generator.cmake file with this content. The paths could be arguments passed into the function from the main CMAKE file to allow maximum configuration, I just didn't go that far due to this being a PoC.
FUNCTION( GENERATE_GODOT_DOCUMENTATION )
    # Grab all documentation XML files
    FILE(GLOB XML_FILES "${CMAKE_CURRENT_SOURCE_DIR}/doc_classes/*.xml")
    STRING(JOIN "," XML_FILES_STR ${XML_FILES})
    # Generate the target file
    SET(DOC_DATA_CPP_FILE "${CMAKE_BINARY_DIR}/_generated/doc_data.cpp")
    STRING(JOIN "," DOC_DATA_CPP_STR ${DOC_DATA_CPP_FILE})
    # Run python to generate the doc_data.cpp file
    EXECUTE_PROCESS(
            COMMAND cmd /c py ${CMAKE_CURRENT_SOURCE_DIR}/cmake/generate_godot_docs.py ${DOC_DATA_CPP_STR} ${XML_FILES_STR}
            WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
    )
ENDFUNCTION()
  1. In the generate_godot_docs.py, it contained your make_doc_source function verbatim, with this added to the bottom. I'm not a huge python guy, so might be a better way to do it:
def main():
    if len(sys.argv) > 2:
        target_str = sys.argv[1]
        target_list = target_str.split(",")
        source_str = sys.argv[2]
        source_list = source_str.split(",")
        make_doc_source(target_list, source_list)

if __name__ == "__main__":
    main()
  1. In the main cmake, include the generate-godot-documentation.cmake and call the function, i.e.:
INCLUDE(godot-docs-generator)
GENERATE_GODOT_DOCUMENTATION()

Now CMAKE will use python to run the script and generate the ${CMAKE_BINARY_DIR}/_generated/doc_data.cpp file. All the CMAKE then needs to do is to add that generated file to the list of sources, i.e.:

# Library sources
FILE(GLOB_RECURSE gdext_sources
        CONFIGURE_DEPENDS
        "${CMAKE_CURRENT_SOURCE_DIR}/src/*.[hc]"
        "${CMAKE_CURRENT_SOURCE_DIR}/src/*.[hc]pp"
        # Includes the generated doc data from /doc_classes
        "${CMAKE_BINARY_DIR}/_generated/*.cpp"
)

And that's it. It should be pretty straight forward to augment this for the current godot-cpp cmake, but likely with a few extra things since I did this in my downstream extension cmake.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cmake topic:buildsystem Related to the buildsystem or CI setup
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants