From b2eb732aadae33c9f29c48b3f394fd758e485663 Mon Sep 17 00:00:00 2001 From: torets Date: Tue, 14 Jan 2025 15:24:54 +0300 Subject: [PATCH] adding options to hide some of targets from building --- cmake/godotcpp.cmake | 28 ++++++++++++++++++++++++---- test/CMakeLists.txt | 2 +- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/cmake/godotcpp.cmake b/cmake/godotcpp.cmake index 49480699..c98afaa4 100644 --- a/cmake/godotcpp.cmake +++ b/cmake/godotcpp.cmake @@ -42,7 +42,6 @@ set( PLATFORM_LIST linux macos windows android ios web ) # List of known architectures set( ARCH_LIST universal x86_32 x86_64 arm32 arm64 rv64 ppc32 ppc64 wasm32 ) - # Function to map processors to known architectures function( godot_arch_map ALIAS PROC ) string( TOLOWER "${PROC}" PROC ) @@ -147,7 +146,26 @@ function( godotcpp_options ) # Enable Testing option( GODOT_ENABLE_TESTING "Enable the godot-cpp.test. integration testing targets" OFF ) - + # Define which targets create for build. By default all targets are included + # Not presented in SCons + option(GODOT_ADD_TARGET_TEMPLATE_RELEASE "Add template_release target to build" ON) + option(GODOT_ADD_TARGET_TEMPLATE_DEBUG "Add template_debug target to build" ON) + option(GODOT_ADD_TARGET_EDITOR "Add editor target to build" ON) + if(GODOT_ADD_TARGET_TEMPLATE_DEBUG) + list(APPEND GODOT_TARGETS "template_debug") + endif() + if(GODOT_ADD_TARGET_TEMPLATE_RELEASE) + list(APPEND GODOT_TARGETS "template_release") + endif() + if(GODOT_ADD_TARGET_EDITOR) + list(APPEND GODOT_TARGETS "editor") + endif() + if(NOT GODOT_TARGETS) + message(FATAL_ERROR "No targets were chosen to be build.See GODOT_ADD_TARGET_* variables: at least one of the should be ON") + endif() + # parent scoping GODOT_TARGETS + set(GODOT_TARGETS ${GODOT_TARGETS} PARENT_SCOPE) + #[[ Target Platform Options ]] android_options() ios_options() @@ -276,7 +294,7 @@ function( godotcpp_generate ) set( DEV_TAG "$<${IS_DEV_BUILD}:.dev>" ) ### Define our godot-cpp library targets - foreach ( TARGET_ALIAS template_debug template_release editor ) + foreach ( TARGET_ALIAS ${GODOT_TARGETS} ) set( TARGET_NAME "godot-cpp.${TARGET_ALIAS}" ) # Generator Expressions that rely on the target @@ -342,6 +360,8 @@ function( godotcpp_generate ) # Added for backwards compatibility with prior cmake solution so that builds dont immediately break # from a missing target. - add_library( godot::cpp ALIAS godot-cpp.template_debug ) + # since targets can be turned off, we need to know which one is left (the order is 'template_debug' 'template_release' 'editor') + list(GET GODOT_TARGETS 0 GODOT_DEFAULT_TARGET) + add_library( godot::cpp ALIAS godot-cpp.${GODOT_DEFAULT_TARGET} ) endfunction() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 263de22b..56ba11de 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -16,7 +16,7 @@ file( GLOB_RECURSE DOC_XML set( DOC_DATA_SOURCE "${CMAKE_CURRENT_BINARY_DIR}/src/gen/doc_data.gen.cpp" ) generate_doc_source( "${DOC_DATA_SOURCE}" "${DOC_XML}" ) -foreach( TARGET_ALIAS template_debug template_release editor ) +foreach( TARGET_ALIAS ${GODOT_TARGETS} ) set( TARGET_NAME "godot-cpp.test.${TARGET_ALIAS}" ) set( LINK_TARGET "godot-cpp::${TARGET_ALIAS}" )