Skip to content

Commit

Permalink
Alleviate CMake target name clashes, visibility, and grouping.
Browse files Browse the repository at this point in the history
Simplify <platform>_generate cmake function signature, as TARGET_ALIAS and TARGET_NAME are still in scope and do not need to be passed.
  • Loading branch information
enetheru committed Nov 27, 2024
1 parent a42b363 commit a71699c
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 33 deletions.
11 changes: 9 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 honour the
# USE_FOLDERS flag will organise 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)
5 changes: 2 additions & 3 deletions cmake/android.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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( ${TARGET_ALIAS} )
endfunction()
6 changes: 3 additions & 3 deletions cmake/common_compiler_flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ set( HOT_RELOAD-UNSET "$<STREQUAL:${GODOT_USE_HOT_RELOAD},>")
set( DISABLE_EXCEPTIONS "$<BOOL:${GODOT_DISABLE_EXCEPTIONS}>")


function( common_compiler_flags TARGET_NAME )
set( IS_RELEASE "$<STREQUAL:${TARGET_NAME},template_release>")
set( DEBUG_FEATURES "$<OR:$<STREQUAL:${TARGET_NAME},template_debug>,$<STREQUAL:${TARGET_NAME},editor>>" )
function( common_compiler_flags )
set( IS_RELEASE "$<STREQUAL:${TARGET_ALIAS},template_release>")
set( DEBUG_FEATURES "$<OR:$<STREQUAL:${TARGET_ALIAS},template_debug>,$<STREQUAL:${TARGET_ALIAS},editor>>" )
set( HOT_RELOAD "$<IF:${HOT_RELOAD-UNSET},$<NOT:${IS_RELEASE}>,$<BOOL:${GODOT_USE_HOT_RELOAD}>>" )
set( DEBUG_SYMBOLS "$<BOOL:${GODOT_DEBUG_SYMBOLS}>" )

Expand Down
31 changes: 19 additions & 12 deletions cmake/godotcpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,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 for integration testing" 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.
Expand Down Expand Up @@ -231,17 +234,18 @@ 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 "$<STREQUAL:${TARGET_NAME},template_release>")
set( IS_RELEASE "$<STREQUAL:${TARGET_ALIAS},template_release>")
set( IS_DEV "$<BOOL:${GODOT_DEV_BUILD}>")
set( DEBUG_FEATURES "$<OR:$<STREQUAL:${TARGET_NAME},template_debug>,$<STREQUAL:${TARGET_NAME},editor>>" )
set( DEBUG_FEATURES "$<OR:$<STREQUAL:${TARGET_ALIAS},template_debug>,$<STREQUAL:${TARGET_ALIAS},editor>>" )
set( HOT_RELOAD "$<IF:${HOT_RELOAD-UNSET},$<NOT:${IS_RELEASE}>,$<BOOL:${GODOT_USE_HOT_RELOAD}>>" )

# the godot-cpp.* library targets
add_library( ${TARGET_NAME} STATIC ${EXCLUDE} )
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 )

Expand All @@ -268,27 +272,30 @@ 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}.${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 ()
Expand Down
5 changes: 2 additions & 3 deletions cmake/ios.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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(${TARGET_ALIAS})
endfunction()
5 changes: 2 additions & 3 deletions cmake/linux.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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( ${TARGET_ALIAS} )
endfunction()
4 changes: 2 additions & 2 deletions cmake/macos.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down Expand Up @@ -55,5 +55,5 @@ function( macos_generate TARGET_NAME )
${COCOA_LIBRARY}
)

common_compiler_flags( ${TARGET_NAME} )
common_compiler_flags( ${TARGET_ALIAS} )
endfunction()
5 changes: 2 additions & 3 deletions cmake/web.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ function( web_options )
endfunction()


function( web_generate TARGET_NAME )

function( web_generate )
target_compile_definitions(${TARGET_NAME}
PUBLIC
WEB_ENABLED
Expand All @@ -38,5 +37,5 @@ function( web_generate TARGET_NAME )
-shared
)

common_compiler_flags( ${TARGET_NAME} )
common_compiler_flags( ${TARGET_ALIAS} )
endfunction()
4 changes: 2 additions & 2 deletions cmake/windows.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function( windows_options )
# "use_mingw" "Use the MinGW compiler instead of MSVC - only effective on Windows"
endfunction()

function( windows_generate TARGET_NAME )
function( windows_generate )
set( IS_MSVC "$<CXX_COMPILER_ID:MSVC>" )
set( IS_CLANG "$<OR:$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:Clang>>" )
set( NOT_MSVC "$<NOT:${IS_MSVC}>" )
Expand Down Expand Up @@ -59,5 +59,5 @@ function( windows_generate TARGET_NAME )
$<${IS_CLANG}:-lstdc++>
)

common_compiler_flags( ${TARGET_NAME} )
common_compiler_flags( ${TARGET_ALIAS} )
endfunction()

0 comments on commit a71699c

Please sign in to comment.