Skip to content

Commit 9f02db1

Browse files
authored
Merge pull request godotengine#1733 from enetheru/single_target_test
CMake: Revert to single cmake target
2 parents 0b6350d + 89abe15 commit 9f02db1

File tree

11 files changed

+225
-255
lines changed

11 files changed

+225
-255
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 ../ -DGODOTCPP_ENABLE_TESTING=YES
206-
cmake --build . --verbose -j $(nproc) -t godot-cpp.test.template_release --config Release
205+
cmake ../ -DGODOTCPP_ENABLE_TESTING=YES -DGODOTCPP_TARGET=template_release
206+
cmake --build . --verbose -j $(nproc) --target godot-cpp-test --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 ../ -DGODOTCPP_ENABLE_TESTING=YES
222-
cmake --build . --verbose -t godot-cpp.test.template_release --config Release
221+
cmake ../ -DGODOTCPP_ENABLE_TESTING=YES -DGODOTCPP_TARGET=template_release
222+
cmake --build . --verbose --target godot-cpp-test --config Release

cmake/android.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ endfunction()
4343

4444
#[===========================[ Target Generation ]===========================]
4545
function(android_generate)
46-
target_compile_definitions(${TARGET_NAME} PUBLIC ANDROID_ENABLED UNIX_ENABLED)
46+
target_compile_definitions(godot-cpp PUBLIC ANDROID_ENABLED UNIX_ENABLED)
4747

4848
common_compiler_flags()
4949
endfunction()

cmake/common_compiler_flags.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function(common_compiler_flags)
6262
# gersemi: off
6363
# These compiler options reflect what is in godot/SConstruct.
6464
target_compile_options(
65-
${TARGET_NAME}
65+
godot-cpp
6666
PUBLIC
6767
# Disable exception handling. Godot doesn't use exceptions anywhere, and this
6868
# saves around 20% of binary size and very significant build time.
@@ -146,7 +146,7 @@ function(common_compiler_flags)
146146
)
147147

148148
target_compile_definitions(
149-
${TARGET_NAME}
149+
godot-cpp
150150
PUBLIC
151151
GDEXTENSION
152152

@@ -165,7 +165,7 @@ function(common_compiler_flags)
165165
)
166166

