# This file contains variables needed by all platforms ### Options set(CONFIGS_WITH_DEBUG "Debug;RelWithDebInfo" CACHE STRING "Configurations that should have debug symbols (Modify if support for custom configurations is needed)") # Default config if("${CMAKE_BUILD_TYPE}" STREQUAL "") set(CMAKE_BUILD_TYPE "Debug") endif() set(TARGET "TEMPLATE_DEBUG" CACHE STRING "Target platform (EDITOR, TEMPLATE_DEBUG, TEMPLATE_RELEASE)") # 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=") 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) option(DEBUG_SYMBOLS "Force build with debugging symbols" OFF) 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) # Create the correct name (godot-cpp.platform.target) # See more prefix appends in platform-specific configs if(${DEV_BUILD}) string(APPEND LIBRARY_SUFFIX ".dev") endif() if(${FLOAT_PRECISION} STREQUAL "DOUBLE") string(APPEND LIBRARY_SUFFIX ".double") endif() # Workaround of $ expanding to "" when default build set set(CONFIG "$>,${CMAKE_BUILD_TYPE},$>") string(TOLOWER ".${PLATFORM}.${TARGET}" platform_target) string(PREPEND LIBRARY_SUFFIX ${platform_target}) # Default optimization levels if OPTIMIZE=AUTO, for multi-config support set(DEFAULT_OPTIMIZATION_DEBUG_FEATURES "$,$>") set(DEFAULT_OPTIMIZATION "$") set(DEBUG_SYMBOLS_ENABLED "$,$>") # Clean default options set(CMAKE_CXX_FLAGS_DEBUG "") set(CMAKE_CXX_FLAGS_RELEASE "") set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "") set(CMAKE_CXX_FLAGS_MINSIZEREL "") list(APPEND GODOT_DEFINITIONS GDEXTENSION $<${compiler_is_msvc}: $<$: _HAS_EXCEPTIONS=0 > > $<$: REAL_T_IS_DOUBLE > $<$>,$>: HOT_RELOAD_ENABLE > $<$: TOOLS_ENABLED > $<$: DEV_ENABLED > $<$>: NDEBUG > $<$>: DEBUG_ENABLED DEBUG_METHODS_ENABLED > ) list(APPEND GODOT_CC_FLAGS $<${compiler_is_msvc}: $<${DEBUG_SYMBOLS_ENABLED}: /Zi /FS > $<$: $<$: $<${DEFAULT_OPTIMIZATION}: /O2 > $<${DEFAULT_OPTIMIZATION_DEBUG_FEATURES}: /O2 > > $<$: /O1 > $<$: /Od > > $<$>: $<$:/O2> $<$:/O2> $<$:/O1> $<$:/Od> $<$:/Od> > > $<$: $<${DEBUG_SYMBOLS_ENABLED}: -gdwarf-4 $<$: -g3 > $<$>: -g2 > > $<$: -fvisibility=default > $<$: -fvisibility=hidden > $<$: $<$: $<${DEFAULT_OPTIMIZATION}: -O3 > $<${DEFAULT_OPTIMIZATION_DEBUG_FEATURES}: -O2 > > $<$: -Os > $<$: -Og > > $<$>: $<$:-O3> $<$:-O2> $<$:-Os> $<$:-Og> $<$:-O0> > > ) list(APPEND GODOT_CXX_FLAGS $<${compiler_is_msvc}: $<$>: /EHsc > > $<$: $<$: -fno-exceptions > > ) list(APPEND GODOT_LINK_FLAGS $<${compiler_is_msvc}: $<${DEBUG_SYMBOLS_ENABLED}: /DEBUG:FULL > $<$: $<$: $<${DEFAULT_OPTIMIZATION}: /OPT:REF > $<${DEFAULT_OPTIMIZATION_DEBUG_FEATURES}: /OPT:REF /OPT:NOICF > > $<$: /OPT:REF > > $<$>: $<$:/OPT:REF> $<$:/OPT:REF /OPT:NOICF> $<$:/OPT:REF> > > $<$: $<$: -fvisibility=default > $<$: -fvisibility=hidden > $<$: $<$: # SCons: not is_vanilla_clang(env) "-Wl,-S" "-Wl,-x" "-Wl,-dead_strip" > $<$>: "-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() string(APPEND LIBRARY_SUFFIX ".${ARCH}") if(${IOS_SIMULATOR}) string(APPEND LIBRARY_SUFFIX ".simulator") endif() # Write all flags to file for cmake configuration debug file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/flags-${CONFIG}.txt" CONTENT "C_FLAGS '${GODOT_CC_FLAGS}'\nCXX_FLAGS '${GODOT_CXX_FLAGS}'\nLINK_FLAGS '${GODOT_LINK_FLAGS}'\nCOMPILE_WARNING_FLAGS '${GODOT_COMPILE_WARNING_FLAGS}'\nDEFINITIONS '${GODOT_DEFINITIONS}'" TARGET ${PROJECT_NAME} )