Skip to content

Commit 89d9038

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 ce66e6b commit 89d9038

File tree

9 files changed

+40
-30
lines changed

9 files changed

+40
-30
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 ../ -DGODOT_ENABLE_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 ../ -DGODOT_ENABLE_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
@@ -52,5 +52,12 @@ project( godot-cpp
5252

5353
godotcpp_generate()
5454

55-
# Test Example
56-
add_subdirectory( test )
55+
# optionally add the godot-cpp-test integration testing target
56+
if( GODOT_ENABLE_TESTING )
57+
add_subdirectory( test )
58+
endif()
59+
60+
# If this is the top level CMakeLists.txt, Generators which honor the
61+
# USE_FOLDERS flag will organize godot-cpp targets under the subfolder
62+
# 'godot-cpp'. This is enable by default from CMake version 3.26
63+
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()
4140
endfunction()

cmake/godotcpp.cmake

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ function( godotcpp_options )
142142
option( GODOT_SYSTEM_HEADERS "Expose headers as SYSTEM." OFF )
143143
option( GODOT_WARNING_AS_ERROR "Treat warnings as errors" OFF )
144144

145+
# Enable Testing
146+
option( GODOT_ENABLE_TESTING "Enable the godot-cpp-test target for integration testing" OFF )
147+
145148
#[[ Target Platform Options ]]
146149
android_options()
147150
ios_options()
@@ -263,15 +266,16 @@ function( godotcpp_generate )
263266
set( DEV_TAG "$<${IS_DEV_BUILD}:.dev>" )
264267

265268
### Define our godot-cpp library targets
266-
foreach ( TARGET_NAME template_debug template_release editor )
269+
foreach ( TARGET_ALIAS template_debug template_release editor )
270+
set( TARGET_NAME "godot-cpp.${TARGET_ALIAS}" )
267271

268272
# Generator Expressions that rely on the target
269273
set( DEBUG_FEATURES "$<NOT:$<STREQUAL:${TARGET_NAME},template_release>>" )
270274
set( HOT_RELOAD "$<IF:${HOT_RELOAD-UNSET},${DEBUG_FEATURES},$<BOOL:${GODOT_USE_HOT_RELOAD}>>" )
271275

272276
# the godot-cpp.* library targets
273277
add_library( ${TARGET_NAME} STATIC EXCLUDE_FROM_ALL )
274-
add_library( godot-cpp::${TARGET_NAME} ALIAS ${TARGET_NAME} )
278+
add_library( godot-cpp::${TARGET_ALIAS} ALIAS ${TARGET_NAME} )
275279

276280
file( GLOB_RECURSE GODOTCPP_SOURCES LIST_DIRECTORIES NO CONFIGURE_DEPENDS src/*.cpp )
277281

@@ -298,33 +302,36 @@ function( godotcpp_generate )
298302
BUILD_RPATH_USE_ORIGIN ON
299303

300304
PREFIX lib
301-
OUTPUT_NAME "${PROJECT_NAME}.${SYSTEM_NAME}.${TARGET_NAME}${DEV_TAG}.${SYSTEM_ARCH}"
305+
OUTPUT_NAME "${PROJECT_NAME}.${SYSTEM_NAME}.${TARGET_ALIAS}${DEV_TAG}.${SYSTEM_ARCH}"
302306
ARCHIVE_OUTPUT_DIRECTORY "$<1:${CMAKE_BINARY_DIR}/bin>"
303307

304308
# Things that are handy to know for dependent targets
305309
GODOT_PLATFORM "${SYSTEM_NAME}"
306-
GODOT_TARGET "${TARGET_NAME}"
310+
GODOT_TARGET "${TARGET_ALIAS}"
307311
GODOT_ARCH "${SYSTEM_ARCH}"
312+
313+
# Some IDE's respect this property to logically group targets
314+
FOLDER "godot-cpp"
308315
)
309316

310317
if( CMAKE_SYSTEM_NAME STREQUAL Android )
311-
android_generate( ${TARGET_NAME} )
318+
android_generate()
312319
elseif ( CMAKE_SYSTEM_NAME STREQUAL iOS )
313-
ios_generate( ${TARGET_NAME} )
320+
ios_generate()
314321
elseif ( CMAKE_SYSTEM_NAME STREQUAL Linux )
315-
linux_generate( ${TARGET_NAME} )
322+
linux_generate()
316323
elseif ( CMAKE_SYSTEM_NAME STREQUAL Darwin )
317-
macos_generate( ${TARGET_NAME} )
324+
macos_generate()
318325
elseif ( CMAKE_SYSTEM_NAME STREQUAL Emscripten )
319-
web_generate( ${TARGET_NAME} )
326+
web_generate()
320327
elseif ( CMAKE_SYSTEM_NAME STREQUAL Windows )
321-
windows_generate( ${TARGET_NAME} )
328+
windows_generate()
322329
endif ()
323330

324331
endforeach ()
325332

326333
# Added for backwards compatibility with prior cmake solution so that builds dont immediately break
327334
# from a missing target.
328-
add_library( godot::cpp ALIAS template_debug )
335+
add_library( godot::cpp ALIAS godot-cpp.template_debug )
329336

330337
endfunction()

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()
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()
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()
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()
4241
endfunction()

cmake/windows.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,5 @@ function( windows_generate TARGET_NAME )
9696
$<${IS_CLANG}:-lstdc++>
9797
)
9898

99-
common_compiler_flags( ${TARGET_NAME} )
99+
common_compiler_flags()
100100
endfunction()

0 commit comments

Comments
 (0)