167167
target_link_options(
168-
${TARGET_NAME}
168+
godot-cpp
169169
PUBLIC
170170
$<${IS_MSVC}:
171171
/WX # treat link warnings as errors.

cmake/godotcpp.cmake

Lines changed: 70 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ function(godotcpp_options)
106106
#NOTE: arch is managed by using toolchain files.
107107
# To create a universal build for macos, set CMAKE_OSX_ARCHITECTURES
108108

109+
set(GODOTCPP_TARGET
110+
"template_debug"
111+
CACHE STRING
112+
"Which target to generate. valid values are: template_debug, template_release, and editor"
113+
)
114+
set_property(CACHE GODOTCPP_TARGET PROPERTY STRINGS "template_debug;template_release;editor")
115+
109116
# Input from user for GDExtension interface header and the API JSON file
110117
set(GODOTCPP_GDEXTENSION_DIR
111118
"gdextension"
@@ -305,94 +312,79 @@ function(godotcpp_generate)
305312
set(IS_DEV_BUILD "$<BOOL:${GODOTCPP_DEV_BUILD}>")
306313

307314
### Define our godot-cpp library targets
308-
foreach(TARGET_ALIAS template_debug template_release editor)
309-
set(TARGET_NAME "godot-cpp.${TARGET_ALIAS}")
310-
311-
# Generator Expressions that rely on the target
312-
set(DEBUG_FEATURES "$<NOT:$<STREQUAL:${TARGET_ALIAS},template_release>>")
313-
set(HOT_RELOAD "$<IF:${HOT_RELOAD-UNSET},${DEBUG_FEATURES},$<BOOL:${GODOTCPP_USE_HOT_RELOAD}>>")
314-
315-
# Suffix
316-
string(
317-
CONCAT
318-
GODOTCPP_SUFFIX
319-
"$<1:.${SYSTEM_NAME}>"
320-
"$<1:.${TARGET_ALIAS}>"
321-
"$<${IS_DEV_BUILD}:.dev>"
322-
"$<$<STREQUAL:${GODOTCPP_PRECISION},double>:.double>"
323-
"$<1:.${ARCH_NAME}>"
324-
# TODO IOS_SIMULATOR
325-
"$<$<NOT:${THREADS_ENABLED}>:.nothreads>"
326-
)
327-
328-
# People are compiling godot by itself.
329-
set(EXCLUDE EXCLUDE_FROM_ALL)
330-
if(GODOTCPP_IS_TOP_LEVEL)
331-
if(TARGET_ALIAS STREQUAL template_debug)
332-
set(EXCLUDE "")
333-
endif()
334-
endif()
315+
# Generator Expressions that rely on the target
316+
set(DEBUG_FEATURES "$<NOT:$<STREQUAL:${GODOTCPP_TARGET},template_release>>")
317+
set(HOT_RELOAD "$<IF:${HOT_RELOAD-UNSET},${DEBUG_FEATURES},$<BOOL:${GODOTCPP_USE_HOT_RELOAD}>>")
335318

336-
# the godot-cpp.* library targets
337-
add_library(${TARGET_NAME} STATIC ${EXCLUDE})
319+
# Suffix
320+
string(
321+
CONCAT
322+
GODOTCPP_SUFFIX
323+
"$<1:.${SYSTEM_NAME}>"
324+
"$<1:.${GODOTCPP_TARGET}>"
325+
"$<${IS_DEV_BUILD}:.dev>"
326+
"$<$<STREQUAL:${GODOTCPP_PRECISION},double>:.double>"
327+
"$<1:.${ARCH_NAME}>"
328+
# TODO IOS_SIMULATOR
329+
"$<$<NOT:${THREADS_ENABLED}>:.nothreads>"
330+
)
338331

339-
add_library(godot-cpp::${TARGET_ALIAS} ALIAS ${TARGET_NAME})
332+
# the godot-cpp.* library targets
333+
add_library(godot-cpp STATIC)
340334

341-
file(GLOB_RECURSE GODOTCPP_SOURCES LIST_DIRECTORIES NO CONFIGURE_DEPENDS src/*.cpp)
335+
# Added for backwards compatibility with prior cmake solution so that builds dont immediately break
336+
# from a missing target.
337+
add_library(godot::cpp ALIAS godot-cpp)
342338

343-
target_sources(${TARGET_NAME} PRIVATE ${GODOTCPP_SOURCES} ${GENERATED_FILES_LIST})
339+
file(GLOB_RECURSE GODOTCPP_SOURCES LIST_DIRECTORIES NO CONFIGURE_DEPENDS src/*.cpp)
344340

345-
target_include_directories(
346-
${TARGET_NAME}
347-
${GODOTCPP_SYSTEM_HEADERS_ATTRIBUTE}
348-
PUBLIC include ${CMAKE_CURRENT_BINARY_DIR}/gen/include ${GODOTCPP_GDEXTENSION_DIR}
349-
)
341+
target_sources(godot-cpp PRIVATE ${GODOTCPP_SOURCES} ${GENERATED_FILES_LIST})
350342

351-
# gersemi: off
352-
set_target_properties(
353-
${TARGET_NAME}
354-
PROPERTIES
355-
CXX_STANDARD 17
356-
CXX_EXTENSIONS OFF
357-
CXX_VISIBILITY_PRESET ${GODOTCPP_SYMBOL_VISIBILITY}
343+
target_include_directories(
344+
godot-cpp
345+
${GODOTCPP_SYSTEM_HEADERS_ATTRIBUTE}
346+
PUBLIC include ${CMAKE_CURRENT_BINARY_DIR}/gen/include ${GODOTCPP_GDEXTENSION_DIR}
347+
)
358348

359-
COMPILE_WARNING_AS_ERROR ${GODOTCPP_WARNING_AS_ERROR}
360-
POSITION_INDEPENDENT_CODE ON
361-
BUILD_RPATH_USE_ORIGIN ON
349+
# gersemi: off
350+
set_target_properties(
351+
godot-cpp
352+
PROPERTIES
353+
CXX_STANDARD 17
354+
CXX_EXTENSIONS OFF
355+
CXX_VISIBILITY_PRESET ${GODOTCPP_SYMBOL_VISIBILITY}
362356

363-
PREFIX "lib"
364-
OUTPUT_NAME "${PROJECT_NAME}${GODOTCPP_SUFFIX}"
357+
COMPILE_WARNING_AS_ERROR ${GODOTCPP_WARNING_AS_ERROR}
358+
POSITION_INDEPENDENT_CODE ON
359+
BUILD_RPATH_USE_ORIGIN ON
365360

366-
ARCHIVE_OUTPUT_DIRECTORY "$<1:${CMAKE_BINARY_DIR}/bin>"
361+
PREFIX "lib"
362+
OUTPUT_NAME "${PROJECT_NAME}${GODOTCPP_SUFFIX}"
367363

368-
# Things that are handy to know for dependent targets
369-
GODOTCPP_PLATFORM "${SYSTEM_NAME}"
370-
GODOTCPP_TARGET "${TARGET_ALIAS}"
371-
GODOTCPP_ARCH "${ARCH_NAME}"
372-
GODOTCPP_PRECISION "${GODOTCPP_PRECISION}"
373-
GODOTCPP_SUFFIX "${GODOTCPP_SUFFIX}"
364+
ARCHIVE_OUTPUT_DIRECTORY "$<1:${CMAKE_BINARY_DIR}/bin>"
374365

375-
# Some IDE's respect this property to logically group targets
376-
FOLDER "godot-cpp"
377-
)
378-
# gersemi: on
379-
380-
if(CMAKE_SYSTEM_NAME STREQUAL Android)
381-
android_generate()
382-
elseif(CMAKE_SYSTEM_NAME STREQUAL iOS)
383-
ios_generate()
384-
elseif(CMAKE_SYSTEM_NAME STREQUAL Linux)
385-
linux_generate()
386-
elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
387-
macos_generate()
388-
elseif(CMAKE_SYSTEM_NAME STREQUAL Emscripten)
389-
web_generate()
390-
elseif(CMAKE_SYSTEM_NAME STREQUAL Windows)
391-
windows_generate()
392-
endif()
393-
endforeach()
366+
# Things that are handy to know for dependent targets
367+
GODOTCPP_PLATFORM "${SYSTEM_NAME}"
368+
GODOTCPP_TARGET "${GODOTCPP_TARGET}"
369+
GODOTCPP_ARCH "${ARCH_NAME}"
370+
GODOTCPP_PRECISION "${GODOTCPP_PRECISION}"
371+
GODOTCPP_SUFFIX "${GODOTCPP_SUFFIX}"
394372

395-
# Added for backwards compatibility with prior cmake solution so that builds dont immediately break
396-
# from a missing target.
397-
add_library(godot::cpp ALIAS godot-cpp.template_debug)
373+
# Some IDE's respect this property to logically group targets
374+
FOLDER "godot-cpp"
375+
)
376+
# gersemi: on
377+
if(CMAKE_SYSTEM_NAME STREQUAL Android)
378+
android_generate()
379+
elseif(CMAKE_SYSTEM_NAME STREQUAL iOS)
380+
ios_generate()
381+
elseif(CMAKE_SYSTEM_NAME STREQUAL Linux)
382+
linux_generate()
383+
elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
384+
macos_generate()
385+
elseif(CMAKE_SYSTEM_NAME STREQUAL Emscripten)
386+
web_generate()
387+
elseif(CMAKE_SYSTEM_NAME STREQUAL Windows)
388+
windows_generate()
389+
endif()
398390
endfunction()

cmake/ios.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ endfunction()
3030

3131
#[===========================[ Target Generation ]===========================]
3232
function(ios_generate)
33-
target_compile_definitions(${TARGET_NAME} PUBLIC IOS_ENABLED UNIX_ENABLED)
33+
target_compile_definitions(godot-cpp PUBLIC IOS_ENABLED UNIX_ENABLED)
3434

3535
common_compiler_flags()
3636
endfunction()

cmake/linux.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ endfunction()
1818

1919
#[===========================[ Target Generation ]===========================]
2020
function(linux_generate)
21-
target_compile_definitions(${TARGET_NAME} PUBLIC LINUX_ENABLED UNIX_ENABLED)
21+
target_compile_definitions(godot-cpp PUBLIC LINUX_ENABLED UNIX_ENABLED)
2222

2323
common_compiler_flags()
2424
endfunction()

cmake/macos.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ endfunction()
4343

4444
#[===========================[ Target Generation ]===========================]
4545
function(macos_generate)
46-
target_compile_definitions(${TARGET_NAME} PUBLIC MACOS_ENABLED UNIX_ENABLED)
46+
target_compile_definitions(godot-cpp PUBLIC MACOS_ENABLED UNIX_ENABLED)
4747

48-
target_link_options(${TARGET_NAME} PUBLIC -Wl,-undefined,dynamic_lookup)
48+
target_link_options(godot-cpp PUBLIC -Wl,-undefined,dynamic_lookup)
4949

50-
target_link_libraries(${TARGET_NAME} INTERFACE ${COCOA_LIBRARY})
50+
target_link_libraries(godot-cpp INTERFACE ${COCOA_LIBRARY})
5151

5252
common_compiler_flags()
5353
endfunction()

cmake/web.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ endfunction()
1616

1717
#[===========================[ Target Generation ]===========================]
1818
function(web_generate)
19-
target_compile_definitions(${TARGET_NAME} PUBLIC WEB_ENABLED UNIX_ENABLED)
19+
target_compile_definitions(godot-cpp PUBLIC WEB_ENABLED UNIX_ENABLED)
2020

2121
target_compile_options(
22-
${TARGET_NAME}
22+
godot-cpp
2323
PUBLIC #
2424
-sSIDE_MODULE
2525
-sSUPPORT_LONGJMP=wasm
2626
$<${THREADS_ENABLED}:-sUSE_PTHREADS=1>
2727
)
2828

2929
target_link_options(
30-
${TARGET_NAME}
30+
godot-cpp
3131
INTERFACE #
3232
-sWASM_BIGINT
3333
-sSUPPORT_LONGJMP=wasm

cmake/windows.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,16 @@ endfunction()
8888
function(windows_generate)
8989
set(STATIC_CPP "$<BOOL:${GODOTCPP_USE_STATIC_CPP}>")
9090

91-
set_target_properties(${TARGET_NAME} PROPERTIES PDB_OUTPUT_DIRECTORY "$<1:${CMAKE_SOURCE_DIR}/bin>")
91+
set_target_properties(godot-cpp PROPERTIES PDB_OUTPUT_DIRECTORY "$<1:${CMAKE_SOURCE_DIR}/bin>")
9292

9393
target_compile_definitions(
94-
${TARGET_NAME}
94+
godot-cpp
9595
PUBLIC WINDOWS_ENABLED $<${IS_MSVC}: TYPED_METHOD_BIND NOMINMAX >
9696
)
9797

9898
# gersemi: off
9999
target_link_options(
100-
${TARGET_NAME}
100+
godot-cpp
101101
PUBLIC
102102
$<${NOT_MSVC}:
103103
-Wl,--no-undefined

0 commit comments

Comments
 (0)