Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Privatise and Tidy #1665

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ jobs:
run: |
mkdir cmake-build
cd cmake-build
cmake ../ -DTEST_TARGET=template_release
cmake --build . --verbose -j $(nproc) -t godot-cpp-test --config Release
cmake ../ -DGODOT_ENABLE_TESTING=YES
cmake --build . --verbose -j $(nproc) -t godot-cpp.test.template_release --config Release

windows-msvc-cmake:
name: 🏁 Build (Windows, MSVC, CMake)
Expand All @@ -218,5 +218,5 @@ jobs:
run: |
mkdir cmake-build
cd cmake-build
cmake ../ -DTEST_TARGET=template_release
cmake --build . --verbose -t godot-cpp-test --config Release
cmake ../ -DGODOT_ENABLE_TESTING=YES
cmake --build . --verbose -t godot-cpp.test.template_release --config Release
12 changes: 10 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ The CMake equivalent is below.
]=======================================================================]

include( cmake/godotcpp.cmake )

godotcpp_options()

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

# Test Example
add_subdirectory( test )
# Conditionally enable the godot-cpp.test.<target> integration testing targets
if( GODOT_ENABLE_TESTING )
add_subdirectory( test )
endif()

# If this is the top level CMakeLists.txt, Generators which honor the
# USE_FOLDERS flag will organize 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()
endfunction()
69 changes: 30 additions & 39 deletions cmake/common_compiler_flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ set( IS_GNU "$<CXX_COMPILER_ID:GNU>" )
set( IS_MSVC "$<CXX_COMPILER_ID:MSVC>" )
set( NOT_MSVC "$<NOT:$<CXX_COMPILER_ID:MSVC>>" )

set( GNU_LT_V8 "$<VERSION_LESS:$<CXX_COMPILER_VERSION>,8>" )
set( GNU_GE_V9 "$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,9>" )
set( GNU_GT_V11 "$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,11>" )
set( GNU_LT_V11 "$<VERSION_LESS:$<CXX_COMPILER_VERSION>,11>" )
set( GNU_GE_V12 "$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,12>" )
set( LT_V8 "$<VERSION_LESS:$<CXX_COMPILER_VERSION>,8>" )
set( GE_V9 "$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,9>" )
set( GT_V11 "$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,11>" )
set( LT_V11 "$<VERSION_LESS:$<CXX_COMPILER_VERSION>,11>" )
set( GE_V12 "$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,12>" )

#[[ Check for clang-cl with MSVC frontend
The compiler is tested and set when the project command is called.
Expand All @@ -44,21 +44,16 @@ function( compiler_detection )
endif ()
endfunction( )

function( common_compiler_flags TARGET_NAME )

target_compile_features(${TARGET_NAME}
PUBLIC
cxx_std_17
)
function( common_compiler_flags )

