Skip to content

Commit 39b2a22

Browse files
committed
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
1 parent a42b363 commit 39b2a22

File tree

10 files changed

+45
-35
lines changed

10 files changed

+45
-35
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ jobs:
225225
run: |
226226
mkdir cmake-build
227227
cd cmake-build
228-
cmake ../ -DTEST_TARGET=template_release
228+
cmake ../ -DENABLE_TESTING=YES -DTEST_TARGET=template_release
229229
cmake --build . --verbose -j $(nproc) -t godot-cpp-test --config Release
230230
231231
windows-msvc-cmake:
@@ -241,5 +241,5 @@ jobs:
241241
run: |
242242
mkdir cmake-build
243243
cd cmake-build
244-
cmake ../ -DTEST_TARGET=template_release
244+
cmake ../ -DENABLE_TESTING=YES -DTEST_TARGET=template_release
245245
cmake --build . --verbose -t godot-cpp-test --config Release

CMakeLists.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,12 @@ project( godot-cpp
9494

9595
godotcpp_generate()
9696

97-
# Test Example
98-
add_subdirectory( test )
97+
# optionally add the godot-cpp-test integration testing target
98+
if( GODOT_ENABLE_TESTING )
99+
add_subdirectory( test )
100+
endif()
101+
102+
# If this is the top level CMakeLists.txt, Generators which honor the
103+
# USE_FOLDERS flag will organize godot-cpp targets under the subfolder
104+
# 'godot-cpp'. This is enable by default from CMake version 3.26
105+
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

cmake/android.cmake

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,12 @@ function( android_options )
2929
# Android Options
3030
endfunction()
3131

32-
function( android_generate TARGET_NAME )
33-
32+
function( android_generate )
3433
target_compile_definitions(${TARGET_NAME}
3534
PUBLIC
3635
ANDROID_ENABLED
3736
UNIX_ENABLED
3837
)
3938

40-
common_compiler_flags( ${TARGET_NAME} )
39+
common_compiler_flags( ${TARGET_ALIAS} )
4140
endfunction()

cmake/common_compiler_flags.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ set( HOT_RELOAD-UNSET "$<STREQUAL:${GODOT_USE_HOT_RELOAD},>")
2525
set( DISABLE_EXCEPTIONS "$<BOOL:${GODOT_DISABLE_EXCEPTIONS}>")
2626

2727

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

cmake/godotcpp.cmake

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ function( godotcpp_options )
122122
option( GODOT_SYSTEM_HEADERS "Expose headers as SYSTEM." OFF )
123123
option( GODOT_WARNING_AS_ERROR "Treat warnings as errors" OFF )
124124

125+
# Enable Testing
126+
option( GODOT_ENABLE_TESTING "Enable the godot-cpp-test target for integration testing" OFF )
127+
125128
# Run options commands on the following to populate cache for all
126129
# platforms. This type of thing is typically done conditionally But as
127130
# scons shows all options so shall we.
@@ -231,17 +234,18 @@ function( godotcpp_generate )
231234
endif()
232235

233236
### Define our godot-cpp library targets
234-
foreach ( TARGET_NAME template_debug template_release editor )
237+
foreach ( TARGET_ALIAS template_debug template_release editor )
238+
set( TARGET_NAME "godot-cpp.${TARGET_ALIAS}" )
235239

236240
# Useful genex snippits used in subsequent genex's
237-
set( IS_RELEASE "$<STREQUAL:${TARGET_NAME},template_release>")
241+
set( IS_RELEASE "$<STREQUAL:${TARGET_ALIAS},template_release>")
238242
set( IS_DEV "$<BOOL:${GODOT_DEV_BUILD}>")
239-
set( DEBUG_FEATURES "$<OR:$<STREQUAL:${TARGET_NAME},template_debug>,$<STREQUAL:${TARGET_NAME},editor>>" )
243+
set( DEBUG_FEATURES "$<OR:$<STREQUAL:${TARGET_ALIAS},template_debug>,$<STREQUAL:${TARGET_ALIAS},editor>>" )
240244
set( HOT_RELOAD "$<IF:${HOT_RELOAD-UNSET},$<NOT:${IS_RELEASE}>,$<BOOL:${GODOT_USE_HOT_RELOAD}>>" )
241245

242246
# the godot-cpp.* library targets
243247
add_library( ${TARGET_NAME} STATIC ${EXCLUDE} )
244-
add_library( godot-cpp::${TARGET_NAME} ALIAS ${TARGET_NAME} )
248+
add_library( godot-cpp::${TARGET_ALIAS} ALIAS ${TARGET_NAME} )
245249

246250
file( GLOB_RECURSE GODOTCPP_SOURCES LIST_DIRECTORIES NO CONFIGURE_DEPENDS src/*.cpp )
247251

@@ -268,27 +272,30 @@ function( godotcpp_generate )
268272
BUILD_RPATH_USE_ORIGIN ON
269273

270274
PREFIX lib
271-
OUTPUT_NAME "${PROJECT_NAME}.${SYSTEM_NAME}.${TARGET_NAME}.${SYSTEM_ARCH}"
275+
OUTPUT_NAME "${PROJECT_NAME}.${SYSTEM_NAME}.${TARGET_ALIAS}.${SYSTEM_ARCH}"
272276
ARCHIVE_OUTPUT_DIRECTORY "$<1:${CMAKE_BINARY_DIR}/bin>"
273277

274278
# Things that are handy to know for dependent targets
275279
GODOT_PLATFORM "${SYSTEM_NAME}"
276-
GODOT_TARGET "${TARGET_NAME}"
280+
GODOT_TARGET "${TARGET_ALIAS}"
277281
GODOT_ARCH "${SYSTEM_ARCH}"
282+
283+
# Some IDE's respect this property to logically group targets
284+
FOLDER "godot-cpp"
278285
)
279286

280287
if( CMAKE_SYSTEM_NAME STREQUAL Android )
281-
android_generate( ${TARGET_NAME} )
288+
android_generate()
282289
elseif ( CMAKE_SYSTEM_NAME STREQUAL iOS )
283-
ios_generate( ${TARGET_NAME} )
290+
ios_generate()
284291
elseif ( CMAKE_SYSTEM_NAME STREQUAL Linux )
285-
linux_generate( ${TARGET_NAME} )
292+
linux_generate()
286293
elseif ( CMAKE_SYSTEM_NAME STREQUAL Darwin )
287-
macos_generate( ${TARGET_NAME} )
294+
macos_generate()
288295
elseif ( CMAKE_SYSTEM_NAME STREQUAL Emscripten )
289-
web_generate( ${TARGET_NAME} )
296+
web_generate()
290297
elseif ( CMAKE_SYSTEM_NAME STREQUAL Windows )
291-
windows_generate( ${TARGET_NAME} )
298+
windows_generate()
292299
endif ()
293300

294301
endforeach ()

cmake/ios.cmake

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@ function(ios_options)
1010
# iOS options
1111
endfunction()
1212

13-
function(ios_generate TARGET_NAME)
14-
13+
function(ios_generate)
1514
target_compile_definitions(${TARGET_NAME}
1615
PUBLIC
1716
IOS_ENABLED
1817
UNIX_ENABLED
1918
)
2019

21-
common_compiler_flags(${TARGET_NAME})
20+
common_compiler_flags(${TARGET_ALIAS})
2221
endfunction()

cmake/linux.cmake

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@ function( linux_options )
1010
# Linux Options
1111
endfunction()
1212

13-
function( linux_generate TARGET_NAME )
14-
13+
function( linux_generate )
1514
target_compile_definitions( ${TARGET_NAME}
1615
PUBLIC
1716
LINUX_ENABLED
1817
UNIX_ENABLED
1918
)
2019

21-
common_compiler_flags( ${TARGET_NAME} )
20+
common_compiler_flags( ${TARGET_ALIAS} )
2221
endfunction()

cmake/macos.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function( macos_options )
2323
endfunction()
2424

2525

26-
function( macos_generate TARGET_NAME )
26+
function( macos_generate )
2727

2828
# OSX_ARCHITECTURES does not support generator expressions.
2929
if( NOT GODOT_ARCH OR GODOT_ARCH STREQUAL universal )
@@ -55,5 +55,5 @@ function( macos_generate TARGET_NAME )
5555
${COCOA_LIBRARY}
5656
)
5757

58-
common_compiler_flags( ${TARGET_NAME} )
58+
common_compiler_flags( ${TARGET_ALIAS} )
5959
endfunction()

cmake/web.cmake

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ function( web_options )
1515
endfunction()
1616

1717

18-
function( web_generate TARGET_NAME )
19-
18+
function( web_generate )
2019
target_compile_definitions(${TARGET_NAME}
2120
PUBLIC
2221
WEB_ENABLED
@@ -38,5 +37,5 @@ function( web_generate TARGET_NAME )
3837
-shared
3938
)
4039

41-
common_compiler_flags( ${TARGET_NAME} )
40+
common_compiler_flags( ${TARGET_ALIAS} )
4241
endfunction()

cmake/windows.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function( windows_options )
1717
# "use_mingw" "Use the MinGW compiler instead of MSVC - only effective on Windows"
1818
endfunction()
1919

20-
function( windows_generate TARGET_NAME )
20+
function( windows_generate )
2121
set( IS_MSVC "$<CXX_COMPILER_ID:MSVC>" )
2222
set( IS_CLANG "$<OR:$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:Clang>>" )
2323
set( NOT_MSVC "$<NOT:${IS_MSVC}>" )
@@ -59,5 +59,5 @@ function( windows_generate TARGET_NAME )
5959
$<${IS_CLANG}:-lstdc++>
6060
)
6161

62-
common_compiler_flags( ${TARGET_NAME} )
62+
common_compiler_flags( ${TARGET_ALIAS} )
6363
endfunction()

0 commit comments

Comments
 (0)