Skip to content

CMake Configuration Exporting #1309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 49 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# GODOT_CPP_SYSTEM_HEADERS Mark the header files as SYSTEM. This may be useful to supress warnings in projects including this one.
# GODOT_CPP_WARNING_AS_ERROR Treat any warnings as errors
# GODOT_CUSTOM_API_FILE: Path to a custom GDExtension API JSON file (takes precedence over `gdextension_dir`)
# GODOT_CPP_INSTALL: Enables target install for exporting godot-cpp cmake configuration
# FLOAT_PRECISION: Floating-point precision level ("single", "double")
#
# Android cmake arguments
Expand Down Expand Up @@ -43,6 +44,8 @@ project(godot-cpp LANGUAGES CXX)
option(GENERATE_TEMPLATE_GET_NODE "Generate a template version of the Node class's get_node." ON)
option(GODOT_CPP_SYSTEM_HEADERS "Expose headers as SYSTEM." ON)
option(GODOT_CPP_WARNING_AS_ERROR "Treat warnings as errors" OFF)
option(GODOT_CPP_INSTALL "Enables target install for exporting godot-cpp cmake configuration" ON)


# Add path to modules
list( APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/" )
Expand All @@ -65,7 +68,7 @@ if(NOT DEFINED BITS)
endif()

# Input from user for GDExtension interface header and the API JSON file
set(GODOT_GDEXTENSION_DIR "gdextension" CACHE STRING "")
set(GODOT_GDEXTENSION_DIR "${CMAKE_CURRENT_SOURCE_DIR}/gdextension" CACHE STRING "")
set(GODOT_CUSTOM_API_FILE "" CACHE STRING "")

set(GODOT_GDEXTENSION_API_FILE "${GODOT_GDEXTENSION_DIR}/extension_api.json")
Expand Down Expand Up @@ -183,9 +186,10 @@ if (GODOT_CPP_SYSTEM_HEADERS)
endif ()

target_include_directories(${PROJECT_NAME} ${GODOT_CPP_SYSTEM_HEADERS_ATTRIBUTE} PUBLIC
include
${CMAKE_CURRENT_BINARY_DIR}/gen/include
${GODOT_GDEXTENSION_DIR}
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/gen/include>
$<BUILD_INTERFACE:${GODOT_GDEXTENSION_DIR}>
$<INSTALL_INTERFACE:include>
)

# Add the compile flags
Expand Down Expand Up @@ -213,4 +217,45 @@ set_target_properties(${PROJECT_NAME}
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin"
OUTPUT_NAME "${OUTPUT_NAME}"
EXPORT_NAME "cpp"
)

if ($CACHE{GODOT_CPP_INSTALL})
install(TARGETS ${PROJECT_NAME}
EXPORT GodotCppTargets
)

install(EXPORT GodotCppTargets
FILE GodotCppTargets.cmake
NAMESPACE godot::
DESTINATION lib/cmake/GodotCpp
)

install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/
DESTINATION include
)

install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/gen/include/
DESTINATION include
)

if (GODOT_GDEXTENSION_DIR AND EXISTS ${GODOT_GDEXTENSION_DIR})
install(DIRECTORY ${GODOT_GDEXTENSION_DIR}/
DESTINATION include
)
endif ()

include(CMakePackageConfigHelpers)

configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/GodotCppConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/GodotCppConfig.cmake"
INSTALL_DESTINATION "lib/cmake/GodotCpp"
NO_SET_AND_CHECK_MACRO
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)

install(FILES
${CMAKE_CURRENT_BINARY_DIR}/GodotCppConfig.cmake
DESTINATION lib/cmake/GodotCpp
)
endif ()
3 changes: 3 additions & 0 deletions cmake/GodotCppConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/GodotCppTargets.cmake")