# These compiler options reflect what is in godot/SConstruct.
target_compile_options( ${TARGET_NAME}
# The public flag tells CMake that the following options are transient,
#and will propagate to consumers.
PUBLIC
# Disable exception handling. Godot doesn't use exceptions anywhere, and this
# saves around 20% of binary size and very significant build time.
$<${DISABLE_EXCEPTIONS}:
$<${NOT_MSVC}:-fno-exceptions>
>
$<${DISABLE_EXCEPTIONS}:$<${NOT_MSVC}:-fno-exceptions>>

# Enabling Debug Symbols
$<${DEBUG_SYMBOLS}:
Expand All @@ -70,20 +65,19 @@ function( common_compiler_flags TARGET_NAME )
>
>

$<${IS_DEV_BUILD}:
$<${NOT_MSVC}:-fno-omit-frame-pointer -O0>
>
$<${IS_DEV_BUILD}:$<${NOT_MSVC}:-fno-omit-frame-pointer -O0>>

$<${HOT_RELOAD}:
$<${IS_GNU}:-fno-gnu-unique>
>
$<${HOT_RELOAD}:$<${IS_GNU}:-fno-gnu-unique>>

# Warnings below, these do not need to propagate to consumers.
PRIVATE

# MSVC only
$<${IS_MSVC}:
# /MP isn't valid for clang-cl with msvc frontend
$<$<CXX_COMPILER_ID:MSVC>:/MP${PROC_N}>
/W4

/W4 # Warning level 4 (informational) warnings that aren't off by default.
# Disable warnings which we don't plan to fix.
/wd4100 # C4100 (unreferenced formal parameter): Doesn't play nice with polymorphism.
/wd4127 # C4127 (conditional expression is constant)
Expand All @@ -95,8 +89,6 @@ function( common_compiler_flags TARGET_NAME )
/wd4514 # C4514 (unreferenced inline function has been removed)
/wd4714 # C4714 (function marked as __forceinline not inlined)
/wd4820 # C4820 (padding added after construct)

/utf-8
>

# Clang and GNU common options
Expand Down Expand Up @@ -124,21 +116,22 @@ function( common_compiler_flags TARGET_NAME )
-Wplacement-new=1
-Wshadow-local
-Wstringop-overflow=4
>

# Bogus warning fixed in 8+.
$<${GNU_LT_V8}:-Wno-strict-overflow>
# Bogus warning fixed in 8+.
$<${IS_GNU}:$<${LT_V8}:-Wno-strict-overflow>>

$<${GNU_GE_V9}:-Wattribute-alias=2>
$<${IS_GNU}:$<${GE_V9}:-Wattribute-alias=2>>

# Broke on MethodBind templates before GCC 11.
$<${GNU_GT_V11}:-Wlogical-op>
# Broke on MethodBind templates before GCC 11.
$<${IS_GNU}:$<${GT_V11}:-Wlogical-op>>

# Regression in GCC 9/10, spams so much in our variadic templates that we need to outright disable it.
$<${GNU_LT_V11}:-Wno-type-limits>
# Regression in GCC 9/10, spams so much in our variadic templates that we need to outright disable it.
$<${IS_GNU}:$<${LT_V11}:-Wno-type-limits>>

# False positives in our error macros, see GH-58747.
$<${IS_GNU}:$<${GE_V12}:-Wno-return-type>>

# False positives in our error macros, see GH-58747.
$<${GNU_GE_V12}:-Wno-return-type>
>
)

target_compile_definitions(${TARGET_NAME}
Expand All @@ -158,13 +151,11 @@ function( common_compiler_flags TARGET_NAME )
)

