Alleviate CMake target name clashes, visibility, and grouping.

Simplify <platform>_generate cmake function signature, as TARGET_ALIAS and TARGET_NAME are still in scope and do not need to be passed.
Add USE_FOLDERS, and FOLDER properties to group targets in VS and XCode
Guard test target with GODOT_ENABLE_TESTING
Generate all three variants in the form godot-cpp.test.<target> to remove the -DTEST_TARGET option clutter.
Update the docs/cmake.rst with information about the testing target
Update the Github CI
This commit is contained in:
Samuel Nicholas
2024-12-11 10:40:21 +10:30
parent 47f11bc5c7
commit 6f7293cef4
12 changed files with 181 additions and 125 deletions

View File

@@ -142,6 +142,9 @@ function( godotcpp_options )
option( GODOT_SYSTEM_HEADERS "Expose headers as SYSTEM." OFF )
option( GODOT_WARNING_AS_ERROR "Treat warnings as errors" OFF )
# Enable Testing
option( GODOT_ENABLE_TESTING "Enable the godot-cpp.test.<target> integration testing targets" OFF )
#[[ Target Platform Options ]]
android_options()
ios_options()
@@ -228,7 +231,7 @@ function( godotcpp_generate )
### Platform is derived from the toolchain target
# See GeneratorExpressions PLATFORM_ID and CMAKE_SYSTEM_NAME
set( SYSTEM_NAME
$<$<PLATFORM_ID:Android>:android.${ANDROID_ABI}>
$<$<PLATFORM_ID:Android>:android>
$<$<PLATFORM_ID:iOS>:ios>
$<$<PLATFORM_ID:Linux>:linux>
$<$<PLATFORM_ID:Darwin>:macos>
@@ -263,7 +266,8 @@ function( godotcpp_generate )
set( DEV_TAG "$<${IS_DEV_BUILD}:.dev>" )
### Define our godot-cpp library targets
foreach ( TARGET_NAME template_debug template_release editor )
foreach ( TARGET_ALIAS template_debug template_release editor )
set( TARGET_NAME "godot-cpp.${TARGET_ALIAS}" )
# Generator Expressions that rely on the target
set( DEBUG_FEATURES "$<NOT:$<STREQUAL:${TARGET_NAME},template_release>>" )
@@ -271,7 +275,7 @@ function( godotcpp_generate )
# the godot-cpp.* library targets
add_library( ${TARGET_NAME} STATIC EXCLUDE_FROM_ALL )
add_library( godot-cpp::${TARGET_NAME} ALIAS ${TARGET_NAME} )
add_library( godot-cpp::${TARGET_ALIAS} ALIAS ${TARGET_NAME} )
file( GLOB_RECURSE GODOTCPP_SOURCES LIST_DIRECTORIES NO CONFIGURE_DEPENDS src/*.cpp )
@@ -298,33 +302,36 @@ function( godotcpp_generate )
BUILD_RPATH_USE_ORIGIN ON
PREFIX lib
OUTPUT_NAME "${PROJECT_NAME}.${SYSTEM_NAME}.${TARGET_NAME}${DEV_TAG}.${SYSTEM_ARCH}"
OUTPUT_NAME "${PROJECT_NAME}.${SYSTEM_NAME}.${TARGET_ALIAS}${DEV_TAG}.${SYSTEM_ARCH}"
ARCHIVE_OUTPUT_DIRECTORY "$<1:${CMAKE_BINARY_DIR}/bin>"
# Things that are handy to know for dependent targets
GODOT_PLATFORM "${SYSTEM_NAME}"
GODOT_TARGET "${TARGET_NAME}"
GODOT_TARGET "${TARGET_ALIAS}"
GODOT_ARCH "${SYSTEM_ARCH}"
# Some IDE's respect this property to logically group targets
FOLDER "godot-cpp"
)
if( CMAKE_SYSTEM_NAME STREQUAL Android )
android_generate( ${TARGET_NAME} )
android_generate()
elseif ( CMAKE_SYSTEM_NAME STREQUAL iOS )
ios_generate( ${TARGET_NAME} )
ios_generate()
elseif ( CMAKE_SYSTEM_NAME STREQUAL Linux )
linux_generate( ${TARGET_NAME} )
linux_generate()
elseif ( CMAKE_SYSTEM_NAME STREQUAL Darwin )
macos_generate( ${TARGET_NAME} )
macos_generate()
elseif ( CMAKE_SYSTEM_NAME STREQUAL Emscripten )
web_generate( ${TARGET_NAME} )
web_generate()
elseif ( CMAKE_SYSTEM_NAME STREQUAL Windows )
windows_generate( ${TARGET_NAME} )
windows_generate()
endif ()
endforeach ()
# Added for backwards compatibility with prior cmake solution so that builds dont immediately break
# from a missing target.
add_library( godot::cpp ALIAS template_debug )
add_library( godot::cpp ALIAS godot-cpp.template_debug )
endfunction()