godot-cpp
godot-cpp copied to clipboard
Export cmake target config to build directory
I use cmake to build gdextension in linux. I used to make godot-cpp a submodule in my game project with add_subdirectory
to create godot-cpp targets. It works fine but is a bit cumbersome.
An alternative approach would be maintaining and building godot-cpp alone then telling my game project where the godot-cpp library is.
This PR makes cmake generate necessary files so that any other cmake-based projects can import godot-cpp like regular libraries. This makes it possible to share the compiled godot-cpp library among different projects.
Example:
# Build godot-cpp somewhere
mkdir build_godot_cpp
cmake -B build_godot_cpp -S godot-cpp -DCMAKE_BUILD_TYPE=Release
cmake --build build_godot_cpp -j12
# Build my gdextension with path to the library
mkdir build_myextension
cmake -B build_myextension -S myextension_source -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=$(realpath build_godot_cpp)
cmake --build build_myextension -j12
and in my CMakeLists.txt I write:
find_package(godot-cpp CONFIG REQUIRED)
# ...
target_link_libraries(libmyextension PUBLIC godot::godot-cpp)
This would be extremely useful in a CI/CD context, where it would be nice to avoid rebuilding godot-cpp each time.
As someone trying to get godot-cpp working this way through vcpkg and would love to also see a portfile.cmake for godot-cpp in the official registry, I'm highly interested in seeing this merged.