Skip to content

Commit 012b8ff

Browse files
authored
Merge pull request #1658 from enetheru/name_clash
CMake: Alleviate target name clashes, visibility, and grouping.
2 parents 7d3870b + 6f7293c commit 012b8ff

File tree

12 files changed

+191
-135
lines changed

12 files changed

+191
-135
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ jobs:
202202
run: |
203203
mkdir cmake-build
204204
cd cmake-build
205-
cmake ../ -DTEST_TARGET=template_release
206-
cmake --build . --verbose -j $(nproc) -t godot-cpp-test --config Release
205+
cmake ../ -DGODOT_ENABLE_TESTING=YES
206+
cmake --build . --verbose -j $(nproc) -t godot-cpp.test.template_release --config Release
207207
208208
windows-msvc-cmake:
209209
name: 🏁 Build (Windows, MSVC, CMake)
@@ -218,5 +218,5 @@ jobs:
218218
run: |
219219
mkdir cmake-build
220220
cd cmake-build
221-
cmake ../ -DTEST_TARGET=template_release
222-
cmake --build . --verbose -t godot-cpp-test --config Release
221+
cmake ../ -DGODOT_ENABLE_TESTING=YES
222+
cmake --build . --verbose -t godot-cpp.test.template_release --config Release

CMakeLists.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ The CMake equivalent is below.
3838
]=======================================================================]
3939

4040
include( cmake/godotcpp.cmake )
41+
4142
godotcpp_options()
4243

4344
#[[ Python is required for code generation ]]
@@ -53,5 +54,12 @@ project( godot-cpp
5354
compiler_detection()
5455
godotcpp_generate()
5556

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function( compiler_detection )
4444
endif ()
4545
endfunction( )
4646

47-
function( common_compiler_flags TARGET_NAME )
47+
function( common_compiler_flags )
4848

4949
target_compile_features(${TARGET_NAME}
5050
PUBLIC

cmake/godotcpp.cmake

Lines changed: 19 additions & 12 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> integration testing targets" OFF )
147+
145148
#[[ Target Platform Options ]]
146149
android_options()
147150
ios_options()
@@ -228,7 +231,7 @@ function( godotcpp_generate )
228231
### Platform is derived from the toolchain target
229232
# See GeneratorExpressions PLATFORM_ID and CMAKE_SYSTEM_NAME
230233
set( SYSTEM_NAME
231-
$<$<PLATFORM_ID:Android>:android.${ANDROID_ABI}>
234+
$<$<PLATFORM_ID:Android>:android>
232235
$<$<PLATFORM_ID:iOS>:ios>
233236
$<$<PLATFORM_ID:Linux>:linux>
234237
$<$<PLATFORM_ID:Darwin>:macos>
@@ -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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function( windows_options )
5858
endfunction()
5959

6060
#[===========================[ Target Generation ]===========================]
61-
function( windows_generate TARGET_NAME )
61+
function( windows_generate )
6262
set( STATIC_CPP "$<BOOL:${GODOT_USE_STATIC_CPP}>")
6363
set( DEBUG_CRT "$<BOOL:${GODOT_DEBUG_CRT}>" )
6464

@@ -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)