Skip to content

Commit 3c816e4

Browse files
committed
Export cmake target config to build directory
1 parent 0068320 commit 3c816e4

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

CMakeLists.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,3 +210,27 @@ set_target_properties(${PROJECT_NAME}
210210
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin"
211211
OUTPUT_NAME "${OUTPUT_NAME}"
212212
)
213+
214+
install(TARGETS ${PROJECT_NAME} EXPORT godot_cpp_targets)
215+
216+
# Export the target to the build directory.
217+
# The target then can be imported by another cmake project like this:
218+
# find_package(godot-cpp CONFIG REQUIRED)
219+
#
220+
# add_library(libfoo SHARED)
221+
# set_target_properties(libfoo PROPERTIES POSITION_INDEPENDENT_CODE ON)
222+
# target_link_libraries(libfoo PUBLIC godot::godot-cpp)
223+
#
224+
# And user provides the build directory to cmake:
225+
# -DCMAKE_PREFIX_PATH=<absolute-path-to-godot-cpp-build-dir>.
226+
227+
export(EXPORT godot_cpp_targets
228+
FILE "${PROJECT_BINARY_DIR}/cmake/godot-cpp.cmake"
229+
NAMESPACE godot::
230+
)
231+
232+
include(CMakePackageConfigHelpers)
233+
configure_package_config_file(${PROJECT_SOURCE_DIR}/cmake/config.cmake.in
234+
"${PROJECT_BINARY_DIR}/cmake/godot-cpp-config.cmake"
235+
INSTALL_DESTINATION "lib/cmake/godot-cpp"
236+
)

cmake/config.cmake.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@PACKAGE_INIT@
2+
3+
include("${CMAKE_CURRENT_LIST_DIR}/godot-cpp.cmake")
4+
5+
check_required_components(godot-cpp)

0 commit comments

Comments
 (0)