# This file contains variables needed by all platforms ### Options set(CMAKE_CONFIGURATION_TYPES "template_debug;editor;template_release") if("${CMAKE_BUILD_TYPE}" STREQUAL "") set(CMAKE_BUILD_TYPE template_debug) endif() # 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 "Build with debugging symbols" ON) 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.arch) 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}" platform) string(PREPEND LIBRARY_SUFFIX "${platform}.${CONFIG}") # Default optimization levels if OPTIMIZE=AUTO, for multi-config support set(DEFAULT_OPTIMIZATION_DEV "$,$>") set(DEFAULT_OPTIMIZATION_DEBUG_FEATURES "$,$,$,$>>") set(DEFAULT_OPTIMIZATION "$<$>,STREQUAL:${OPTIMIZE},AUTO>>") 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}: $<$: /Zi /FS > $<$,${DEFAULT_OPTIMIZATION}>: /O2 > $<$,${DEFAULT_OPTIMIZATION_DEBUG_FEATURES}>: /O2 > $<$: /O1 > $<$,$,${DEFAULT_OPTIMIZATION_DEV}>: /Od > > $<$: $<$: -gdwarf-4 $<$: -g3 > $<$>: -g2 > > $<$: -fvisibility=default > $<$: -fvisibility=hidden > $<$>: -O3 > $<$,${DEFAULT_OPTIMIZATION_DEBUG_FEATURES}>: -O2 > $<$: -Os > $<$: -Og > $<$,${DEFAULT_OPTIMIZATION_DEV}>: -O0 > > ) list(APPEND GODOT_CXX_FLAGS $<${compiler_is_msvc}: $<$>: /EHsc > > $<$: $<$: -fno-exceptions > > ) list(APPEND GODOT_LINK_FLAGS $<${compiler_is_msvc}: $<$: /DEBUG:FULL > $<$: /OPT:REF > $<$,${DEFAULT_OPTIMIZATION_DEBUG_FEATURES}>: /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() # Write all flags to file for cmake configuration debug file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/flags.txt" CONTENT "C_FLAGS '${GODOT_CC_FLAGS}'\nCXX_FLAGS '${GODOT_CXX_FLAGS}'\nLINK_FLAGS '${GODOT_LINK_FLAGS}'\nCOMPILE_WARNING_FLAGS '${GODOT_COMPILE_WARNING_FLAGS}'\n" TARGET ${PROJECT_NAME} )