2024-01-09 21:35:20 +00:00
|
|
|
# Main cmake arguments
|
|
|
|
#
|
|
|
|
# CMAKE_BUILD_TYPE Compilation target (Debug, Release, RelWithDebInfo, MinSizeRel)
|
|
|
|
#
|
|
|
|
# CMAKE_CONFIGURATION_TYPES Set to "Debug;Release;RelWithDebInfo;MinSizeRel"
|
|
|
|
# if not all needed configurations are created in multi-config generator
|
|
|
|
# (Setting it in script causes crash on Ninja Multi-Config)
|
|
|
|
#
|
|
|
|
# TARGET Godot build target (EDITOR, TEMPLATE_DEBUG, TEMPLATE_RELEASE)
|
2023-12-31 16:17:28 +00:00
|
|
|
#
|
|
|
|
# PLATFORM: Platform type (LINUX, MACOS, WINDOWS, ANDROID, IOS, WEB)
|
|
|
|
# Auto-detected by default depending on current OS or chosen toolchain
|
|
|
|
#
|
|
|
|
# other global and chosen platform-specific options:
|
|
|
|
#
|
2024-01-09 21:35:20 +00:00
|
|
|
# cmake -LH <build_dir>
|
2023-12-31 16:17:28 +00:00
|
|
|
#
|
2024-01-09 21:35:20 +00:00
|
|
|
# Note: use `-B <build_dir>` option to build in separate directories
|
2023-12-31 16:17:28 +00:00
|
|
|
# for different configurations
|
|
|
|
#
|
2024-01-09 21:35:20 +00:00
|
|
|
# cmake -B build && cmake --build build
|
2021-08-18 14:03:52 +00:00
|
|
|
#
|
2018-12-02 20:07:26 +00:00
|
|
|
# Examples
|
2021-08-18 14:03:52 +00:00
|
|
|
#
|
2023-12-31 16:17:28 +00:00
|
|
|
# Builds default configuration:
|
2024-01-09 21:35:20 +00:00
|
|
|
# cmake . -Bbuild
|
|
|
|
# cmake --build build
|
2021-08-18 14:03:52 +00:00
|
|
|
#
|
2023-12-31 16:17:28 +00:00
|
|
|
# Builds template_release version
|
|
|
|
#
|
2024-01-09 21:35:20 +00:00
|
|
|
# cmake -DTARGET=TEMPLATE_RELEASE -Bbuild
|
|
|
|
# cmake --build build
|
2021-08-18 14:03:52 +00:00
|
|
|
#
|
2024-01-09 21:35:20 +00:00
|
|
|
# Creates multi-config setup and builds Release version (example for Linux)
|
2023-12-31 16:17:28 +00:00
|
|
|
#
|
2024-01-09 21:35:20 +00:00
|
|
|
# cmake -G "Ninja Multi-Config" -Bbuild
|
|
|
|
# cmake --build build --config Release
|
2023-12-31 16:17:28 +00:00
|
|
|
#
|
|
|
|
# Builds web version, using Emscripten toolchain
|
|
|
|
#
|
2024-01-09 21:35:20 +00:00
|
|
|
# cmake --toolchain /usr/lib/emscripten/cmake/Modules/Platform/Emscripten.cmake -Bbuild
|
|
|
|
# cmake --build build
|
2023-12-31 16:17:28 +00:00
|
|
|
#
|
|
|
|
#
|
2018-12-02 20:07:26 +00:00
|
|
|
# Builds an android armeabi-v7a debug version:
|
2023-12-31 16:17:28 +00:00
|
|
|
# cmake --toolchain $ANDROID_NDK/build/cmake/android.toolchain.cmake \
|
2024-01-09 21:35:20 +00:00
|
|
|
# -DANDROID_TOOLCHAIN_NAME=arm-linux-androideabi-4.9 -DANDROID_TOOLCHAIN=clang -DANDROID_PLATFORM=21 -Bbuild
|
|
|
|
# cmake --build build
|
2021-08-18 14:03:52 +00:00
|
|
|
#
|
|
|
|
#
|
2024-01-09 21:35:20 +00:00
|
|
|
# TODO:
|
|
|
|
# Test builds for MacOS/IOS
|
2018-12-02 20:07:26 +00:00
|
|
|
|
2024-01-09 21:35:20 +00:00
|
|
|
cmake_minimum_required(VERSION 3.12)
|
2023-05-06 06:55:41 +00:00
|
|
|
project(godot-cpp LANGUAGES CXX)
|
2018-12-02 20:07:26 +00:00
|
|
|
|
2023-12-31 16:17:28 +00:00
|
|
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")
|
2023-01-19 13:01:50 +00:00
|
|
|
|
2023-12-31 16:17:28 +00:00
|
|
|
# Handles all global and platform-specific variables
|
|
|
|
include(godotcpp)
|
2023-08-16 09:47:19 +00:00
|
|
|
|
2018-12-02 20:07:26 +00:00
|
|
|
# Generate source from the bindings file
|
2021-12-29 14:02:38 +00:00
|
|
|
find_package(Python3 3.4 REQUIRED) # pathlib should be present
|
2020-09-20 10:18:42 +00:00
|
|
|
|
2023-12-31 16:17:28 +00:00
|
|
|
execute_process(COMMAND "${Python3_EXECUTABLE}" "-c" "import binding_generator; binding_generator.print_file_list(\"${GDEXTENSION_API_FILE}\", \"${CMAKE_CURRENT_BINARY_DIR}\", headers=True, sources=True)"
|
2019-04-11 09:56:42 +00:00
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
2021-08-28 22:15:12 +00:00
|
|
|
OUTPUT_VARIABLE GENERATED_FILES_LIST
|
2023-11-11 12:59:33 +00:00
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
2020-02-02 19:47:45 +00:00
|
|
|
)
|
|
|
|
|
2023-12-31 16:17:28 +00:00
|
|
|
string(TOLOWER ${FLOAT_PRECISION} FLOAT_PRECISION_ARG)
|
|
|
|
if(GENERATE_TEMPLATE_GET_NODE)
|
|
|
|
set(GENERATE_BINDING_PARAMETERS "True")
|
|
|
|
else()
|
|
|
|
set(GENERATE_BINDING_PARAMETERS "False")
|
|
|
|
endif()
|
|
|
|
|
2021-08-28 22:15:12 +00:00
|
|
|
add_custom_command(OUTPUT ${GENERATED_FILES_LIST}
|
2023-12-31 16:17:28 +00:00
|
|
|
COMMAND "${Python3_EXECUTABLE}" "-c" "import binding_generator; binding_generator.generate_bindings(\"${GDEXTENSION_API_FILE}\", \"${GENERATE_BINDING_PARAMETERS}\", \"${BITS}\", \"${FLOAT_PRECISION_ARG}\", \"${CMAKE_CURRENT_BINARY_DIR}\")"
|
2020-02-02 19:47:45 +00:00
|
|
|
VERBATIM
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
2023-12-31 16:17:28 +00:00
|
|
|
MAIN_DEPENDENCY ${GDEXTENSION_API_FILE}
|
2020-02-02 19:47:45 +00:00
|
|
|
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/binding_generator.py
|
2021-09-01 21:43:07 +00:00
|
|
|
COMMENT "Generating bindings"
|
2020-02-02 19:47:45 +00:00
|
|
|
)
|
2018-12-02 20:07:26 +00:00
|
|
|
|
|
|
|
# Get Sources
|
2022-12-03 21:43:00 +00:00
|
|
|
file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS src/*.c**)
|
|
|
|
file(GLOB_RECURSE HEADERS CONFIGURE_DEPENDS include/*.h**)
|
2018-12-02 20:07:26 +00:00
|
|
|
|
|
|
|
# Define our godot-cpp library
|
2023-12-31 16:17:28 +00:00
|
|
|
add_library(${PROJECT_NAME} ${GODOT_CPP_LIBRARY_TYPE}
|
2020-02-02 19:47:45 +00:00
|
|
|
${SOURCES}
|
|
|
|
${HEADERS}
|
2021-08-28 22:15:12 +00:00
|
|
|
${GENERATED_FILES_LIST}
|
2020-02-02 19:47:45 +00:00
|
|
|
)
|
2021-09-01 22:54:47 +00:00
|
|
|
add_library(godot::cpp ALIAS ${PROJECT_NAME})
|
2022-12-03 21:43:00 +00:00
|
|
|
|
2023-01-19 02:12:50 +00:00
|
|
|
target_include_directories(${PROJECT_NAME} ${GODOT_CPP_SYSTEM_HEADERS_ATTRIBUTE} PUBLIC
|
2018-12-02 20:07:26 +00:00
|
|
|
include
|
2021-08-18 14:03:52 +00:00
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/gen/include
|
2023-12-31 16:17:28 +00:00
|
|
|
${GDEXTENSION_DIR}
|
2018-12-02 20:07:26 +00:00
|
|
|
)
|
|
|
|
|
2023-12-31 16:17:28 +00:00
|
|
|
target_compile_features(${PROJECT_NAME} PUBLIC
|
|
|
|
cxx_std_17
|
|
|
|
)
|
2018-12-02 20:07:26 +00:00
|
|
|
|
2023-12-31 16:17:28 +00:00
|
|
|
target_compile_options(${PROJECT_NAME} PRIVATE
|
|
|
|
${GODOT_CC_FLAGS}
|
|
|
|
${GODOT_CXX_FLAGS}
|
|
|
|
${GODOT_COMPILE_WARNING_FLAGS}
|
|
|
|
)
|
2018-12-02 20:07:26 +00:00
|
|
|
|
2023-12-31 16:17:28 +00:00
|
|
|
target_link_options(${PROJECT_NAME} PRIVATE ${GODOT_LINK_FLAGS})
|
2022-12-03 21:43:00 +00:00
|
|
|
|
2024-01-09 21:35:20 +00:00
|
|
|
target_compile_definitions(${PROJECT_NAME} PUBLIC ${GODOT_DEFINITIONS})
|
2022-12-03 21:43:00 +00:00
|
|
|
|
|
|
|
set_target_properties(${PROJECT_NAME}
|
|
|
|
PROPERTIES
|
|
|
|
CXX_EXTENSIONS OFF
|
2022-12-23 17:38:35 +00:00
|
|
|
POSITION_INDEPENDENT_CODE ON
|
2022-12-03 21:43:00 +00:00
|
|
|
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin"
|
|
|
|
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin"
|
|
|
|
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin"
|
2023-12-31 16:17:28 +00:00
|
|
|
OUTPUT_NAME "${PROJECT_NAME}${LIBRARY_SUFFIX}"
|
2022-12-03 21:43:00 +00:00
|
|
|
)
|
2024-01-09 21:35:20 +00:00
|
|
|
if(${GODOT_CPP_WARNING_AS_ERROR})
|
|
|
|
set_warning_as_error(${PROJECT_NAME})
|
|
|
|
endif()
|