2023-12-31 16:17:28 +00:00
# This file contains variables needed by all platforms
### Options
2024-01-09 21:35:20 +00:00
set ( CONFIGS_WITH_DEBUG "Debug;RelWithDebInfo" CACHE STRING "Configurations that should have debug symbols (Modify if support for custom configurations is needed)" )
2023-12-31 16:17:28 +00:00
2024-01-09 21:35:20 +00:00
# Default config
2023-12-31 16:17:28 +00:00
if ( "${CMAKE_BUILD_TYPE}" STREQUAL "" )
2024-01-09 21:35:20 +00:00
set ( CMAKE_BUILD_TYPE "Debug" )
2023-12-31 16:17:28 +00:00
endif ( )
2024-01-09 21:35:20 +00:00
set ( TARGET "TEMPLATE_DEBUG" CACHE STRING "Target platform (EDITOR, TEMPLATE_DEBUG, TEMPLATE_RELEASE)" )
2023-12-31 16:17:28 +00:00
# Auto-detect platform
if ( CMAKE_SYSTEM_NAME STREQUAL "Linux" )
set ( DEFAULT_PLATFORM "LINUX" )
elseif ( CMAKE_SYSTEM_NAME STREQUAL "Windows" )
set ( DEFAULT_PLATFORM "WINDOWS" )
elseif ( CMAKE_SYSTEM_NAME STREQUAL "Darwin" )
set ( DEFAULT_PLATFORM "MACOS" )
elseif ( CMAKE_SYSTEM_NAME STREQUAL "Emscripten" ) # Set by providing Emscripten toolchain
set ( DEFAULT_PLATFORM "WEB" )
elseif ( CMAKE_SYSTEM_NAME STREQUAL "Android" ) # Set by providing Android toolchain
set ( DEFAULT_PLATFORM "ANDROID" )
else ( )
message ( FATAL_ERROR "Could not auto-detect platform for \" ${ CMAKE_SYSTEM_NAME } \" automatically, please specify with -DPLATFORM=<platform> " )
endif ( )
set ( PLATFORM "${DEFAULT_PLATFORM}" CACHE STRING "[Auto-detected] Target platform (LINUX, MACOS, WINDOWS, ANDROID, IOS, WEB)" )
set ( GDEXTENSION_DIR "${CMAKE_CURRENT_SOURCE_DIR}/gdextension" CACHE FILEPATH "Path to a directory containing GDExtension interface header" )
set ( GDEXTENSION_API_FILE "${CMAKE_CURRENT_SOURCE_DIR}/gdextension/extension_api.json" CACHE FILEPATH "Path to GDExtension API JSON file" )
set ( FLOAT_PRECISION "SINGLE" CACHE STRING "Floating-point precision level (SINGLE, DOUBLE)" )
set ( OPTIMIZE "AUTO" CACHE STRING "The desired optimization flags (NONE, CUSTOM, DEBUG, SPEED, SPEED_TRACE, SIZE)" )
set ( SYMBOLS_VISIBILITY "AUTO" CACHE STRING "Symbols visibility on GNU platforms (AUTO, VISIBLE, HIDDEN)" )
#TODO: custom .gdextension template file to add shared library as dependency
set ( GODOT_CPP_LIBRARY_TYPE "STATIC" CACHE STRING "[Experimental] Library type (STATIC, SHARED)" )
option ( DEV_BUILD "Developer build with dev-only debugging code" OFF )
2024-01-09 21:35:20 +00:00
option ( DEBUG_SYMBOLS "Force build with debugging symbols" OFF )
2023-12-31 16:17:28 +00:00
option ( USE_HOT_RELOAD "Enable the extra accounting required to support hot reload" ON )
# Disable exception handling. Godot doesn't use exceptions anywhere, and this
# saves around 20% of binary size and very significant build time (GH-80513).
option ( GODOT_DISABLE_EXCEPTIONS "Force disabling exception handling code" ON )
# Optionally mark headers as SYSTEM
option ( GODOT_CPP_SYSTEM_HEADERS "Mark the header files as SYSTEM. This may be useful to supress warnings in projects including this one" OFF )
set ( GODOT_CPP_SYSTEM_HEADERS_ATTRIBUTE "" )
if ( GODOT_CPP_SYSTEM_HEADERS )
set ( GODOT_CPP_SYSTEM_HEADERS_ATTRIBUTE SYSTEM )
endif ( )
# Enable by default when building godot-cpp only
set ( DEFAULT_WARNING_AS_ERROR OFF )
if ( ${ CMAKE_PROJECT_NAME } STREQUAL ${ PROJECT_NAME } )
set ( DEFAULT_WARNING_AS_ERROR ON )
endif ( )
set ( GODOT_CPP_WARNING_AS_ERROR ${ DEFAULT_WARNING_AS_ERROR } CACHE BOOL "Treat warnings as errors" )
option ( GENERATE_TEMPLATE_GET_NODE "Generate a template version of the Node class's get_node" ON )
###
# Compiler warnings and compiler check generators
include ( GodotCompilerWarnings )
2024-01-09 21:35:20 +00:00
# Create the correct name (godot-cpp.platform.target)
# See more prefix appends in platform-specific configs
2023-12-31 16:17:28 +00:00
if ( ${ DEV_BUILD } )
string ( APPEND LIBRARY_SUFFIX ".dev" )
endif ( )
if ( ${ FLOAT_PRECISION } STREQUAL "DOUBLE" )
string ( APPEND LIBRARY_SUFFIX ".double" )
endif ( )
# Workaround of $<CONFIG> expanding to "" when default build set
set ( CONFIG "$<IF:$<STREQUAL:,$<CONFIG>>,${CMAKE_BUILD_TYPE},$<CONFIG>>" )
2024-01-09 21:35:20 +00:00
string ( TOLOWER ".${PLATFORM}.${TARGET}" platform_target )
string ( PREPEND LIBRARY_SUFFIX ${ platform_target } )
2023-12-31 16:17:28 +00:00
# Default optimization levels if OPTIMIZE=AUTO, for multi-config support
2024-01-09 21:35:20 +00:00
set ( DEFAULT_OPTIMIZATION_DEBUG_FEATURES "$<OR:$<STREQUAL:${TARGET},EDITOR>,$<STREQUAL:${TARGET},TEMPLATE_DEBUG>>" )
set ( DEFAULT_OPTIMIZATION "$<NOT:${DEFAULT_OPTIMIZATION_DEBUG_FEATURES}>" )
set ( DEBUG_SYMBOLS_ENABLED "$<OR:$<BOOL:${DEBUG_SYMBOLS}>,$<IN_LIST:${CONFIG},${CONFIGS_WITH_DEBUG}>>" )
# Clean default options
set ( CMAKE_CXX_FLAGS_DEBUG "" )
set ( CMAKE_CXX_FLAGS_RELEASE "" )
set ( CMAKE_CXX_FLAGS_RELWITHDEBINFO "" )
set ( CMAKE_CXX_FLAGS_MINSIZEREL "" )
2023-12-31 16:17:28 +00:00
list ( APPEND GODOT_DEFINITIONS
G D E X T E N S I O N
$ < $ { c o m p i l e r _ i s _ m s v c } :
$ < $ < B O O L : $ { G O D O T _ D I S A B L E _ E X C E P T I O N S } > :
_ H A S _ E X C E P T I O N S = 0
>
>
$ < $ < S T R E Q U A L : $ { F L O A T _ P R E C I S I O N } , D O U B L E > :
R E A L _ T _ I S _ D O U B L E
>
2024-01-09 21:35:20 +00:00
$ < $ < A N D : $ < N O T : $ < S T R E Q U A L : $ { T A R G E T } , T E M P L A T E _ R E L E A S E > > , $ < B O O L : $ { U S E _ H O T _ R E L O A D } > > :
2024-01-29 23:18:12 +00:00
H O T _ R E L O A D _ E N A B L E D
2023-12-31 16:17:28 +00:00
>
2024-01-09 21:35:20 +00:00
$ < $ < S T R E Q U A L : $ { T A R G E T } , E D I T O R > :
2023-12-31 16:17:28 +00:00
T O O L S _ E N A B L E D
>
$ < $ < B O O L : $ { D E V _ B U I L D } > :
D E V _ E N A B L E D
>
$ < $ < N O T : $ < B O O L : $ { D E V _ B U I L D } > > :
N D E B U G
>
2024-01-09 21:35:20 +00:00
$ < $ < N O T : $ < S T R E Q U A L : $ { T A R G E T } , T E M P L A T E _ R E L E A S E > > :
2023-12-31 16:17:28 +00:00
D E B U G _ E N A B L E D
D E B U G _ M E T H O D S _ E N A B L E D
>
)
list ( APPEND GODOT_CC_FLAGS
$ < $ { c o m p i l e r _ i s _ m s v c } :
2024-01-09 21:35:20 +00:00
$ < $ { D E B U G _ S Y M B O L S _ E N A B L E D } :
2023-12-31 16:17:28 +00:00
/ Z i
/ F S
>
2024-01-09 21:35:20 +00:00
$ < $ < S T R E Q U A L : $ { O P T I M I Z E } , A U T O > :
$ < $ < C O N F I G : R e l e a s e , R e l W i t h D e b I n f o > :
$ < $ { D E F A U L T _ O P T I M I Z A T I O N } :
/ O 2
>
$ < $ { D E F A U L T _ O P T I M I Z A T I O N _ D E B U G _ F E A T U R E S } :
/ O 2
>
>
$ < $ < C O N F I G : M i n S i z e R e l > :
/ O 1
>
$ < $ < C O N F I G : D e b u g , > :
/ O d
>
2023-12-31 16:17:28 +00:00
>
2024-01-09 21:35:20 +00:00
$ < $ < N O T : $ < S T R E Q U A L : $ { O P T I M I Z E } , A U T O > > :
$ < $ < S T R E Q U A L : $ { O P T I M I Z E } , S P E E D > : / O 2 >
$ < $ < S T R E Q U A L : $ { O P T I M I Z E } , S P E E D _ T R A C E > : / O 2 >
$ < $ < S T R E Q U A L : $ { O P T I M I Z E } , S I Z E > : / O 1 >
$ < $ < S T R E Q U A L : $ { O P T I M I Z E } , D E B U G > : / O d >
$ < $ < S T R E Q U A L : $ { O P T I M I Z E } , N O N E > : / O d >
2023-12-31 16:17:28 +00:00
>
2024-01-09 21:35:20 +00:00
2023-12-31 16:17:28 +00:00
>
$ < $ < N O T : $ { c o m p i l e r _ i s _ m s v c } > :
2024-01-09 21:35:20 +00:00
$ < $ { D E B U G _ S Y M B O L S _ E N A B L E D } :
2023-12-31 16:17:28 +00:00
- g d w a r f - 4
2024-01-09 21:35:20 +00:00
2023-12-31 16:17:28 +00:00
$ < $ < B O O L : $ { D E V _ B U I L D } > :
- g 3
>
$ < $ < N O T : $ < B O O L : $ { D E V _ B U I L D } > > :
- g 2
>
>
$ < $ < S T R E Q U A L : $ { S Y M B O L S _ V I S I B I L I T Y } , V I S I B L E > :
- f v i s i b i l i t y = d e f a u l t
>
$ < $ < S T R E Q U A L : $ { S Y M B O L S _ V I S I B I L I T Y } , H I D D E N > :
- f v i s i b i l i t y = h i d d e n
>
2024-01-09 21:35:20 +00:00
$ < $ < S T R E Q U A L : $ { O P T I M I Z E } , A U T O > :
$ < $ < C O N F I G : R e l e a s e , R e l W i t h D e b I n f o > :
$ < $ { D E F A U L T _ O P T I M I Z A T I O N } :
- O 3
>
$ < $ { D E F A U L T _ O P T I M I Z A T I O N _ D E B U G _ F E A T U R E S } :
- O 2
>
>
$ < $ < C O N F I G : M i n S i z e R e l > :
- O s
>
$ < $ < C O N F I G : D e b u g , > :
- O g
>
2023-12-31 16:17:28 +00:00
>
2024-01-09 21:35:20 +00:00
$ < $ < N O T : $ < S T R E Q U A L : $ { O P T I M I Z E } , A U T O > > :
$ < $ < S T R E Q U A L : $ { O P T I M I Z E } , S P E E D > : - O 3 >
$ < $ < S T R E Q U A L : $ { O P T I M I Z E } , S P E E D _ T R A C E > : - O 2 >
$ < $ < S T R E Q U A L : $ { O P T I M I Z E } , S I Z E > : - O s >
$ < $ < S T R E Q U A L : $ { O P T I M I Z E } , D E B U G > : - O g >
$ < $ < S T R E Q U A L : $ { O P T I M I Z E } , N O N E > : - O 0 >
2023-12-31 16:17:28 +00:00
>
>
)
list ( APPEND GODOT_CXX_FLAGS
$ < $ { c o m p i l e r _ i s _ m s v c } :
$ < $ < N O T : $ < B O O L : $ { G O D O T _ D I S A B L E _ E X C E P T I O N S } > > :
/ E H s c
>
>
$ < $ < N O T : $ { c o m p i l e r _ i s _ m s v c } > :
$ < $ < B O O L : $ { G O D O T _ D I S A B L E _ E X C E P T I O N S } > :
2024-01-09 21:35:20 +00:00
- f n o - e x c e p t i o n s
2023-12-31 16:17:28 +00:00
>
>
)
list ( APPEND GODOT_LINK_FLAGS
$ < $ { c o m p i l e r _ i s _ m s v c } :
2024-01-09 21:35:20 +00:00
$ < $ { D E B U G _ S Y M B O L S _ E N A B L E D } :
2023-12-31 16:17:28 +00:00
/ D E B U G : F U L L
>
2024-01-09 21:35:20 +00:00
$ < $ < S T R E Q U A L : $ { O P T I M I Z E } , A U T O > :
$ < $ < C O N F I G : R e l e a s e , R e l W i t h D e b I n f o > :
$ < $ { D E F A U L T _ O P T I M I Z A T I O N } :
/ O P T : R E F
>
$ < $ { D E F A U L T _ O P T I M I Z A T I O N _ D E B U G _ F E A T U R E S } :
/ O P T : R E F
/ O P T : N O I C F
>
>
$ < $ < C O N F I G : M i n S i z e R e l > :
/ O P T : R E F
>
2023-12-31 16:17:28 +00:00
>
2024-01-09 21:35:20 +00:00
$ < $ < N O T : $ < S T R E Q U A L : $ { O P T I M I Z E } , A U T O > > :
$ < $ < S T R E Q U A L : $ { O P T I M I Z E } , S P E E D > : / O P T : R E F >
$ < $ < S T R E Q U A L : $ { O P T I M I Z E } , S P E E D _ T R A C E > : / O P T : R E F / O P T : N O I C F >
$ < $ < S T R E Q U A L : $ { O P T I M I Z E } , S I Z E > : / O P T : R E F >
2023-12-31 16:17:28 +00:00
>
>
$ < $ < N O T : $ { c o m p i l e r _ i s _ m s v c } > :
$ < $ < S T R E Q U A L : $ { S Y M B O L S _ V I S I B I L I T Y } , V I S I B L E > :
- f v i s i b i l i t y = d e f a u l t
>
$ < $ < S T R E Q U A L : $ { S Y M B O L S _ V I S I B I L I T Y } , H I D D E N > :
- f v i s i b i l i t y = h i d d e n
>
2024-01-09 21:35:20 +00:00
$ < $ < N O T : $ { D E B U G _ S Y M B O L S _ E N A B L E D } > :
2023-12-31 16:17:28 +00:00
$ < $ < C X X _ C O M P I L E R _ I D : A p p l e C l a n g > : # SCons: not is_vanilla_clang(env)
" - W l , - S "
" - W l , - x "
" - W l , - d e a d _ s t r i p "
>
$ < $ < N O T : $ < C X X _ C O M P I L E R _ I D : A p p l e C l a n g > > :
" - s "
>
>
>
)
# Platform-specific options
if ( "${PLATFORM}" STREQUAL "LINUX" )
include ( linux )
elseif ( "${PLATFORM}" STREQUAL "MACOS" )
include ( macos )
elseif ( "${PLATFORM}" STREQUAL "WINDOWS" )
include ( windows )
elseif ( "${PLATFORM}" STREQUAL "ANDROID" )
include ( android )
elseif ( "${PLATFORM}" STREQUAL "IOS" )
include ( ios )
elseif ( "${PLATFORM}" STREQUAL "WEB" )
include ( web )
else ( )
message ( FATAL_ERROR "Platform not supported: ${PLATFORM}" )
endif ( )
2024-01-09 21:35:20 +00:00
string ( APPEND LIBRARY_SUFFIX ".${ARCH}" )
if ( ${ IOS_SIMULATOR } )
string ( APPEND LIBRARY_SUFFIX ".simulator" )
endif ( )
2023-12-31 16:17:28 +00:00
# Write all flags to file for cmake configuration debug
2024-01-09 21:35:20 +00:00
file ( GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/flags-${CONFIG}.txt"
2023-12-31 16:17:28 +00:00
C O N T E N T
2024-01-09 21:35:20 +00:00
" C _ F L A G S ' $ { G O D O T _ C C _ F L A G S } ' \ n C X X _ F L A G S ' $ { G O D O T _ C X X _ F L A G S } ' \ n L I N K _ F L A G S ' $ { G O D O T _ L I N K _ F L A G S } ' \ n C O M P I L E _ W A R N I N G _ F L A G S ' $ { G O D O T _ C O M P I L E _ W A R N I N G _ F L A G S } ' \ n D E F I N I T I O N S ' $ { G O D O T _ D E F I N I T I O N S } ' "
2023-12-31 16:17:28 +00:00
T A R G E T $ { P R O J E C T _ N A M E }
)