godot-cpp icon indicating copy to clipboard operation
godot-cpp copied to clipboard

Export cmake target config to build directory

Open zhehangd opened this issue 2 years ago • 2 comments

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)

zhehangd avatar Feb 15 '23 03:02 zhehangd

This would be extremely useful in a CI/CD context, where it would be nice to avoid rebuilding godot-cpp each time.

jacogasp avatar Mar 23 '23 11:03 jacogasp

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.

erodozer avatar Sep 29 '23 05:09 erodozer