2024-03-20 19:25:56 +00:00
|
|
|
cmake_minimum_required(VERSION 3.13)
|
2021-12-24 00:29:21 +00:00
|
|
|
project(godot-cpp-test)
|
|
|
|
|
2022-12-13 23:40:17 +00:00
|
|
|
set(GODOT_GDEXTENSION_DIR ../gdextension/ CACHE STRING "Path to GDExtension interface header directory")
|
2022-01-23 18:54:51 +00:00
|
|
|
set(CPP_BINDINGS_PATH ../ CACHE STRING "Path to C++ bindings")
|
2021-12-24 00:29:21 +00:00
|
|
|
|
|
|
|
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
2022-01-23 18:54:51 +00:00
|
|
|
set(TARGET_PATH x11)
|
2021-12-24 00:29:21 +00:00
|
|
|
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
2022-01-23 18:54:51 +00:00
|
|
|
set(TARGET_PATH win64)
|
2021-12-24 00:29:21 +00:00
|
|
|
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
|
2022-07-20 08:01:47 +00:00
|
|
|
set(TARGET_PATH macos)
|
2021-12-24 00:29:21 +00:00
|
|
|
else()
|
2022-01-23 18:54:51 +00:00
|
|
|
message(FATAL_ERROR "Not implemented support for ${CMAKE_SYSTEM_NAME}")
|
2021-12-24 00:29:21 +00:00
|
|
|
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++
|
2023-08-16 09:47:19 +00:00
|
|
|
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /WX") # /GF /MP
|
2022-01-23 18:54:51 +00:00
|
|
|
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /DTYPED_METHOD_BIND")
|
2021-12-24 00:29:21 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2022-03-15 09:18:33 +00:00
|
|
|
# Disable conversion warning, truncation, unreferenced var, signed mismatch
|
2021-12-24 00:29:21 +00:00
|
|
|
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /wd4244 /wd4305 /wd4101 /wd4018 /wd4267")
|
|
|
|
|
2022-09-11 11:12:44 +00:00
|
|
|
add_definitions(-DNOMINMAX)
|
2021-12-24 00:29:21 +00:00
|
|
|
|
|
|
|
# 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()
|
|
|
|
|
2023-08-16 09:47:19 +00:00
|
|
|
# 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 OFF "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()
|
|
|
|
|
2021-12-24 00:29:21 +00:00
|
|
|
# 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
|
2022-01-23 18:54:51 +00:00
|
|
|
PRIVATE
|
|
|
|
${CPP_BINDINGS_PATH}/include
|
2022-12-13 23:40:17 +00:00
|
|
|
${CPP_BINDINGS_PATH}/gen/include
|
|
|
|
${GODOT_GDEXTENSION_DIR}
|
2021-12-24 00:29:21 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Create the correct name (godot.os.build_type.system_bits)
|
|
|
|
# Synchronized with godot-cpp's CMakeLists.txt
|
|
|
|
|
|
|
|
set(BITS 32)
|
|
|
|
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
2022-01-23 18:54:51 +00:00
|
|
|
set(BITS 64)
|
2021-12-24 00:29:21 +00:00
|
|
|
endif(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
|
|
|
|
|
|
|
if(CMAKE_BUILD_TYPE MATCHES Debug)
|
2022-01-23 18:54:51 +00:00
|
|
|
set(GODOT_CPP_BUILD_TYPE Debug)
|
2021-12-24 00:29:21 +00:00
|
|
|
else()
|
2022-01-23 18:54:51 +00:00
|
|
|
set(GODOT_CPP_BUILD_TYPE Release)
|
2021-12-24 00:29:21 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
string(TOLOWER ${CMAKE_SYSTEM_NAME} SYSTEM_NAME)
|
|
|
|
string(TOLOWER ${GODOT_CPP_BUILD_TYPE} BUILD_TYPE)
|
|
|
|
|
|
|
|
if(ANDROID)
|
2022-01-23 18:54:51 +00:00
|
|
|
# Added the android abi after system name
|
|
|
|
set(SYSTEM_NAME ${SYSTEM_NAME}.${ANDROID_ABI})
|
2021-12-24 00:29:21 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(CMAKE_VERSION VERSION_GREATER "3.13")
|
2022-01-23 18:54:51 +00:00
|
|
|
target_link_directories(${PROJECT_NAME}
|
|
|
|
PRIVATE
|
|
|
|
${CPP_BINDINGS_PATH}/bin/
|
|
|
|
)
|
|
|
|
|
|
|
|
target_link_libraries(${PROJECT_NAME}
|
|
|
|
godot-cpp.${SYSTEM_NAME}.${BUILD_TYPE}$<$<NOT:$<PLATFORM_ID:Android>>:.${BITS}>
|
|
|
|
)
|
2021-12-24 00:29:21 +00:00
|
|
|
else()
|
2022-01-23 18:54:51 +00:00
|
|
|
target_link_libraries(${PROJECT_NAME}
|
|
|
|
${CPP_BINDINGS_PATH}/bin/libgodot-cpp.${SYSTEM_NAME}.${BUILD_TYPE}$<$<NOT:$<PLATFORM_ID:Android>>:.${BITS}>.a
|
|
|
|
)
|
2021-12-24 00:29:21 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# 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})
|
|
|
|
|
|
|
|
set_property(TARGET ${PROJECT_NAME} PROPERTY OUTPUT_NAME "gdexample")
|