target_link_options( ${TARGET_NAME}
PUBLIC
$<${IS_MSVC}:
/WX # treat link warnings as errors.
/MANIFEST:NO # We dont need a manifest
>
PRIVATE
$<${IS_MSVC}:/WX /MANIFEST:NO>
# /WX # treat link warnings as errors.
# /MANIFEST:NO # We dont need a manifest

$<${DEBUG_SYMBOLS}:$<${IS_MSVC}:/DEBUG:FULL>>
$<$<NOT:${DEBUG_SYMBOLS}>:
$<${IS_GNU}:-s>
$<${IS_CLANG}:-s>
Expand Down
53 changes: 25 additions & 28 deletions cmake/godotcpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,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> integration testing targets" OFF )

#[[ Target Platform Options ]]
android_options()
ios_options()
Expand Down Expand Up @@ -190,32 +193,21 @@ function( godotcpp_generate )
set(GODOT_SYSTEM_HEADERS_ATTRIBUTE SYSTEM)
endif ()

#[[ Generate Bindings ]]
if(NOT DEFINED BITS)
set(BITS 32)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(BITS 64)
endif(CMAKE_SIZEOF_VOID_P EQUAL 8)
endif()

#[[ Configure Binding Variables ]]
set(GODOT_GDEXTENSION_API_FILE "${GODOT_GDEXTENSION_DIR}/extension_api.json")
if (NOT "${GODOT_CUSTOM_API_FILE}" STREQUAL "") # User-defined override.
if( GODOT_CUSTOM_API_FILE ) # User-defined override.
set(GODOT_GDEXTENSION_API_FILE "${GODOT_CUSTOM_API_FILE}")
endif()

# Code Generation option
if(GODOT_GENERATE_TEMPLATE_GET_NODE)
set(GENERATE_BINDING_PARAMETERS "True")
else()
set(GENERATE_BINDING_PARAMETERS "False")
endif()
set( GENERATE_BINDING_PARAMETERS "$<IF:$<BOOL:${GODOT_GENERATE_TEMPLATE_GET_NODE}>,True,False>" )
math( EXPR BITS "${CMAKE_SIZEOF_VOID_P} * 8" )

execute_process(COMMAND "${Python3_EXECUTABLE}" "-c" "import binding_generator; binding_generator.print_file_list('${GODOT_GDEXTENSION_API_FILE}', '${CMAKE_CURRENT_BINARY_DIR}', headers=True, sources=True)"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE GENERATED_FILES_LIST
OUTPUT_STRIP_TRAILING_WHITESPACE
)

add_custom_command(OUTPUT ${GENERATED_FILES_LIST}
COMMAND "${Python3_EXECUTABLE}" "-c" "import binding_generator; binding_generator.generate_bindings('${GODOT_GDEXTENSION_API_FILE}', '${GENERATE_BINDING_PARAMETERS}', '${BITS}', '${GODOT_PRECISION}', '${CMAKE_CURRENT_BINARY_DIR}')"
VERBATIM
Expand Down Expand Up @@ -263,15 +255,16 @@ function( godotcpp_generate )
set( DEV_TAG "$<${IS_DEV_BUILD}:.dev>" )

### 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}" )

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

# the godot-cpp.* library targets
add_library( ${TARGET_NAME} STATIC EXCLUDE_FROM_ALL )
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 @@ -294,37 +287,41 @@ function( godotcpp_generate )
CXX_VISIBILITY_PRESET ${GODOT_SYMBOL_VISIBILITY}

COMPILE_WARNING_AS_ERROR ${GODOT_WARNING_AS_ERROR}

POSITION_INDEPENDENT_CODE ON
BUILD_RPATH_USE_ORIGIN ON
INTERFACE_POSITION_INDEPENDENT_CODE ON

PREFIX lib
OUTPUT_NAME "${PROJECT_NAME}.${SYSTEM_NAME}.${TARGET_NAME}${DEV_TAG}.${SYSTEM_ARCH}"
OUTPUT_NAME "${PROJECT_NAME}.${SYSTEM_NAME}.${TARGET_ALIAS}${DEV_TAG}.${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 ()

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

endfunction()
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()
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()
endfunction()
6 changes: 4 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 All @@ -36,7 +36,9 @@ function( macos_generate TARGET_NAME )
set_target_properties( ${TARGET_NAME}
PROPERTIES

# Specify multiple architectures for universal builds
OSX_ARCHITECTURES "${OSX_ARCH}"
GODOT_ARCH ${SYSTEM_ARCH}
)

target_compile_definitions(${TARGET_NAME}
Expand All @@ -55,5 +57,5 @@ function( macos_generate TARGET_NAME )
${COCOA_LIBRARY}
)

common_compiler_flags( ${TARGET_NAME} )
common_compiler_flags()
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()
endfunction()
4 changes: 2 additions & 2 deletions cmake/windows.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function( windows_options )
endfunction()

#[===========================[ Target Generation ]===========================]
function( windows_generate TARGET_NAME )
function( windows_generate )
set( STATIC_CPP "$<BOOL:${GODOT_USE_STATIC_CPP}>")
set( DEBUG_CRT "$<BOOL:${GODOT_DEBUG_CRT}>" )

Expand Down Expand Up @@ -96,5 +96,5 @@ function( windows_generate TARGET_NAME )
$<${IS_CLANG}:-lstdc++>
)

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