From 0263b91ddd5881ef399dde3ddfc8882f07c15ae6 Mon Sep 17 00:00:00 2001 From: Samuel Nicholas Date: Sat, 7 Dec 2024 10:18:24 +1030 Subject: [PATCH] Alleviate CMake target name clashes, visibility, and grouping. Simplify _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 --- .github/workflows/ci.yml | 4 ++-- CMakeLists.txt | 11 +++++++++-- cmake/android.cmake | 5 ++--- cmake/common_compiler_flags.cmake | 2 +- cmake/godotcpp.cmake | 33 ++++++++++++++++++------------- cmake/ios.cmake | 5 ++--- cmake/linux.cmake | 5 ++--- cmake/macos.cmake | 4 ++-- cmake/web.cmake | 5 ++--- cmake/windows.cmake | 4 ++-- 10 files changed, 43 insertions(+), 35 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 33b2450d8..13d9c6e81 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -225,7 +225,7 @@ jobs: run: | mkdir cmake-build cd cmake-build - cmake ../ -DTEST_TARGET=template_release + cmake ../ -DGODOT_ENABLE_TESTING=YES -DTEST_TARGET=template_release cmake --build . --verbose -j $(nproc) -t godot-cpp-test --config Release windows-msvc-cmake: @@ -241,5 +241,5 @@ jobs: run: | mkdir cmake-build cd cmake-build - cmake ../ -DTEST_TARGET=template_release + cmake ../ -DGODOT_ENABLE_TESTING=YES -DTEST_TARGET=template_release cmake --build . --verbose -t godot-cpp-test --config Release diff --git a/CMakeLists.txt b/CMakeLists.txt index 926946d98..872c3a64d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -94,5 +94,12 @@ project( godot-cpp godotcpp_generate() -# Test Example -add_subdirectory( test ) +# optionally add the godot-cpp-test integration testing target +if( GODOT_ENABLE_TESTING ) + add_subdirectory( test ) +endif() + +# If this is the top level CMakeLists.txt, Generators which honor the +# USE_FOLDERS flag will organize godot-cpp targets under the subfolder +# 'godot-cpp'. This is enable by default from CMake version 3.26 +set_property(GLOBAL PROPERTY USE_FOLDERS ON) diff --git a/cmake/android.cmake b/cmake/android.cmake index 2227f89ce..d3d95ee50 100644 --- a/cmake/android.cmake +++ b/cmake/android.cmake @@ -29,13 +29,12 @@ function( android_options ) # Android Options endfunction() -function( android_generate TARGET_NAME ) - +function( android_generate ) target_compile_definitions(${TARGET_NAME} PUBLIC ANDROID_ENABLED UNIX_ENABLED ) - common_compiler_flags( ${TARGET_NAME} ) + common_compiler_flags() endfunction() diff --git a/cmake/common_compiler_flags.cmake b/cmake/common_compiler_flags.cmake index 1b185fe2c..2062df3bd 100644 --- a/cmake/common_compiler_flags.cmake +++ b/cmake/common_compiler_flags.cmake @@ -25,7 +25,7 @@ set( HOT_RELOAD-UNSET "$") set( DISABLE_EXCEPTIONS "$") -function( common_compiler_flags TARGET_NAME ) +function( common_compiler_flags ) set( IS_RELEASE "$") set( DEBUG_FEATURES "$,$>" ) set( HOT_RELOAD "$,$>" ) diff --git a/cmake/godotcpp.cmake b/cmake/godotcpp.cmake index 13f1bfdb1..a7154ee91 100644 --- a/cmake/godotcpp.cmake +++ b/cmake/godotcpp.cmake @@ -122,9 +122,10 @@ function( godotcpp_options ) option( GODOT_SYSTEM_HEADERS "Expose headers as SYSTEM." OFF ) option( GODOT_WARNING_AS_ERROR "Treat warnings as errors" OFF ) - # Run options commands on the following to populate cache for all - # platforms. This type of thing is typically done conditionally But as - # scons shows all options so shall we. + #[[ Target Platform Options ]] + # Enable Testing + option( GODOT_ENABLE_TESTING "Enable the godot-cpp-test target for integration testing" OFF ) + android_options() ios_options() linux_options() @@ -231,7 +232,8 @@ function( godotcpp_generate ) endif() ### 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}" ) # Useful genex snippits used in subsequent genex's set( IS_RELEASE "$") @@ -241,7 +243,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 ) @@ -268,33 +270,36 @@ function( godotcpp_generate ) BUILD_RPATH_USE_ORIGIN ON PREFIX lib - OUTPUT_NAME "${PROJECT_NAME}.${SYSTEM_NAME}.${TARGET_NAME}.${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() diff --git a/cmake/ios.cmake b/cmake/ios.cmake index bb9642210..a4c570577 100644 --- a/cmake/ios.cmake +++ b/cmake/ios.cmake @@ -10,13 +10,12 @@ function(ios_options) # iOS options endfunction() -function(ios_generate TARGET_NAME) - +function(ios_generate) target_compile_definitions(${TARGET_NAME} PUBLIC IOS_ENABLED UNIX_ENABLED ) - common_compiler_flags(${TARGET_NAME}) + common_compiler_flags() endfunction() diff --git a/cmake/linux.cmake b/cmake/linux.cmake index fae620e0e..15855099e 100644 --- a/cmake/linux.cmake +++ b/cmake/linux.cmake @@ -10,13 +10,12 @@ function( linux_options ) # Linux Options endfunction() -function( linux_generate TARGET_NAME ) - +function( linux_generate ) target_compile_definitions( ${TARGET_NAME} PUBLIC LINUX_ENABLED UNIX_ENABLED ) - common_compiler_flags( ${TARGET_NAME} ) + common_compiler_flags() endfunction() diff --git a/cmake/macos.cmake b/cmake/macos.cmake index 1bb4dbcfb..6cb33bcc7 100644 --- a/cmake/macos.cmake +++ b/cmake/macos.cmake @@ -23,7 +23,7 @@ function( macos_options ) endfunction() -function( macos_generate TARGET_NAME ) +function( macos_generate ) # OSX_ARCHITECTURES does not support generator expressions. if( NOT GODOT_ARCH OR GODOT_ARCH STREQUAL universal ) @@ -55,5 +55,5 @@ function( macos_generate TARGET_NAME ) ${COCOA_LIBRARY} ) - common_compiler_flags( ${TARGET_NAME} ) + common_compiler_flags() endfunction() diff --git a/cmake/web.cmake b/cmake/web.cmake index b7d6c13aa..8ccd28f2d 100644 --- a/cmake/web.cmake +++ b/cmake/web.cmake @@ -15,8 +15,7 @@ function( web_options ) endfunction() -function( web_generate TARGET_NAME ) - +function( web_generate ) target_compile_definitions(${TARGET_NAME} PUBLIC WEB_ENABLED @@ -38,5 +37,5 @@ function( web_generate TARGET_NAME ) -shared ) - common_compiler_flags( ${TARGET_NAME} ) + common_compiler_flags() endfunction() diff --git a/cmake/windows.cmake b/cmake/windows.cmake index c209bdee8..e29cb6a69 100644 --- a/cmake/windows.cmake +++ b/cmake/windows.cmake @@ -58,7 +58,7 @@ function( windows_options ) endfunction() #[===========================[ Target Generation ]===========================] -function( windows_generate TARGET_NAME ) +function( windows_generate ) set( IS_MSVC "$" ) set( IS_CLANG "$,$>" ) set( NOT_MSVC "$" ) @@ -100,5 +100,5 @@ function( windows_generate TARGET_NAME ) $<${IS_CLANG}:-lstdc++> ) - common_compiler_flags( ${TARGET_NAME} ) + common_compiler_flags() endfunction()