@@ -4,7 +4,7 @@ function( godotcpp_options )
44 #TODO target
55
66 # Input from user for GDExtension interface header and the API JSON file
7- set (GODOT_GDEXTENSION_DIR "gdextension" CACHE PATH
7+ set (GODOT_GDEXTENSION_DIR "${PROJECT_SOURCE_DIR} / gdextension" CACHE PATH
88 "Path to a custom directory containing GDExtension interface header and API JSON file ( /path/to/gdextension_dir )" )
99 set (GODOT_CUSTOM_API_FILE "" CACHE FILEPATH
1010 "Path to a custom GDExtension API JSON file (takes precedence over `gdextension_dir`) ( /path/to/custom_api_file )" )
@@ -203,10 +203,11 @@ function( godotcpp_generate )
203203 set (GODOT_SYSTEM_HEADERS_ATTRIBUTE SYSTEM )
204204 endif ()
205205
206- target_include_directories (${PROJECT_NAME} ${GODOT_SYSTEM_HEADERS_ATTRIBUTE} PUBLIC
207- include
208- ${CMAKE_CURRENT_BINARY_DIR} /gen/include
209- ${GODOT_GDEXTENSION_DIR}
206+ target_include_directories (${PROJECT_NAME} ${GODOT_CPP_SYSTEM_HEADERS_ATTRIBUTE} PUBLIC
207+ $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR} /include >
208+ $<BUILD_INTERFACE:${PROJECT_BINARY_DIR} /gen/include >
209+ $<BUILD_INTERFACE:${GODOT_GDEXTENSION_DIR} >
210+ $<INSTALL_INTERFACE:include >
210211 )
211212
212213 # Add the compile flags
@@ -235,6 +236,63 @@ function( godotcpp_generate )
235236 LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR} /bin"
236237 RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR} /bin"
237238 OUTPUT_NAME "${OUTPUT_NAME} "
239+ EXPORT_NAME "cpp" # This ensures that the exported target is godot::cpp
238240 )
239241
240242endfunction ()
243+
244+ function ( godotcpp_install )
245+ include ("CMakePackageConfigHelpers" )
246+ include ("GNUInstallDirs" )
247+
248+ # Install the library and headers to their respective install location
249+ # CMAKE_INSTALL_ are used to allow the package manager to chose the install location
250+ install (TARGETS "godot-cpp"
251+ EXPORT "godot-cpp-config"
252+ ARCHIVE
253+ DESTINATION "${CMAKE_INSTALL_LIBDIR} "
254+ )
255+ install (
256+ DIRECTORY
257+ "${PROJECT_SOURCE_DIR} /include/"
258+ "${PROJECT_BINARY_DIR} /gen/include/"
259+ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR} "
260+ )
261+
262+ # Install the gdextension files
263+ # The gdextension header is assumed to be the root include directory
264+ # As the JSON file is neither a header nor lib file it goes to the datadir
265+ install (FILES "${GODOT_GDEXTENSION_DIR} /gdextension_interface.h"
266+ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR} "
267+ )
268+ install (FILES "${GODOT_GDEXTENSION_DIR} /extension_api.json"
269+ DESTINATION "${CMAKE_INSTALL_DATADIR} /godot-cpp"
270+ )
271+
272+ # Install the export config file
273+ # This allows this library to be easily consumed by cmake projects:
274+ # find_package("godot-cpp" CONFIG REQUIRED)
275+ # target_link_libaries("my-project" PRIVATE "godot::cpp")
276+ install (EXPORT "godot-cpp-config"
277+ NAMESPACE "godot::"
278+ DESTINATION "${CMAKE_INSTALL_DATADIR} /godot-cpp"
279+ )
280+
281+ if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.19" ) # string(JSON...) only available in cmake v3.19+
282+ # Use the JSON api file to get the version
283+ file (READ "${GODOT_GDEXTENSION_DIR} /extension_api.json" GODOT_GDEXTENSION_API_JSON)
284+ # GODOT_API_VERSION_MAJOR = GODOT_GDEXTENSION_API_JSON["header"]["version_major"]
285+ string (JSON GODOT_API_VERSION_MAJOR GET "${GODOT_GDEXTENSION_API_JSON} " "header" "version_major" )
286+ string (JSON GODOT_API_VERSION_MINOR GET "${GODOT_GDEXTENSION_API_JSON} " "header" "version_minor" )
287+ string (JSON GODOT_API_VERSION_PATCH GET "${GODOT_GDEXTENSION_API_JSON} " "header" "version_patch" )
288+ set (GODOT_API_VERSION "${GODOT_API_VERSION_MAJOR} .${GODOT_API_VERSION_MINOR} .${GODOT_API_VERSION_PATCH} " )
289+ # Install the config version file so that the gdextension version can be specified in find_package
290+ write_basic_package_version_file("${PROJECT_BINARY_DIR} /godot-cpp-config-version.cmake"
291+ VERSION "${GODOT_API_VERSION} "
292+ COMPATIBILITY SameMinorVersion
293+ )
294+ install (FILES "${PROJECT_BINARY_DIR} /godot-cpp-config-version.cmake"
295+ DESTINATION "${CMAKE_INSTALL_DATADIR} /godot-cpp"
296+ )
297+ endif ()
298+ endfunction ()
0 commit comments