From 826c50e1629b38bba6253a2faf537957a3d7e405 Mon Sep 17 00:00:00 2001 From: Zhehang Ding Date: Tue, 14 Feb 2023 19:35:16 -0800 Subject: [PATCH] Export cmake target config to build directory --- CMakeLists.txt | 24 ++++++++++++++++++++++++ cmake/config.cmake.in | 5 +++++ 2 files changed, 29 insertions(+) create mode 100644 cmake/config.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 49d5988f..a6972326 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -210,3 +210,27 @@ set_target_properties(${PROJECT_NAME} RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin" OUTPUT_NAME "${OUTPUT_NAME}" ) + +install(TARGETS ${PROJECT_NAME} EXPORT godot_cpp_targets) + +# Export the target to the build directory. +# The target then can be imported by another cmake project like this: +# find_package(godot-cpp CONFIG REQUIRED) +# +# add_library(libfoo SHARED) +# set_target_properties(libfoo PROPERTIES POSITION_INDEPENDENT_CODE ON) +# target_link_libraries(libfoo PUBLIC godot::godot-cpp) +# +# And user provides the build directory to cmake: +# -DCMAKE_PREFIX_PATH=. + +export(EXPORT godot_cpp_targets + FILE "${PROJECT_BINARY_DIR}/cmake/godot-cpp.cmake" + NAMESPACE godot:: +) + +include(CMakePackageConfigHelpers) +configure_package_config_file(${PROJECT_SOURCE_DIR}/cmake/config.cmake.in + "${PROJECT_BINARY_DIR}/cmake/godot-cpp-config.cmake" + INSTALL_DESTINATION "lib/cmake/godot-cpp" +) diff --git a/cmake/config.cmake.in b/cmake/config.cmake.in new file mode 100644 index 00000000..4501f7b1 --- /dev/null +++ b/cmake/config.cmake.in @@ -0,0 +1,5 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/godot-cpp.cmake") + +check_required_components(godot-cpp)