|
| 1 | +include("GNUInstallDirs") |
| 2 | + |
1 | 3 | function( godotcpp_options )
|
2 | 4 |
|
3 | 5 | #TODO platform
|
4 | 6 | #TODO target
|
5 | 7 |
|
6 | 8 | # Input from user for GDExtension interface header and the API JSON file
|
7 |
| - set(GODOT_GDEXTENSION_DIR "gdextension" CACHE PATH |
| 9 | + set(GODOT_GDEXTENSION_DIR "${PROJECT_SOURCE_DIR}/gdextension" CACHE PATH |
8 | 10 | "Path to a custom directory containing GDExtension interface header and API JSON file ( /path/to/gdextension_dir )" )
|
9 |
| - set(GODOT_CUSTOM_API_FILE "" CACHE FILEPATH |
| 11 | + set(GODOT_CUSTOM_API_FILE "${GODOT_GDEXTENSION_DIR}/extension_api.json" CACHE FILEPATH |
10 | 12 | "Path to a custom GDExtension API JSON file (takes precedence over `gdextension_dir`) ( /path/to/custom_api_file )")
|
11 | 13 |
|
12 | 14 | #TODO generate_bindings
|
@@ -42,6 +44,12 @@ function( godotcpp_options )
|
42 | 44 | option(GODOT_SYSTEM_HEADERS "Expose headers as SYSTEM." ON)
|
43 | 45 | option(GODOT_WARNING_AS_ERROR "Treat warnings as errors" OFF)
|
44 | 46 |
|
| 47 | + set(GODOT_USE_HOT_RELOAD "" CACHE BOOL |
| 48 | + "Enable the extra accounting required to support hot reload. (ON|OFF)") |
| 49 | + |
| 50 | + set(GODOT_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/godot" CACHE PATH |
| 51 | + "Install path to godot-cpp CMake folder (relative to install prefix)") |
| 52 | + |
45 | 53 | # Run options commands on the following to populate cache for all platforms.
|
46 | 54 | # This type of thing is typically done conditionally
|
47 | 55 | # But as scons shows all options so shall we.
|
@@ -203,10 +211,11 @@ function( godotcpp_generate )
|
203 | 211 | set(GODOT_SYSTEM_HEADERS_ATTRIBUTE SYSTEM)
|
204 | 212 | endif ()
|
205 | 213 |
|
206 |
| - target_include_directories(${PROJECT_NAME} ${GODOT_SYSTEM_HEADERS_ATTRIBUTE} PUBLIC |
207 |
| - include |
208 |
| - ${CMAKE_CURRENT_BINARY_DIR}/gen/include |
209 |
| - ${GODOT_GDEXTENSION_DIR} |
| 214 | + target_include_directories(${PROJECT_NAME} ${GODOT_CPP_SYSTEM_HEADERS_ATTRIBUTE} PUBLIC |
| 215 | + $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include> |
| 216 | + $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/gen/include> |
| 217 | + $<BUILD_INTERFACE:${GODOT_GDEXTENSION_DIR}> |
| 218 | + $<INSTALL_INTERFACE:include> |
210 | 219 | )
|
211 | 220 |
|
212 | 221 | # Add the compile flags
|
@@ -235,6 +244,73 @@ function( godotcpp_generate )
|
235 | 244 | LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin"
|
236 | 245 | RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin"
|
237 | 246 | OUTPUT_NAME "${OUTPUT_NAME}"
|
| 247 | + EXPORT_NAME "cpp" # This ensures that the exported target is godot::cpp |
238 | 248 | )
|
239 | 249 |
|
240 | 250 | endfunction()
|
| 251 | + |
| 252 | +function( godotcpp_installable ) |
| 253 | + include("CMakePackageConfigHelpers") |
| 254 | + |
| 255 | + # Install the library and headers to their respective install location |
| 256 | + # CMAKE_INSTALL_* is used to allow the package manager to chose the install location |
| 257 | + install(TARGETS "godot-cpp" |
| 258 | + EXPORT "godot-config" |
| 259 | + ARCHIVE |
| 260 | + DESTINATION "${CMAKE_INSTALL_LIBDIR}" |
| 261 | + COMPONENT "godot-cpp" |
| 262 | + ) |
| 263 | + install( |
| 264 | + DIRECTORY |
| 265 | + "${PROJECT_SOURCE_DIR}/include/" |
| 266 | + "${PROJECT_BINARY_DIR}/gen/include/" |
| 267 | + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" |
| 268 | + COMPONENT "godot-cpp" |
| 269 | + ) |
| 270 | + install(FILES "${GODOT_GDEXTENSION_DIR}/gdextension_interface.h" |
| 271 | + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" |
| 272 | + COMPONENT "godot-cpp" |
| 273 | + ) |
| 274 | + |
| 275 | + # Install the export config file |
| 276 | + # This allows this library to be easily consumed by cmake projects: |
| 277 | + # find_package("godot-cpp" CONFIG REQUIRED) |
| 278 | + # target_link_libaries("my-project" PRIVATE "godot::cpp") |
| 279 | + install(EXPORT "godot-config" |
| 280 | + NAMESPACE "godot::" |
| 281 | + DESTINATION "${GODOT_INSTALL_CMAKEDIR}" |
| 282 | + COMPONENT "godot-cpp" |
| 283 | + ) |
| 284 | + |
| 285 | + if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.19") # string(JSON...) only available in cmake v3.19+ |
| 286 | + # Use the JSON api file to get the version |
| 287 | + file(READ "${GODOT_GDEXTENSION_DIR}/extension_api.json" GODOT_GDEXTENSION_API_JSON) |
| 288 | + # GODOT_API_VERSION_MAJOR = GODOT_GDEXTENSION_API_JSON["header"]["version_major"] |
| 289 | + string(JSON GODOT_API_VERSION_MAJOR GET "${GODOT_GDEXTENSION_API_JSON}" "header" "version_major") |
| 290 | + string(JSON GODOT_API_VERSION_MINOR GET "${GODOT_GDEXTENSION_API_JSON}" "header" "version_minor") |
| 291 | + string(JSON GODOT_API_VERSION_PATCH GET "${GODOT_GDEXTENSION_API_JSON}" "header" "version_patch") |
| 292 | + set(GODOT_API_VERSION "${GODOT_API_VERSION_MAJOR}.${GODOT_API_VERSION_MINOR}.${GODOT_API_VERSION_PATCH}") |
| 293 | + # Install the config version file so that the gdextension version can be specified in find_package |
| 294 | + write_basic_package_version_file("${PROJECT_BINARY_DIR}/godot-config-version.cmake" |
| 295 | + VERSION "${GODOT_API_VERSION}" |
| 296 | + COMPATIBILITY SameMinorVersion |
| 297 | + ) |
| 298 | + install(FILES "${PROJECT_BINARY_DIR}/godot-config-version.cmake" |
| 299 | + DESTINATION "${GODOT_INSTALL_CMAKEDIR}" |
| 300 | + COMPONENT "godot-cpp" |
| 301 | + ) |
| 302 | + |
| 303 | + #Configure and install the pkg-config file |
| 304 | + get_target_property(GODOTCPP_OUTPUT_NAME ${PROJECT_NAME} OUTPUT_NAME) |
| 305 | + configure_file( |
| 306 | + "${PROJECT_SOURCE_DIR}/cmake/godot-cpp.pc.in" |
| 307 | + "${PROJECT_BINARY_DIR}/godot-cpp.pc" |
| 308 | + @ONLY |
| 309 | + ) |
| 310 | + install( |
| 311 | + FILES "${PROJECT_BINARY_DIR}/godot-cpp.pc" |
| 312 | + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig" |
| 313 | + COMPONENT "godot-cpp" |
| 314 | + ) |
| 315 | + endif() |
| 316 | +endfunction() |
0 commit comments