mirror of
https://github.com/godotengine/godot-cpp.git
synced 2026-01-05 02:10:14 +03:00
Modernise Existing CMakeLists.txt
- Added to .gitignore CMakeUserPresets.json
### Configuration:
- Changed python command to use single quotes to make build output log more legible.
- Added GODOT_DEV_BUILD to allow differentiation of debug or Release builds.
- Added find logic for macos Cocoa library
### godot-cpp Changes
- godot-cpp-test is changed to be incorporated into the cmake build as a target.
- Duplicated godot-cpp target into [template_release, template_debug, editor]
- Created {platform}.cmake files mirroring the style of the SCons build.
CMake has a feature called generator expressions for its configuration variables that are evaluated at build time. This allows multi-configuration build systems to properly evaulate options. for msvc, xcode and nijna multi-config.
- Moved configuration options to generator expressions with the notable exclusion of OSX_ARCHITECTURES.
- Remove CMAKE_BUILD_TYPE from msvc CI target as Multi-Config generators ignore it
### godot-cpp-test Changes
- Removed majority of the cmake code, now that the godot-cpp project is setup, the majority of the flags will be propagated as transient dependencies
- Marked with EXCLUDE_FROM_ALL so that it isn't built as part of the 'all' target
- Updated ci to build the godot-cpp-test target from the root directory using cmake
- Tests passing for Windows, Linux, and Macos builds.
### Documentation
Updated with new information
Added Emscripten example
Added Android example
This commit is contained in:
41
cmake/android.cmake
Normal file
41
cmake/android.cmake
Normal file
@@ -0,0 +1,41 @@
|
||||
#[=======================================================================[.rst:
|
||||
Android
|
||||
-------
|
||||
|
||||
This file contains functions for options and configuration for targeting the
|
||||
Android platform
|
||||
|
||||
Configuration of the Android toolchain is done using toolchain files,
|
||||
CMakePresets, or variables on the command line.
|
||||
|
||||
The `Android SDK`_ provides toolchain files to help with configuration.
|
||||
|
||||
CMake has its own `built-in support`_ for cross compiling to the
|
||||
Android platforms.
|
||||
|
||||
.. warning::
|
||||
|
||||
Android does not support or test the CMake built-in workflow, recommend
|
||||
using their toolchain file.
|
||||
|
||||
.. _Android SDK:https://developer.android.com/ndk/guides/cmake
|
||||
|
||||
.. _built-in support:https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html#cross-compiling-for-android
|
||||
|
||||
There is further information and examples in the doc/cmake.rst file.
|
||||
|
||||
]=======================================================================]
|
||||
function( android_options )
|
||||
# Android Options
|
||||
endfunction()
|
||||
|
||||
function( android_generate TARGET_NAME )
|
||||
|
||||
target_compile_definitions(${TARGET_NAME}
|
||||
PUBLIC
|
||||
ANDROID_ENABLED
|
||||
UNIX_ENABLED
|
||||
)
|
||||
|
||||
common_compiler_flags( ${TARGET_NAME} )
|
||||
endfunction()
|
||||
@@ -1,94 +1,162 @@
|
||||
# Add warnings based on compiler & version
|
||||
# Set some helper variables for readability
|
||||
set( compiler_less_than_v8 "$<VERSION_LESS:$<CXX_COMPILER_VERSION>,8>" )
|
||||
set( compiler_greater_than_or_equal_v9 "$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,9>" )
|
||||
set( compiler_greater_than_or_equal_v11 "$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,11>" )
|
||||
set( compiler_less_than_v11 "$<VERSION_LESS:$<CXX_COMPILER_VERSION>,11>" )
|
||||
set( compiler_greater_than_or_equal_v12 "$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,12>" )
|
||||
#[=======================================================================[.rst:
|
||||
Common Compiler Flags
|
||||
---------------------
|
||||
|
||||
# These compiler options reflect what is in godot/SConstruct.
|
||||
target_compile_options( ${PROJECT_NAME} PRIVATE
|
||||
# MSVC only
|
||||
$<${compiler_is_msvc}:
|
||||
/W4
|
||||
This file contains a single function to configure platform agnostic compiler
|
||||
flags like optimization levels, warnings, and features. For platform specific
|
||||
flags look to each of the ``cmake/<platform>.cmake`` files.
|
||||
|
||||
# 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)
|
||||
/wd4201 # C4201 (non-standard nameless struct/union): Only relevant for C89.
|
||||
/wd4244 # C4244 C4245 C4267 (narrowing conversions): Unavoidable at this scale.
|
||||
/wd4245
|
||||
/wd4267
|
||||
/wd4305 # C4305 (truncation): double to float or real_t, too hard to avoid.
|
||||
/wd4514 # C4514 (unreferenced inline function has been removed)
|
||||
/wd4714 # C4714 (function marked as __forceinline not inlined)
|
||||
/wd4820 # C4820 (padding added after construct)
|
||||
>
|
||||
]=======================================================================]
|
||||
#Generator Expression Helpers
|
||||
set( IS_CLANG "$<CXX_COMPILER_ID:Clang>" )
|
||||
set( IS_APPLECLANG "$<CXX_COMPILER_ID:AppleClang>" )
|
||||
set( IS_GNU "$<CXX_COMPILER_ID:GNU>" )
|
||||
set( IS_MSVC "$<CXX_COMPILER_ID:MSVC>" )
|
||||
set( NOT_MSVC "$<NOT:$<CXX_COMPILER_ID:MSVC>>" )
|
||||
|
||||
# Clang and GNU common options
|
||||
$<$<OR:${compiler_is_clang},${compiler_is_gnu}>:
|
||||
-Wall
|
||||
-Wctor-dtor-privacy
|
||||
-Wextra
|
||||
-Wno-unused-parameter
|
||||
-Wnon-virtual-dtor
|
||||
-Wwrite-strings
|
||||
>
|
||||
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>" )
|
||||
|
||||
# Clang only
|
||||
$<${compiler_is_clang}:
|
||||
-Wimplicit-fallthrough
|
||||
-Wno-ordered-compare-function-pointers
|
||||
>
|
||||
set( HOT_RELOAD-UNSET "$<STREQUAL:${GODOT_USE_HOT_RELOAD},>")
|
||||
|
||||
# GNU only
|
||||
$<${compiler_is_gnu}:
|
||||
-Walloc-zero
|
||||
-Wduplicated-branches
|
||||
-Wduplicated-cond
|
||||
-Wno-misleading-indentation
|
||||
-Wplacement-new=1
|
||||
-Wshadow-local
|
||||
-Wstringop-overflow=4
|
||||
>
|
||||
$<$<AND:${compiler_is_gnu},${compiler_less_than_v8}>:
|
||||
# Bogus warning fixed in 8+.
|
||||
-Wno-strict-overflow
|
||||
>
|
||||
$<$<AND:${compiler_is_gnu},${compiler_greater_than_or_equal_v9}>:
|
||||
-Wattribute-alias=2
|
||||
>
|
||||
$<$<AND:${compiler_is_gnu},${compiler_greater_than_or_equal_v11}>:
|
||||
# Broke on MethodBind templates before GCC 11.
|
||||
-Wlogical-op
|
||||
>
|
||||
$<$<AND:${compiler_is_gnu},${compiler_less_than_v11}>:
|
||||
# Regression in GCC 9/10, spams so much in our variadic templates that we need to outright disable it.
|
||||
-Wno-type-limits
|
||||
>
|
||||
$<$<AND:${compiler_is_gnu},${compiler_greater_than_or_equal_v12}>:
|
||||
# False positives in our error macros, see GH-58747.
|
||||
-Wno-return-type
|
||||
>
|
||||
)
|
||||
set( DISABLE_EXCEPTIONS "$<BOOL:${GODOT_DISABLE_EXCEPTIONS}>")
|
||||
|
||||
|
||||
function( common_compiler_flags TARGET_NAME )
|
||||
set( IS_RELEASE "$<STREQUAL:${TARGET_NAME},template_release>")
|
||||
set( DEBUG_FEATURES "$<OR:$<STREQUAL:${TARGET_NAME},template_debug>,$<STREQUAL:${TARGET_NAME},editor>>" )
|
||||
set( HOT_RELOAD "$<IF:${HOT_RELOAD-UNSET},$<NOT:${IS_RELEASE}>,$<BOOL:${GODOT_USE_HOT_RELOAD}>>" )
|
||||
set( DEBUG_SYMBOLS "$<BOOL:${GODOT_DEBUG_SYMBOLS}>" )
|
||||
|
||||
target_compile_features(${TARGET_NAME}
|
||||
PUBLIC
|
||||
cxx_std_17
|
||||
)
|
||||
|
||||
# These compiler options reflect what is in godot/SConstruct.
|
||||
target_compile_options( ${TARGET_NAME}
|
||||
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>
|
||||
>
|
||||
$<$<NOT:${DISABLE_EXCEPTIONS}>:
|
||||
$<${IS_MSVC}:/EHsc>
|
||||
>
|
||||
|
||||
# Enabling Debug Symbols
|
||||
$<${DEBUG_SYMBOLS}:
|
||||
$<${IS_MSVC}: /Zi /FS>
|
||||
|
||||
# Adding dwarf-4 explicitly makes stacktraces work with clang builds,
|
||||
# otherwise addr2line doesn't understand them.
|
||||
$<${NOT_MSVC}:
|
||||
-gdwarf-4
|
||||
$<IF:${IS_DEV},-g3,-g2>
|
||||
>
|
||||
>
|
||||
|
||||
$<${IS_DEV}:
|
||||
$<${NOT_MSVC}:-fno-omit-frame-pointer -O0 -g>
|
||||
>
|
||||
|
||||
$<${HOT_RELOAD}:
|
||||
$<${IS_GNU}:-fno-gnu-unique>
|
||||
>
|
||||
|
||||
# MSVC only
|
||||
$<${IS_MSVC}:
|
||||
"/MP ${PROC_N}"
|
||||
/W4
|
||||
|
||||
# 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)
|
||||
/wd4201 # C4201 (non-standard nameless struct/union): Only relevant for C89.
|
||||
/wd4244 # C4244 C4245 C4267 (narrowing conversions): Unavoidable at this scale.
|
||||
/wd4245
|
||||
/wd4267
|
||||
/wd4305 # C4305 (truncation): double to float or real_t, too hard to avoid.
|
||||
/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
|
||||
$<$<OR:${IS_CLANG},${IS_GNU}>:
|
||||
-Wall
|
||||
-Wctor-dtor-privacy
|
||||
-Wextra
|
||||
-Wno-unused-parameter
|
||||
-Wnon-virtual-dtor
|
||||
-Wwrite-strings
|
||||
>
|
||||
|
||||
# Clang only
|
||||
$<${IS_CLANG}:
|
||||
-Wimplicit-fallthrough
|
||||
-Wno-ordered-compare-function-pointers
|
||||
>
|
||||
|
||||
# GNU only
|
||||
$<${IS_GNU}:
|
||||
-Walloc-zero
|
||||
-Wduplicated-branches
|
||||
-Wduplicated-cond
|
||||
-Wno-misleading-indentation
|
||||
-Wplacement-new=1
|
||||
-Wshadow-local
|
||||
-Wstringop-overflow=4
|
||||
|
||||
# Bogus warning fixed in 8+.
|
||||
$<${GNU_LT_V8}:-Wno-strict-overflow>
|
||||
|
||||
$<${GNU_GE_V9}:-Wattribute-alias=2>
|
||||
|
||||
# Broke on MethodBind templates before GCC 11.
|
||||
$<${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>
|
||||
|
||||
# False positives in our error macros, see GH-58747.
|
||||
$<${GNU_GE_V12}:-Wno-return-type>
|
||||
>
|
||||
)
|
||||
|
||||
target_compile_definitions(${TARGET_NAME}
|
||||
PUBLIC
|
||||
GDEXTENSION
|
||||
|
||||
# features
|
||||
$<${DEBUG_FEATURES}:DEBUG_ENABLED DEBUG_METHODS_ENABLED>
|
||||
|
||||
$<${HOT_RELOAD}:HOT_RELOAD_ENABLED>
|
||||
|
||||
$<$<STREQUAL:${GODOT_PRECISION},double>:REAL_T_IS_DOUBLE>
|
||||
|
||||
$<${IS_MSVC}:$<${DISABLE_EXCEPTIONS}:_HAS_EXCEPTIONS=0>>
|
||||
)
|
||||
|
||||
target_link_options( ${TARGET_NAME}
|
||||
PUBLIC
|
||||
$<${IS_MSVC}:
|
||||
/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>
|
||||
$<${IS_APPLECLANG}:-Wl,-S -Wl,-x -Wl,-dead_strip>
|
||||
>
|
||||
)
|
||||
|
||||
# Treat warnings as errors
|
||||
function( set_warning_as_error )
|
||||
message( STATUS "[${PROJECT_NAME}] Treating warnings as errors")
|
||||
if ( CMAKE_VERSION VERSION_GREATER_EQUAL "3.24" )
|
||||
set_target_properties( ${PROJECT_NAME}
|
||||
PROPERTIES
|
||||
COMPILE_WARNING_AS_ERROR ON
|
||||
)
|
||||
else()
|
||||
target_compile_options( ${PROJECT_NAME}
|
||||
PRIVATE
|
||||
$<${compiler_is_msvc}:/WX>
|
||||
$<$<OR:${compiler_is_clang},${compiler_is_gnu}>:-Werror>
|
||||
)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
if ( GODOT_WARNING_AS_ERROR )
|
||||
set_warning_as_error()
|
||||
endif()
|
||||
|
||||
40
cmake/emsdkHack.cmake
Normal file
40
cmake/emsdkHack.cmake
Normal file
@@ -0,0 +1,40 @@
|
||||
#[=======================================================================[.rst:
|
||||
emsdkHack
|
||||
---------
|
||||
|
||||
The Emscripten platform doesn't support the use of shared libraries as known by cmake.
|
||||
|
||||
* https://github.com/emscripten-core/emscripten/issues/15276
|
||||
* https://github.com/emscripten-core/emscripten/issues/17804
|
||||
|
||||
This workaround only works due to the way the cmake scripts are loaded.
|
||||
|
||||
Prior to the use of ``project( ... )`` directive we need to set
|
||||
``CMAKE_PROJECT_INCLUDE=cmake/emscripten.cmake``.
|
||||
This file will be loaded after the toolchain overriding the settings that
|
||||
prevent shared library building.
|
||||
|
||||
CMAKE_PROJECT_INCLUDE was Added in version 3.15.
|
||||
``CMAKE_PROJECT_<projectName>_INCLUDE`` was Added in version 3.17:
|
||||
|
||||
More information on cmake's `code injection`_
|
||||
|
||||
.. _code injection:https://cmake.org/cmake/help/latest/command/project.html#code-injection
|
||||
|
||||
Overwrite Shared Library Properties to allow shared libs to be generated.
|
||||
]=======================================================================]
|
||||
if( EMSCRIPTEN )
|
||||
set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE)
|
||||
set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-sSIDE_MODULE=1")
|
||||
set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS "-sSIDE_MODULE=1")
|
||||
set(CMAKE_SHARED_LIBRARY_SUFFIX) # remove the suffix from the shared lib
|
||||
set(CMAKE_STRIP FALSE) # used by default in pybind11 on .so modules
|
||||
|
||||
# The Emscripten toolchain sets the default value for EMSCRIPTEN_SYSTEM_PROCESSOR to x86
|
||||
# and CMAKE_SYSTEM_PROCESSOR to this value. I don't want that.
|
||||
set(CMAKE_SYSTEM_PROCESSOR "wasm32" )
|
||||
# the above prevents the need for logic like:
|
||||
#if( ${CMAKE_SYSTEM_NAME} STREQUAL Emscripten )
|
||||
# set( SYSTEM_ARCH wasm32 )
|
||||
#endif ()
|
||||
endif ()
|
||||
@@ -1,13 +1,85 @@
|
||||
function( godotcpp_options )
|
||||
#[=======================================================================[.rst:
|
||||
godotcpp.cmake
|
||||
--------------
|
||||
|
||||
#TODO platform
|
||||
#TODO target
|
||||
Because these files are included into the top level CMakelists.txt before the
|
||||
project directive, it means that
|
||||
|
||||
* ``CMAKE_CURRENT_SOURCE_DIR`` is the location of godot-cpp's CMakeLists.txt
|
||||
* ``CMAKE_SOURCE_DIR`` is the location where any prior ``project(...)``
|
||||
directive was
|
||||
|
||||
]=======================================================================]
|
||||
include( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/common_compiler_flags.cmake)
|
||||
include( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/android.cmake)
|
||||
include( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/ios.cmake)
|
||||
include( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/linux.cmake)
|
||||
include( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/macos.cmake)
|
||||
include( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/web.cmake)
|
||||
include( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/windows.cmake)
|
||||
|
||||
#Silence warning from unused CMAKE_C_COMPILER from toolchain
|
||||
if( CMAKE_C_COMPILER )
|
||||
endif ()
|
||||
|
||||
include(ProcessorCount)
|
||||
ProcessorCount(PROC_MAX)
|
||||
message( "Auto-detected ${PROC_MAX} CPU cores available for build parallelism." )
|
||||
|
||||
# List of known platforms
|
||||
set( PLATFORM_LIST linux macos windows android ios web )
|
||||
|
||||
# List of known architectures
|
||||
set( ARCH_LIST universal x86_32 x86_64 arm32 arm64 rv64 ppc32 ppc64 wasm32 )
|
||||
|
||||
# Function to map processors to known architectures
|
||||
function( godot_arch_map ALIAS PROC )
|
||||
string( TOLOWER "${PROC}" PROC )
|
||||
|
||||
if( "${PROC}" IN_LIST ARCH_LIST )
|
||||
set( ${ALIAS} "${PROC}" PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
|
||||
set( x86_64 "w64;amd64" )
|
||||
set( arm32 "armv7" )
|
||||
set( arm64 "armv8;arm64v8;aarch64" )
|
||||
set( rv64 "rv;riscv;riscv64" )
|
||||
set( ppc32 "ppcle;ppc" )
|
||||
set( ppc64 "ppc64le" )
|
||||
|
||||
if( PROC IN_LIST x86_64 )
|
||||
set(${ALIAS} "x86_64" PARENT_SCOPE )
|
||||
|
||||
elseif( PROC IN_LIST arm32 )
|
||||
set(${ALIAS} "arm32" PARENT_SCOPE )
|
||||
|
||||
elseif( PROC IN_LIST arm64 )
|
||||
set(${ALIAS} "arm64" PARENT_SCOPE )
|
||||
|
||||
elseif( PROC IN_LIST rv64 )
|
||||
set(${ALIAS} "rv64" PARENT_SCOPE )
|
||||
|
||||
elseif( PROC IN_LIST ppc32 )
|
||||
set(${ALIAS} "ppc32" PARENT_SCOPE )
|
||||
|
||||
elseif( PROC IN_LIST ppc64 )
|
||||
set(${ALIAS} "ppc64" PARENT_SCOPE )
|
||||
|
||||
else()
|
||||
set(${ALIAS} "unknown" PARENT_SCOPE )
|
||||
endif ()
|
||||
endfunction()
|
||||
|
||||
# Function to define all the options.
|
||||
function( godotcpp_options )
|
||||
#NOTE: platform is managed using toolchain files.
|
||||
|
||||
# Input from user for GDExtension interface header and the API JSON file
|
||||
set(GODOT_GDEXTENSION_DIR "gdextension" CACHE PATH
|
||||
"Path to a custom directory containing GDExtension interface header and API JSON file ( /path/to/gdextension_dir )" )
|
||||
set(GODOT_CUSTOM_API_FILE "" CACHE FILEPATH
|
||||
"Path to a custom GDExtension API JSON file (takes precedence over `gdextension_dir`) ( /path/to/custom_api_file )")
|
||||
"Path to a custom GDExtension API JSON file (takes precedence over `GODOT_GDEXTENSION_DIR`) ( /path/to/custom_api_file )")
|
||||
|
||||
#TODO generate_bindings
|
||||
|
||||
@@ -19,15 +91,22 @@ function( godotcpp_options )
|
||||
set(GODOT_PRECISION "single" CACHE STRING
|
||||
"Set the floating-point precision level (single|double)")
|
||||
|
||||
#TODO arch
|
||||
# The arch is typically set by the toolchain
|
||||
# however for Apple multi-arch setting it here will override.
|
||||
set( GODOT_ARCH "" CACHE STRING "Target CPU Architecture")
|
||||
set_property( CACHE GODOT_ARCH PROPERTY STRINGS ${ARCH_LIST} )
|
||||
|
||||
#TODO threads
|
||||
#TODO compiledb
|
||||
#TODO compiledb_file
|
||||
#TODO build_profile aka cmake preset
|
||||
|
||||
#NOTE: build_profile's equivalent in cmake is CMakePresets.json
|
||||
|
||||
set(GODOT_USE_HOT_RELOAD "" CACHE BOOL
|
||||
"Enable the extra accounting required to support hot reload. (ON|OFF)")
|
||||
|
||||
# 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|OFF)" ON )
|
||||
|
||||
set( GODOT_SYMBOL_VISIBILITY "hidden" CACHE STRING
|
||||
@@ -36,48 +115,67 @@ function( godotcpp_options )
|
||||
|
||||
#TODO optimize
|
||||
#TODO debug_symbols
|
||||
#TODO dev_build
|
||||
option( GODOT_DEBUG_SYMBOLS "" OFF )
|
||||
option( GODOT_DEV_BUILD "Developer build with dev-only debugging code (DEV_ENABLED)" OFF )
|
||||
|
||||
# FIXME These options are not present in SCons, and perhaps should be added there.
|
||||
option(GODOT_SYSTEM_HEADERS "Expose headers as SYSTEM." ON)
|
||||
option(GODOT_WARNING_AS_ERROR "Treat warnings as errors" OFF)
|
||||
option( GODOT_SYSTEM_HEADERS "Expose headers as SYSTEM." OFF )
|
||||
option( GODOT_WARNING_AS_ERROR "Treat warnings as errors" OFF )
|
||||
|
||||
# Run options commands on the following to populate cache for all platforms.
|
||||
# This type of thing is typically done conditionally
|
||||
# But as scons shows all options so shall we.
|
||||
#TODO ios_options()
|
||||
#TODO linux_options()
|
||||
#TODO macos_options()
|
||||
#TODO web_options()
|
||||
#TODO windows_options()
|
||||
# Run options commands on the following to populate cache for all
|
||||
# platforms. This type of thing is typically done conditionally But as
|
||||
# scons shows all options so shall we.
|
||||
android_options()
|
||||
ios_options()
|
||||
linux_options()
|
||||
macos_options()
|
||||
web_options()
|
||||
windows_options()
|
||||
endfunction()
|
||||
|
||||
|
||||
# Function to configure and generate the targets
|
||||
function( godotcpp_generate )
|
||||
# Set some helper variables for readability
|
||||
set( compiler_is_clang "$<OR:$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:Clang>>" )
|
||||
set( compiler_is_gnu "$<CXX_COMPILER_ID:GNU>" )
|
||||
set( compiler_is_msvc "$<CXX_COMPILER_ID:MSVC>" )
|
||||
#[[ Multi-Threaded MSVC Compilation
|
||||
|
||||
# CXX_VISIBILITY_PRESET supported values are: default, hidden, protected, and internal
|
||||
# which is inline with the gcc -fvisibility=
|
||||
# https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html
|
||||
# To match the scons options we need to change the text to match the -fvisibility flag
|
||||
# it is probably worth another PR which changes both to use the flag options
|
||||
When using the MSVC compiler the build command -j <n> only specifies
|
||||
parallel jobs or targets, and not multi-threaded compilation To speed up
|
||||
compile times on msvc, the /MP <n> flag can be set. But we need to set it
|
||||
at configure time.
|
||||
|
||||
MSVC is true when the compiler is some version of Microsoft Visual C++ or
|
||||
another compiler simulating the Visual C++ cl command-line syntax. ]]
|
||||
if( MSVC )
|
||||
math( EXPR PROC_N "(${PROC_MAX}-1) | (${X}-2)>>31 & 1" )
|
||||
message( "Using ${PROC_N} cores for multi-threaded compilation.")
|
||||
# TODO You can override it at configure time with ...." )
|
||||
else ()
|
||||
message( "Using ${CMAKE_BUILD_PARALLEL_LEVEL} cores, You can override"
|
||||
" it at configure time by using -j <n> or --parallel <n> on the build"
|
||||
" command.")
|
||||
message( " eg. cmake --build . -j 7 ...")
|
||||
endif ()
|
||||
|
||||
#[[ GODOT_SYMBOL_VISIBLITY
|
||||
To match the SCons options, the allowed values are "auto", "visible", and "hidden"
|
||||
This effects the compiler flag -fvisibility=[default|internal|hidden|protected]
|
||||
The corresponding CMake option CXX_VISIBILITY_PRESET accepts the compiler values.
|
||||
|
||||
TODO: It is probably worth a pull request which changes both to use the compiler values
|
||||
https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#index-fvisibility
|
||||
|
||||
This performs the necessary conversion
|
||||
]]
|
||||
if( ${GODOT_SYMBOL_VISIBILITY} STREQUAL "auto" OR ${GODOT_SYMBOL_VISIBILITY} STREQUAL "visible" )
|
||||
set( GODOT_SYMBOL_VISIBILITY "default" )
|
||||
endif ()
|
||||
|
||||
# Default build type is Debug in the SConstruct
|
||||
if("${CMAKE_BUILD_TYPE}" STREQUAL "")
|
||||
set(CMAKE_BUILD_TYPE Debug)
|
||||
endif()
|
||||
|
||||
# Hot reload is enabled by default in Debug-builds
|
||||
if( GODOT_USE_HOT_RELOAD STREQUAL "" AND NOT CMAKE_BUILD_TYPE STREQUAL "Release")
|
||||
set(GODOT_USE_HOT_RELOAD ON)
|
||||
endif()
|
||||
# Setup variable to optionally mark headers as SYSTEM
|
||||
set(GODOT_SYSTEM_HEADERS_ATTRIBUTE "")
|
||||
if (GODOT_SYSTEM_HEADERS)
|
||||
set(GODOT_SYSTEM_HEADERS_ATTRIBUTE SYSTEM)
|
||||
endif ()
|
||||
|
||||
#[[ Generate Bindings ]]
|
||||
if(NOT DEFINED BITS)
|
||||
set(BITS 32)
|
||||
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
@@ -85,67 +183,26 @@ function( godotcpp_generate )
|
||||
endif(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
endif()
|
||||
|
||||
|
||||
set(GODOT_GDEXTENSION_API_FILE "${GODOT_GDEXTENSION_DIR}/extension_api.json")
|
||||
if (NOT "${GODOT_CUSTOM_API_FILE}" STREQUAL "") # User-defined override.
|
||||
set(GODOT_GDEXTENSION_API_FILE "${GODOT_CUSTOM_API_FILE}")
|
||||
endif()
|
||||
|
||||
if ("${GODOT_PRECISION}" STREQUAL "double")
|
||||
add_definitions(-DREAL_T_IS_DOUBLE)
|
||||
endif()
|
||||
|
||||
set( GODOT_COMPILE_FLAGS )
|
||||
|
||||
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
||||
# using Visual Studio C++
|
||||
set(GODOT_COMPILE_FLAGS "/utf-8") # /GF /MP
|
||||
|
||||
if(CMAKE_BUILD_TYPE MATCHES Debug)
|
||||
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /MDd") # /Od /RTC1 /Zi
|
||||
else()
|
||||
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /MD /O2") # /Oy /GL /Gy
|
||||
endif(CMAKE_BUILD_TYPE MATCHES Debug)
|
||||
|
||||
add_definitions(-DNOMINMAX)
|
||||
else() # GCC/Clang
|
||||
if(CMAKE_BUILD_TYPE MATCHES Debug)
|
||||
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -fno-omit-frame-pointer -O0 -g")
|
||||
else()
|
||||
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -O3")
|
||||
endif(CMAKE_BUILD_TYPE MATCHES Debug)
|
||||
endif()
|
||||
|
||||
# Disable exception handling. Godot doesn't use exceptions anywhere, and this
|
||||
# saves around 20% of binary size and very significant build time (GH-80513).
|
||||
if (GODOT_DISABLE_EXCEPTIONS)
|
||||
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
||||
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -D_HAS_EXCEPTIONS=0")
|
||||
else()
|
||||
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -fno-exceptions")
|
||||
endif()
|
||||
else()
|
||||
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
||||
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /EHsc")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Generate source from the bindings file
|
||||
find_package(Python3 3.4 REQUIRED) # pathlib should be present
|
||||
# Code Generation option
|
||||
if(GODOT_GENERATE_TEMPLATE_GET_NODE)
|
||||
set(GENERATE_BINDING_PARAMETERS "True")
|
||||
else()
|
||||
set(GENERATE_BINDING_PARAMETERS "False")
|
||||
endif()
|
||||
|
||||
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)"
|
||||
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}\")"
|
||||
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
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
MAIN_DEPENDENCY ${GODOT_GDEXTENSION_API_FILE}
|
||||
@@ -153,88 +210,87 @@ function( godotcpp_generate )
|
||||
COMMENT "Generating bindings"
|
||||
)
|
||||
|
||||
# Get Sources
|
||||
# As this cmake file was added using 'include(godotcpp)' from the root CMakeLists.txt,
|
||||
# the ${CMAKE_CURRENT_SOURCE_DIR} is still the root dir.
|
||||
file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS src/*.c**)
|
||||
file(GLOB_RECURSE HEADERS CONFIGURE_DEPENDS include/*.h**)
|
||||
|
||||
# Define our godot-cpp library
|
||||
add_library(${PROJECT_NAME} STATIC
|
||||
${SOURCES}
|
||||
${HEADERS}
|
||||
${GENERATED_FILES_LIST}
|
||||
### Platform is derived from the toolchain target
|
||||
# See GeneratorExpressions PLATFORM_ID and CMAKE_SYSTEM_NAME
|
||||
set( SYSTEM_NAME
|
||||
$<$<PLATFORM_ID:Android>:android.${ANDROID_ABI}>
|
||||
$<$<PLATFORM_ID:iOS>:ios>
|
||||
$<$<PLATFORM_ID:Linux>:linux>
|
||||
$<$<PLATFORM_ID:Darwin>:macos>
|
||||
$<$<PLATFORM_ID:Emscripten>:web>
|
||||
$<$<PLATFORM_ID:Windows>:windows>
|
||||
$<$<PLATFORM_ID:Msys>:windows>
|
||||
)
|
||||
add_library(godot::cpp ALIAS ${PROJECT_NAME})
|
||||
string(REPLACE ";" "" SYSTEM_NAME "${SYSTEM_NAME}")
|
||||
|
||||
include(${PROJECT_SOURCE_DIR}/cmake/common_compiler_flags.cmake)
|
||||
|
||||
target_compile_features(${PROJECT_NAME}
|
||||
PRIVATE
|
||||
cxx_std_17
|
||||
)
|
||||
|
||||
if(GODOT_USE_HOT_RELOAD)
|
||||
target_compile_definitions(${PROJECT_NAME} PUBLIC HOT_RELOAD_ENABLED)
|
||||
target_compile_options(${PROJECT_NAME} PUBLIC $<${compiler_is_gnu}:-fno-gnu-unique>)
|
||||
endif()
|
||||
|
||||
target_compile_definitions(${PROJECT_NAME} PUBLIC
|
||||
$<$<CONFIG:Debug>:
|
||||
DEBUG_ENABLED
|
||||
DEBUG_METHODS_ENABLED
|
||||
>
|
||||
$<${compiler_is_msvc}:
|
||||
TYPED_METHOD_BIND
|
||||
>
|
||||
)
|
||||
|
||||
target_link_options(${PROJECT_NAME} PRIVATE
|
||||
$<$<NOT:${compiler_is_msvc}>:
|
||||
-static-libgcc
|
||||
-static-libstdc++
|
||||
-Wl,-R,'$$ORIGIN'
|
||||
>
|
||||
)
|
||||
|
||||
# Optionally mark headers as SYSTEM
|
||||
set(GODOT_SYSTEM_HEADERS_ATTRIBUTE "")
|
||||
if (GODOT_SYSTEM_HEADERS)
|
||||
set(GODOT_SYSTEM_HEADERS_ATTRIBUTE SYSTEM)
|
||||
endif ()
|
||||
|
||||
target_include_directories(${PROJECT_NAME} ${GODOT_SYSTEM_HEADERS_ATTRIBUTE} PUBLIC
|
||||
include
|
||||
${CMAKE_CURRENT_BINARY_DIR}/gen/include
|
||||
${GODOT_GDEXTENSION_DIR}
|
||||
)
|
||||
|
||||
# Add the compile flags
|
||||
set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY COMPILE_FLAGS ${GODOT_COMPILE_FLAGS})
|
||||
|
||||
# Create the correct name (godot.os.build_type.system_bits)
|
||||
string(TOLOWER "${CMAKE_SYSTEM_NAME}" SYSTEM_NAME)
|
||||
string(TOLOWER "${CMAKE_BUILD_TYPE}" BUILD_TYPE)
|
||||
|
||||
if(ANDROID)
|
||||
# Added the android abi after system name
|
||||
set(SYSTEM_NAME ${SYSTEM_NAME}.${ANDROID_ABI})
|
||||
|
||||
# Android does not have the bits at the end if you look at the main godot repo build
|
||||
set(OUTPUT_NAME "godot-cpp.${SYSTEM_NAME}.${BUILD_TYPE}")
|
||||
### Use the arch from the toolchain if it isn't set manually
|
||||
if( GODOT_ARCH )
|
||||
set(SYSTEM_ARCH ${GODOT_ARCH})
|
||||
else()
|
||||
set(OUTPUT_NAME "godot-cpp.${SYSTEM_NAME}.${BUILD_TYPE}.${BITS}")
|
||||
godot_arch_map( SYSTEM_ARCH ${CMAKE_SYSTEM_PROCESSOR} )
|
||||
endif()
|
||||
|
||||
set_target_properties(${PROJECT_NAME}
|
||||
PROPERTIES
|
||||
CXX_EXTENSIONS OFF
|
||||
POSITION_INDEPENDENT_CODE ON
|
||||
CXX_VISIBILITY_PRESET ${GODOT_SYMBOL_VISIBILITY}
|
||||
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin"
|
||||
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin"
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin"
|
||||
OUTPUT_NAME "${OUTPUT_NAME}"
|
||||
)
|
||||
### Define our godot-cpp library targets
|
||||
foreach ( TARGET_NAME template_debug template_release editor )
|
||||
|
||||
# Useful genex snippits used in subsequent genex's
|
||||
set( IS_RELEASE "$<STREQUAL:${TARGET_NAME},template_release>")
|
||||
set( IS_DEV "$<BOOL:${GODOT_DEV_BUILD}>")
|
||||
set( DEBUG_FEATURES "$<OR:$<STREQUAL:${TARGET_NAME},template_debug>,$<STREQUAL:${TARGET_NAME},editor>>" )
|
||||
set( HOT_RELOAD "$<IF:${HOT_RELOAD-UNSET},$<NOT:${IS_RELEASE}>,$<BOOL:${GODOT_USE_HOT_RELOAD}>>" )
|
||||
|
||||
# the godot-cpp.* library targets
|
||||
add_library( ${TARGET_NAME} STATIC ${EXCLUDE} )
|
||||
add_library( godot-cpp::${TARGET_NAME} ALIAS ${TARGET_NAME} )
|
||||
|
||||
file( GLOB_RECURSE GODOTCPP_SOURCES LIST_DIRECTORIES NO CONFIGURE_DEPENDS src/*.cpp )
|
||||
|
||||
target_sources( ${TARGET_NAME}
|
||||
PRIVATE
|
||||
${GODOTCPP_SOURCES}
|
||||
${GENERATED_FILES_LIST}
|
||||
)
|
||||
|
||||
target_include_directories( ${TARGET_NAME} ${GODOT_SYSTEM_HEADERS_ATTRIBUTE} PUBLIC
|
||||
include
|
||||
${CMAKE_CURRENT_BINARY_DIR}/gen/include
|
||||
${GODOT_GDEXTENSION_DIR}
|
||||
)
|
||||
|
||||
set_target_properties( ${TARGET_NAME}
|
||||
PROPERTIES
|
||||
CXX_STANDARD 17
|
||||
CXX_EXTENSIONS OFF
|
||||
CXX_VISIBILITY_PRESET ${GODOT_SYMBOL_VISIBILITY}
|
||||
|
||||
COMPILE_WARNING_AS_ERROR ${GODOT_WARNING_AS_ERROR}
|
||||
POSITION_INDEPENDENT_CODE ON
|
||||
BUILD_RPATH_USE_ORIGIN ON
|
||||
|
||||
PREFIX lib
|
||||
OUTPUT_NAME "${PROJECT_NAME}.${SYSTEM_NAME}.${TARGET_NAME}.${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_ARCH "${SYSTEM_ARCH}"
|
||||
)
|
||||
|
||||
if( CMAKE_SYSTEM_NAME STREQUAL Android )
|
||||
android_generate( ${TARGET_NAME} )
|
||||
elseif ( CMAKE_SYSTEM_NAME STREQUAL iOS )
|
||||
ios_generate( ${TARGET_NAME} )
|
||||
elseif ( CMAKE_SYSTEM_NAME STREQUAL Linux )
|
||||
linux_generate( ${TARGET_NAME} )
|
||||
elseif ( CMAKE_SYSTEM_NAME STREQUAL Darwin )
|
||||
macos_generate( ${TARGET_NAME} )
|
||||
elseif ( CMAKE_SYSTEM_NAME STREQUAL Emscripten )
|
||||
web_generate( ${TARGET_NAME} )
|
||||
elseif ( CMAKE_SYSTEM_NAME STREQUAL Windows )
|
||||
windows_generate( ${TARGET_NAME} )
|
||||
endif ()
|
||||
|
||||
endforeach ()
|
||||
|
||||
endfunction()
|
||||
|
||||
22
cmake/ios.cmake
Normal file
22
cmake/ios.cmake
Normal file
@@ -0,0 +1,22 @@
|
||||
#[=======================================================================[.rst:
|
||||
Ios
|
||||
---
|
||||
|
||||
This file contains functions for options and configuration for targeting the
|
||||
Ios platform
|
||||
|
||||
]=======================================================================]
|
||||
function(ios_options)
|
||||
# iOS options
|
||||
endfunction()
|
||||
|
||||
function(ios_generate TARGET_NAME)
|
||||
|
||||
target_compile_definitions(${TARGET_NAME}
|
||||
PUBLIC
|
||||
IOS_ENABLED
|
||||
UNIX_ENABLED
|
||||
)
|
||||
|
||||
common_compiler_flags(${TARGET_NAME})
|
||||
endfunction()
|
||||
22
cmake/linux.cmake
Normal file
22
cmake/linux.cmake
Normal file
@@ -0,0 +1,22 @@
|
||||
#[=======================================================================[.rst:
|
||||
Linux
|
||||
-----
|
||||
|
||||
This file contains functions for options and configuration for targeting the
|
||||
Linux platform
|
||||
|
||||
]=======================================================================]
|
||||
function( linux_options )
|
||||
# Linux Options
|
||||
endfunction()
|
||||
|
||||
function( linux_generate TARGET_NAME )
|
||||
|
||||
target_compile_definitions( ${TARGET_NAME}
|
||||
PUBLIC
|
||||
LINUX_ENABLED
|
||||
UNIX_ENABLED
|
||||
)
|
||||
|
||||
common_compiler_flags( ${TARGET_NAME} )
|
||||
endfunction()
|
||||
59
cmake/macos.cmake
Normal file
59
cmake/macos.cmake
Normal file
@@ -0,0 +1,59 @@
|
||||
#[=======================================================================[.rst:
|
||||
MacOS
|
||||
-----
|
||||
|
||||
This file contains functions for options and configuration for targeting the
|
||||
MacOS platform
|
||||
|
||||
]=======================================================================]
|
||||
|
||||
# Find Requirements
|
||||
IF(APPLE)
|
||||
set( CMAKE_OSX_SYSROOT $ENV{SDKROOT} )
|
||||
find_library( COCOA_LIBRARY REQUIRED
|
||||
NAMES Cocoa
|
||||
PATHS ${CMAKE_OSX_SYSROOT}/System/Library
|
||||
PATH_SUFFIXES Frameworks
|
||||
NO_DEFAULT_PATH)
|
||||
ENDIF (APPLE)
|
||||
|
||||
|
||||
function( macos_options )
|
||||
# macos options here
|
||||
endfunction()
|
||||
|
||||
|
||||
function( macos_generate TARGET_NAME )
|
||||
|
||||
# OSX_ARCHITECTURES does not support generator expressions.
|
||||
if( NOT GODOT_ARCH OR GODOT_ARCH STREQUAL universal )
|
||||
set( OSX_ARCH "x86_64;arm64" )
|
||||
set( SYSTEM_ARCH universal )
|
||||
else()
|
||||
set( OSX_ARCH ${GODOT_ARCH} )
|
||||
endif()
|
||||
|
||||
set_target_properties( ${TARGET_NAME}
|
||||
PROPERTIES
|
||||
|
||||
OSX_ARCHITECTURES "${OSX_ARCH}"
|
||||
)
|
||||
|
||||
target_compile_definitions(${TARGET_NAME}
|
||||
PUBLIC
|
||||
MACOS_ENABLED
|
||||
UNIX_ENABLED
|
||||
)
|
||||
|
||||
target_link_options( ${TARGET_NAME}
|
||||
PUBLIC
|
||||
-Wl,-undefined,dynamic_lookup
|
||||
)
|
||||
|
||||
target_link_libraries( ${TARGET_NAME}
|
||||
INTERFACE
|
||||
${COCOA_LIBRARY}
|
||||
)
|
||||
|
||||
common_compiler_flags( ${TARGET_NAME} )
|
||||
endfunction()
|
||||
42
cmake/web.cmake
Normal file
42
cmake/web.cmake
Normal file
@@ -0,0 +1,42 @@
|
||||
#[=======================================================================[.rst:
|
||||
Web
|
||||
---
|
||||
|
||||
This file contains functions for options and configuration for targeting the
|
||||
Web platform
|
||||
|
||||
]=======================================================================]
|
||||
|
||||
# Emscripten requires this hack for use of the SHARED option
|
||||
set( CMAKE_PROJECT_godot-cpp_INCLUDE cmake/emsdkHack.cmake )
|
||||
|
||||
function( web_options )
|
||||
# web options
|
||||
endfunction()
|
||||
|
||||
|
||||
function( web_generate TARGET_NAME )
|
||||
|
||||
target_compile_definitions(${TARGET_NAME}
|
||||
PUBLIC
|
||||
WEB_ENABLED
|
||||
UNIX_ENABLED
|
||||
)
|
||||
|
||||
target_compile_options( ${TARGET_NAME}
|
||||
PUBLIC
|
||||
-sSIDE_MODULE
|
||||
-sSUPPORT_LONGJMP=wasm
|
||||
-fno-exceptions
|
||||
)
|
||||
|
||||
target_link_options( ${TARGET_NAME}
|
||||
INTERFACE
|
||||
-sWASM_BIGINT
|
||||
-sSUPPORT_LONGJMP=wasm
|
||||
-fvisibility=hidden
|
||||
-shared
|
||||
)
|
||||
|
||||
common_compiler_flags( ${TARGET_NAME} )
|
||||
endfunction()
|
||||
63
cmake/windows.cmake
Normal file
63
cmake/windows.cmake
Normal file
@@ -0,0 +1,63 @@
|
||||
#[=======================================================================[.rst:
|
||||
Windows
|
||||
-------
|
||||
|
||||
This file contains functions for options and configuration for targeting the
|
||||
Windows platform
|
||||
|
||||
]=======================================================================]
|
||||
|
||||
function( windows_options )
|
||||
|
||||
option( GODOT_USE_STATIC_CPP "Link MinGW/MSVC C++ runtime libraries statically" ON )
|
||||
|
||||
# The below scons variables are controlled via toolchain files instead
|
||||
# "mingw_prefix" "MinGW prefix"
|
||||
# "use_llvm" "Use the LLVM compiler (MVSC or MinGW depending on the use_mingw flag)"
|
||||
# "use_mingw" "Use the MinGW compiler instead of MSVC - only effective on Windows"
|
||||
endfunction()
|
||||
|
||||
function( windows_generate TARGET_NAME )
|
||||
set( IS_MSVC "$<CXX_COMPILER_ID:MSVC>" )
|
||||
set( IS_CLANG "$<OR:$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:Clang>>" )
|
||||
set( NOT_MSVC "$<NOT:${IS_MSVC}>" )
|
||||
set( STATIC_CPP "$<BOOL:${GODOT_USE_STATIC_CPP}>")
|
||||
set( DISABLE_EXCEPTIONS "$<BOOL:${GODOT_DISABLE_EXCEPTIONS}>")
|
||||
|
||||
set_target_properties( ${TARGET_NAME}
|
||||
PROPERTIES
|
||||
PDB_OUTPUT_DIRECTORY "$<1:${CMAKE_SOURCE_DIR}/bin>"
|
||||
)
|
||||
|
||||
target_compile_definitions( ${TARGET_NAME}
|
||||
PUBLIC
|
||||
WINDOWS_ENABLED
|
||||
$<${IS_MSVC}:
|
||||
TYPED_METHOD_BIND
|
||||
NOMINMAX
|
||||
>
|
||||
)
|
||||
|
||||
target_compile_options( ${TARGET_NAME}
|
||||
PUBLIC
|
||||
$<${IS_MSVC}:
|
||||
$<IF:${STATIC_CPP},/MT,/MD>$<${IS_DEV}:d> # Link microsoft runtime
|
||||
>
|
||||
)
|
||||
target_link_options( ${TARGET_NAME}
|
||||
PUBLIC
|
||||
|
||||
$<${NOT_MSVC}:
|
||||
-Wl,--no-undefined
|
||||
$<${STATIC_CPP}:
|
||||
-static
|
||||
-static-libgcc
|
||||
-static-libstdc++
|
||||
>
|
||||
>
|
||||
|
||||
$<${IS_CLANG}:-lstdc++>
|
||||
)
|
||||
|
||||
common_compiler_flags( ${TARGET_NAME} )
|
||||
endfunction()
|
||||
Reference in New Issue
Block a user