|
| 1 | + |
| 2 | +include("CMakePackageConfigHelpers") |
| 3 | +include("GNUInstallDirs") |
| 4 | + |
| 5 | +# Install the library and headers to their respective install location |
| 6 | +# CMAKE_INSTALL_ are used to allow the package manager to chose the install location |
| 7 | +# Components are used so that if godot-cpp is a subproject, the user can chose not to install it |
| 8 | +install(TARGETS "godot-cpp" |
| 9 | + EXPORT "godot-cpp-target" |
| 10 | + ARCHIVE |
| 11 | + DESTINATION "${CMAKE_INSTALL_LIBDIR}" |
| 12 | + COMPONENT "godot-cpp-dev" |
| 13 | +) |
| 14 | +install( |
| 15 | + DIRECTORY |
| 16 | + "${CMAKE_CURRENT_SOURCE_DIR}/include/" |
| 17 | + "${CMAKE_CURRENT_BINARY_DIR}/gen/include/" |
| 18 | + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" |
| 19 | + COMPONENT "godot-cpp-dev" |
| 20 | +) |
| 21 | +# Install the gdextension files |
| 22 | +# The gdextension header is assumed to be the root include directory |
| 23 | +# As the JSON file is neither a header nor lib file it goes to the datadir |
| 24 | +install(FILES "${GODOT_GDEXTENSION_DIR}/gdextension_interface.h" |
| 25 | + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" |
| 26 | + COMPONENT "godot-cpp-dev" |
| 27 | +) |
| 28 | +install(FILES "${GODOT_GDEXTENSION_API_FILE}" |
| 29 | + DESTINATION "${CMAKE_INSTALL_DATADIR}/godot-cpp" |
| 30 | + COMPONENT "godot-cpp-dev" |
| 31 | +) |
| 32 | + |
| 33 | +# Install the export config file |
| 34 | +# This allows this library to be easily consumed by cmake projects: |
| 35 | +# find_package("godot-cpp" 4.2.0 CONFIG REQUIRED) |
| 36 | +# target_link_libaries("my-project" PRIVATE "godot::cpp") |
| 37 | +install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.cmake" |
| 38 | + RENAME "godot-cpp-config.cmake" |
| 39 | + DESTINATION "${CMAKE_INSTALL_DATADIR}/godot-cpp" |
| 40 | + COMPONENT "godot-cpp-dev" |
| 41 | +) |
| 42 | +install(EXPORT "godot-cpp-target" |
| 43 | + NAMESPACE "godot::" |
| 44 | + DESTINATION "${CMAKE_INSTALL_DATADIR}/godot-cpp" |
| 45 | + COMPONENT "godot-cpp-dev" |
| 46 | +) |
| 47 | + |
| 48 | +if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.19") # string(JSON...) only available in cmake v3.19+ |
| 49 | + # Use the JSON api file to get the version |
| 50 | + file(READ "${GODOT_GDEXTENSION_API_FILE}" GODOT_GDEXTENSION_API_JSON) |
| 51 | + # GODOT_API_VERSION_MAJOR = GODOT_GDEXTENSION_API_JSON["header"]["version_major"] |
| 52 | + string(JSON GODOT_API_VERSION_MAJOR GET "${GODOT_GDEXTENSION_API_JSON}" "header" "version_major") |
| 53 | + string(JSON GODOT_API_VERSION_MINOR GET "${GODOT_GDEXTENSION_API_JSON}" "header" "version_minor") |
| 54 | + string(JSON GODOT_API_VERSION_PATCH GET "${GODOT_GDEXTENSION_API_JSON}" "header" "version_patch") |
| 55 | + set(GODOT_API_VERSION "${GODOT_API_VERSION_MAJOR}.${GODOT_API_VERSION_MINOR}.${GODOT_API_VERSION_PATCH}") |
| 56 | + unset(GODOT_GDEXTENSION_API_JSON) |
| 57 | + |
| 58 | + # Install the config version file so that the gdextension version can be specified in find_package |
| 59 | + write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/godot-cpp-config-version.cmake" |
| 60 | + VERSION "${GODOT_API_VERSION}" |
| 61 | + COMPATIBILITY SameMinorVersion |
| 62 | + ) |
| 63 | + install(FILES "${CMAKE_CURRENT_BINARY_DIR}/godot-cpp-config-version.cmake" |
| 64 | + DESTINATION "${CMAKE_INSTALL_DATADIR}/godot-cpp" |
| 65 | + COMPONENT "godot-cpp-dev" |
| 66 | + ) |
| 67 | +endif() |
0 commit comments