mirror of
https://github.com/godotengine/godot-cpp.git
synced 2026-01-01 05:48:37 +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:
@@ -1,144 +1,67 @@
|
||||
cmake_minimum_required(VERSION 3.13)
|
||||
project(godot-cpp-test)
|
||||
# Testing Extension
|
||||
# This is only linked to the template_release config.
|
||||
# so it requires the template_release version of godot to run.
|
||||
|
||||
set(GODOT_GDEXTENSION_DIR ../gdextension/ CACHE STRING "Path to GDExtension interface header directory")
|
||||
set(CPP_BINDINGS_PATH ../ CACHE STRING "Path to C++ bindings")
|
||||
add_library( godot-cpp-test SHARED EXCLUDE_FROM_ALL )
|
||||
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||
set(TARGET_PATH x11)
|
||||
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
||||
set(TARGET_PATH win64)
|
||||
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
|
||||
set(TARGET_PATH macos)
|
||||
else()
|
||||
message(FATAL_ERROR "Not implemented support for ${CMAKE_SYSTEM_NAME}")
|
||||
endif()
|
||||
|
||||
# Change the output directory to the bin directory
|
||||
set(BUILD_PATH ${CMAKE_SOURCE_DIR}/bin/${TARGET_PATH})
|
||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${BUILD_PATH}")
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${BUILD_PATH}")
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${BUILD_PATH}")
|
||||
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${BUILD_PATH}")
|
||||
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${BUILD_PATH}")
|
||||
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG "${BUILD_PATH}")
|
||||
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE "${BUILD_PATH}")
|
||||
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${BUILD_PATH}")
|
||||
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${BUILD_PATH}")
|
||||
|
||||
# Set the c++ standard to c++17
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
|
||||
set(GODOT_COMPILE_FLAGS )
|
||||
set(GODOT_LINKER_FLAGS )
|
||||
|
||||
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
||||
# using Visual Studio C++
|
||||
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /WX") # /GF /MP
|
||||
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /DTYPED_METHOD_BIND")
|
||||
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /utf-8")
|
||||
|
||||
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
|
||||
STRING(REGEX REPLACE "/RTC(su|[1su])" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
string(REPLACE "/RTC1" "" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
|
||||
endif(CMAKE_BUILD_TYPE MATCHES Debug)
|
||||
|
||||
# Disable conversion warning, truncation, unreferenced var, signed mismatch
|
||||
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /wd4244 /wd4305 /wd4101 /wd4018 /wd4267")
|
||||
|
||||
add_definitions(-DNOMINMAX)
|
||||
|
||||
# Unkomment for warning level 4
|
||||
#if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
|
||||
# string(REGEX REPLACE "/W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
#endif()
|
||||
|
||||
else()
|
||||
|
||||
set(GODOT_LINKER_FLAGS "-static-libgcc -static-libstdc++ -Wl,-R,'$$ORIGIN'")
|
||||
|
||||
set(GODOT_COMPILE_FLAGS "-fPIC -g -Wwrite-strings")
|
||||
|
||||
if(CMAKE_BUILD_TYPE MATCHES Debug)
|
||||
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -fno-omit-frame-pointer -O0")
|
||||
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).
|
||||
option(GODOT_DISABLE_EXCEPTIONS ON "Force disabling exception handling code")
|
||||
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()
|
||||
|
||||
# Get Sources
|
||||
file(GLOB_RECURSE SOURCES src/*.c**)
|
||||
file(GLOB_RECURSE HEADERS include/*.h**)
|
||||
|
||||
# Define our godot-cpp library
|
||||
add_library(${PROJECT_NAME} SHARED ${SOURCES} ${HEADERS})
|
||||
|
||||
target_include_directories(${PROJECT_NAME} SYSTEM
|
||||
PRIVATE
|
||||
${CPP_BINDINGS_PATH}/include
|
||||
${CPP_BINDINGS_PATH}/gen/include
|
||||
${GODOT_GDEXTENSION_DIR}
|
||||
target_sources( godot-cpp-test
|
||||
PRIVATE
|
||||
src/example.cpp
|
||||
src/example.h
|
||||
src/register_types.cpp
|
||||
src/register_types.h
|
||||
src/tests.h
|
||||
)
|
||||
|
||||
# Create the correct name (godot.os.build_type.system_bits)
|
||||
# Synchronized with godot-cpp's CMakeLists.txt
|
||||
set( TEST_TARGET "template_debug" CACHE STRING "Which godot-cpp::target to link against" )
|
||||
set_property( CACHE TEST_TARGET PROPERTY STRINGS "template_debug;template_release;editor" )
|
||||
|
||||
set(BITS 32)
|
||||
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
set(BITS 64)
|
||||
endif(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
target_link_libraries( godot-cpp-test
|
||||
PRIVATE
|
||||
godot-cpp::${TEST_TARGET} )
|
||||
|
||||
if(CMAKE_BUILD_TYPE MATCHES Debug)
|
||||
set(GODOT_CPP_BUILD_TYPE Debug)
|
||||
else()
|
||||
set(GODOT_CPP_BUILD_TYPE Release)
|
||||
endif()
|
||||
### Get useful properties of the library
|
||||
get_target_property( GODOT_PLATFORM godot-cpp::${TEST_TARGET} GODOT_PLATFORM )
|
||||
get_target_property( GODOT_TARGET godot-cpp::${TEST_TARGET} GODOT_TARGET )
|
||||
get_target_property( GODOT_ARCH godot-cpp::${TEST_TARGET} GODOT_ARCH )
|
||||
|
||||
string(TOLOWER ${CMAKE_SYSTEM_NAME} SYSTEM_NAME)
|
||||
string(TOLOWER ${GODOT_CPP_BUILD_TYPE} BUILD_TYPE)
|
||||
set( OUTPUT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/project/bin/" )
|
||||
|
||||
if(ANDROID)
|
||||
# Added the android abi after system name
|
||||
set(SYSTEM_NAME ${SYSTEM_NAME}.${ANDROID_ABI})
|
||||
endif()
|
||||
set_target_properties( godot-cpp-test
|
||||
PROPERTIES
|
||||
CXX_STANDARD 17
|
||||
CXX_EXTENSIONS OFF
|
||||
CXX_VISIBILITY_PRESET ${GODOT_SYMBOL_VISIBILITY}
|
||||
|
||||
if(CMAKE_VERSION VERSION_GREATER "3.13")
|
||||
target_link_directories(${PROJECT_NAME}
|
||||
PRIVATE
|
||||
${CPP_BINDINGS_PATH}/bin/
|
||||
)
|
||||
POSITION_INDEPENDENT_CODE ON
|
||||
BUILD_RPATH_USE_ORIGIN ON
|
||||
LINK_SEARCH_START_STATIC ON
|
||||
LINK_SEARCH_END_STATIC ON
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
godot-cpp.${SYSTEM_NAME}.${BUILD_TYPE}$<$<NOT:$<PLATFORM_ID:Android>>:.${BITS}>
|
||||
)
|
||||
else()
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
${CPP_BINDINGS_PATH}/bin/libgodot-cpp.${SYSTEM_NAME}.${BUILD_TYPE}$<$<NOT:$<PLATFORM_ID:Android>>:.${BITS}>.a
|
||||
)
|
||||
endif()
|
||||
# NOTE: Wrapping the output variables inside a generator expression
|
||||
# prevents msvc generator from adding addition Config Directories
|
||||
LIBRARY_OUTPUT_DIRECTORY "$<1:${OUTPUT_DIR}>"
|
||||
RUNTIME_OUTPUT_DIRECTORY "$<1:${OUTPUT_DIR}>"
|
||||
PDB_OUTPUT_DIRECTORY "$<1:${OUTPUT_DIR}>" #MSVC Only, ignored on other platforms
|
||||
|
||||
# Add the compile flags
|
||||
set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY COMPILE_FLAGS ${GODOT_COMPILE_FLAGS})
|
||||
set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY LINK_FLAGS ${GODOT_LINKER_FLAGS})
|
||||
PREFIX "lib"
|
||||
OUTPUT_NAME "gdexample.${GODOT_PLATFORM}.${GODOT_TARGET}.${GODOT_ARCH}"
|
||||
)
|
||||
|
||||
set_property(TARGET ${PROJECT_NAME} PROPERTY OUTPUT_NAME "gdexample")
|
||||
if( CMAKE_SYSTEM_NAME STREQUAL Darwin )
|
||||
get_target_property( OSX_ARCH godot-cpp::${TEST_TARGET} OSX_ARCHITECTURES )
|
||||
|
||||
set( OUTPUT_DIR "${OUTPUT_DIR}/libgdexample.macos.${TEST_TARGET}.framework")
|
||||
|
||||
set_target_properties( godot-cpp-test
|
||||
PROPERTIES
|
||||
LIBRARY_OUTPUT_DIRECTORY "$<1:${OUTPUT_DIR}>"
|
||||
RUNTIME_OUTPUT_DIRECTORY "$<1:${OUTPUT_DIR}>"
|
||||
|
||||
OUTPUT_NAME "gdexample.macos.${TEST_TARGET}"
|
||||
SUFFIX ""
|
||||
|
||||
#macos options
|
||||
OSX_ARCHITECTURES "${OSX_ARCH}"
|
||||
)
|
||||
endif ()
|
||||
|
||||
Reference in New Issue
Block a user