|
| 1 | +include("CMakePackageConfigHelpers") |
| 2 | +include("GNUInstallDirs") |
| 3 | + |
1 | 4 | function( godotcpp_options )
|
2 | 5 |
|
3 | 6 | #TODO platform
|
4 | 7 | #TODO target
|
5 | 8 |
|
6 | 9 | # Input from user for GDExtension interface header and the API JSON file
|
7 |
| - set(GODOT_GDEXTENSION_DIR "gdextension" CACHE PATH |
| 10 | + set(GODOT_GDEXTENSION_DIR "${CMAKE_CURRENT_SOURCE_DIR}/gdextension" CACHE PATH |
8 | 11 | "Path to a custom directory containing GDExtension interface header and API JSON file ( /path/to/gdextension_dir )" )
|
9 | 12 | set(GODOT_CUSTOM_API_FILE "" CACHE FILEPATH
|
10 | 13 | "Path to a custom GDExtension API JSON file (takes precedence over `gdextension_dir`) ( /path/to/custom_api_file )")
|
@@ -204,9 +207,10 @@ function( godotcpp_generate )
|
204 | 207 | endif ()
|
205 | 208 |
|
206 | 209 | target_include_directories(${PROJECT_NAME} ${GODOT_SYSTEM_HEADERS_ATTRIBUTE} PUBLIC
|
207 |
| - include |
208 |
| - ${CMAKE_CURRENT_BINARY_DIR}/gen/include |
209 |
| - ${GODOT_GDEXTENSION_DIR} |
| 210 | + "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>" |
| 211 | + "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/gen/include>" |
| 212 | + "$<BUILD_INTERFACE:${GODOT_GDEXTENSION_DIR}>" |
| 213 | + "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>" |
210 | 214 | )
|
211 | 215 |
|
212 | 216 | # Add the compile flags
|
@@ -235,6 +239,53 @@ function( godotcpp_generate )
|
235 | 239 | LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin"
|
236 | 240 | RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin"
|
237 | 241 | OUTPUT_NAME "${OUTPUT_NAME}"
|
| 242 | + EXPORT_NAME "cpp" # This ensures that the exported target is godot::cpp when installed |
238 | 243 | )
|
239 | 244 |
|
240 | 245 | endfunction()
|
| 246 | + |
| 247 | +function( godotcpp_installable ) |
| 248 | + # Install the library |
| 249 | + install(TARGETS "godot-cpp" |
| 250 | + EXPORT "godot-config" |
| 251 | + ARCHIVE |
| 252 | + DESTINATION "${CMAKE_INSTALL_LIBDIR}" |
| 253 | + COMPONENT "godot-cpp" |
| 254 | + ) |
| 255 | + #Install the headers |
| 256 | + install( |
| 257 | + DIRECTORY |
| 258 | + "${PROJECT_SOURCE_DIR}/include/" |
| 259 | + "${PROJECT_BINARY_DIR}/gen/include/" |
| 260 | + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" |
| 261 | + COMPONENT "godot-cpp" |
| 262 | + ) |
| 263 | + install(FILES "${GODOT_GDEXTENSION_DIR}/gdextension_interface.h" |
| 264 | + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" |
| 265 | + COMPONENT "godot-cpp" |
| 266 | + ) |
| 267 | + # Install the export config file, so the library can be found via find_package |
| 268 | + install(EXPORT "godot-config" |
| 269 | + NAMESPACE "godot::" |
| 270 | + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/godot" |
| 271 | + COMPONENT "godot-cpp" |
| 272 | + ) |
| 273 | + |
| 274 | + if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.19") # string(JSON...) only available in cmake v3.19+ |
| 275 | + # Use the JSON api file to get the version |
| 276 | + file(READ "${GODOT_GDEXTENSION_DIR}/extension_api.json" GODOT_GDEXTENSION_API_JSON) |
| 277 | + string(JSON GODOT_API_VERSION_MAJOR GET "${GODOT_GDEXTENSION_API_JSON}" "header" "version_major") # GODOT_API_VERSION_MAJOR = GODOT_GDEXTENSION_API_JSON["header"]["version_major"] |
| 278 | + string(JSON GODOT_API_VERSION_MINOR GET "${GODOT_GDEXTENSION_API_JSON}" "header" "version_minor") |
| 279 | + string(JSON GODOT_API_VERSION_PATCH GET "${GODOT_GDEXTENSION_API_JSON}" "header" "version_patch") |
| 280 | + set(GODOT_API_VERSION "${GODOT_API_VERSION_MAJOR}.${GODOT_API_VERSION_MINOR}.${GODOT_API_VERSION_PATCH}") |
| 281 | + # Install the config version file so that the gdextension version can be specified in find_package |
| 282 | + write_basic_package_version_file("${PROJECT_BINARY_DIR}/godot-config-version.cmake" |
| 283 | + VERSION "${GODOT_API_VERSION}" |
| 284 | + COMPATIBILITY SameMinorVersion # https://docs.godotengine.org/en/stable/tutorials/scripting/gdextension/what_is_gdextension.html#version-compatibility |
| 285 | + ) |
| 286 | + install(FILES "${PROJECT_BINARY_DIR}/godot-config-version.cmake" |
| 287 | + DESTINATION "${GODOT_INSTALL_CMAKEDIR}" |
| 288 | + COMPONENT "godot-cpp" |
| 289 | + ) |
| 290 | + endif() |
| 291 | +endfunction() |
0 commit comments