Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.1: Backports 2 #788

Open
wants to merge 13 commits into
base: 2.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 54 additions & 54 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,46 +14,48 @@
## See the License for the specific language governing permissions and
## limitations under the License.
##
CMAKE_MINIMUM_REQUIRED(VERSION 3.20)
CMAKE_MINIMUM_REQUIRED(VERSION 3.20 FATAL_ERROR)

SET(GDEXTENSION_LIB_NAME orchestrator)
SET(GDEXTENSION_LIB_PATH "${CMAKE_CURRENT_SOURCE_DIR}/project/addons/orchestrator")

# This doesn't work for editor plugins
# ADD_COMPILE_DEFINITIONS(HOT_RELOAD_ENABLED)
add_compile_definitions(TOOLS_ENABLED)

OPTION(
AUTOFORMAT_SRC_ON_CONFIGURE
"If enabled, clang-format will be used to format all sources in src/ during configuration"
OFF
)
# Configurable options
OPTION(AUTOFORMAT_SRC_ON_CONFIGURE "If enabled, clang-format will be used to format all sources in /src during configuration" OFF)

# Set basic CMAKE properties
SET(CMAKE_CXX_STANDARD 20)
SET(CMAKE_CXX_EXTENSIONS ON)
SET(CMAKE_CXX_STANDARD_REQUIRED ON)
SET(CMAKE_COLOR_DIAGNOSTICS ON)
SET(CMAKE_MESSAGE_LOG_LEVEL STATUS)

# Get the current repository Git commit hash
# This is used when creating the data from VERSION to show the commit hash in the about box
FIND_PACKAGE(Git QUIET)
IF(GIT_FOUND)
IF (GIT_FOUND)
EXECUTE_PROCESS(
COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
ELSE()
SET(GIT_COMMIT_HASH "<Unknown>")
ENDIF()
OUTPUT_STRIP_TRAILING_WHITESPACE)

INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/_generated)
EXECUTE_PROCESS(
COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/extern/godot-cpp"
OUTPUT_VARIABLE GODOT_CPP_GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE)
ELSE ()
# In this case the about box will simply show an unknown git commit
SET(GIT_COMMIT_HASH "<Unknown>")
SET(GODOT_CPP_GIT_COMMIT_HASH "<Unknown>")
ENDIF ()

# Setup the CMAKE_MODULE_PATH
LIST(APPEND CMAKE_MODULE_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/"
"${CMAKE_CURRENT_SOURCE_DIR}/extern/godot-cpp/cmake/"
)
"${CMAKE_CURRENT_SOURCE_DIR}/extern/godot-cpp/cmake/")

# Include and execute various CMAKE modules
INCLUDE(generate-authors)
INCLUDE(generate-license)
INCLUDE(generate-version)
Expand All @@ -62,20 +64,33 @@ INCLUDE(godot-extension-db-generator)
INCLUDE(godot-docs-generator)

# Generation steps
GENERATE_AUTHORS()
GENERATE_LICENSE()
GENERATE_VERSION()
GENERATE_AUTHORS()
GENERATE_DONORS()
GENERATE_GODOT_EXTENSION_DB()
GENERATE_GODOT_DOCUMENTATION()

# Configure project
PROJECT("${GDEXTENSION_LIB_NAME}" LANGUAGES C CXX VERSION ${RESOLVED_VERSION})

# Generate library resource
IF (WIN32)
SET(win32_product_name "${RESOLVED_VERSION_NAME}")
SET(win32_file_version "${PROJECT_VERSION_MAJOR},${PROJECT_VERSION_MINOR},${PROJECT_VERSION_PATCH},0")
SET(win32_product_version "${PROJECT_VERSION_MAJOR},${PROJECT_VERSION_MINOR},${PROJECT_VERSION_PATCH},0")
SET(win32_file_description "Godot ${win32_product_name} Plug-in")
CONFIGURE_FILE(cmake/templates/windows.rc.in ${CMAKE_CURRENT_BINARY_DIR}/_generated/version.rc @ONLY)
ENDIF ()

# Orchestrator is an editor plug-in, force TOOLS_ENABLED
ADD_COMPILE_DEFINITIONS(TOOLS_ENABLED)

# MacOS universal binary support
IF (APPLE)
SET(CMAKE_OSX_ARCHITECTURES "x86_64;arm64" CACHE STRING "Build architectures for OSX" FORCE)
ENDIF ()

PROJECT("${GDEXTENSION_LIB_NAME}" LANGUAGES C CXX VERSION ${RESOLVED_VERSION})

# Compiler Identification
SET(compiler_is_clang "$<OR:$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:Clang>>")
SET(compiler_is_gnu "$<CXX_COMPILER_ID:GNU>")
Expand All @@ -91,7 +106,8 @@ FILE(GLOB_RECURSE gdext_sources
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.[hc]pp"
# Includes the generated doc data from /doc_classes
"${CMAKE_BINARY_DIR}/_generated/*.cpp"
)
# Include windows version resource, if exists
"${CMAKE_CURRENT_BINARY_DIR}/_generated/version.rc")

# GDExtension library
ADD_LIBRARY(${PROJECT_NAME} SHARED ${gdext_sources})
Expand Down Expand Up @@ -132,17 +148,16 @@ TARGET_COMPILE_OPTIONS(${PROJECT_NAME} PUBLIC
$<$<CONFIG:Release>:
-O3
>
>
)
>)

find_program(ccache_exe ccache)
if (ccache_exe)
set(CMAKE_VS_GLOBALS
"TrackFileAccess=false"
"UseMultiToolTask=true"
"DebugInformationFormat=OldStyle"
)
endif()
IF (ccache_exe)
SET(CMAKE_VS_GLOBALS "TrackFileAccess=false" "UseMultiToolTask=true" "DebugInformationFormat=OldStyle")
ENDIF ()

# Add the special "_generated" directory to the include list
# This is where the generator CMAKE module steps creates automated files
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/_generated)

# Include directories for GDExtension library
TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src")
Expand All @@ -157,20 +172,18 @@ IF (NOT APPLE)
$<$<CONFIG:Release>:
$<$<PLATFORM_ID:Android>:-s>
>
>
)
>)
ENDIF ()

if (AUTOFORMAT_SRC_ON_CONFIGURE MATCHES ON)
IF (AUTOFORMAT_SRC_ON_CONFIGURE MATCHES ON)
include(clang-format)
ENDIF ()

# Dependency linking
TARGET_LINK_LIBRARIES(${PROJECT_NAME}
PUBLIC godot::cpp
)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} PUBLIC godot::cpp)

SET(GDEXTENSION_LIB_PREFIX "")

IF (NOT ANDROID)
IF (CMAKE_SIZEOF_VOID_P EQUAL 8)
SET(system_bits 64)
Expand All @@ -186,20 +199,7 @@ ELSE ()
ENDIF ()
ENDIF ()

STRING(TOLOWER "${PROJECT_NAME}.${CMAKE_SYSTEM_NAME}.${system_bits}.${CMAKE_BUILD_TYPE}" gde_lib_name)

# Generate library resource
IF(WIN32)
SET(win32_product_name "${RESOLVED_VERSION_NAME}")
SET(win32_file_version "${PROJECT_VERSION_MAJOR},${PROJECT_VERSION_MINOR},${PROJECT_VERSION_PATCH},0")
SET(win32_product_version "${PROJECT_VERSION_MAJOR},${PROJECT_VERSION_MINOR},${PROJECT_VERSION_PATCH},0")
SET(win32_file_description "Godot ${win32_product_name}")
CONFIGURE_FILE(cmake/windows.rc.in ${CMAKE_CURRENT_BINARY_DIR}/_generated/version.rc @ONLY)
ENDIF()

IF (WIN32)
LIST(APPEND gdext_sources "${CMAKE_CURRENT_BINARY_DIR}/_generated/version.rc")
ENDIF()
STRING(TOLOWER "${PROJECT_NAME}.${CMAKE_SYSTEM_NAME}.${system_bits}.${CMAKE_BUILD_TYPE}" GDEXTENSION_LIB_NAME)

SET_TARGET_PROPERTIES(${PROJECT_NAME}
PROPERTIES
Expand All @@ -212,8 +212,8 @@ SET_TARGET_PROPERTIES(${PROJECT_NAME}
RUNTIME_OUTPUT_DIRECTORY "${GDEXTENSION_LIB_PATH}"
CMAKE_PDB_OUTPUT_DIRECTORY "${GDEXTENSION_LIB_PATH}"
CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY "${GDEXTENSION_LIB_PATH}"
OUTPUT_NAME "${gde_lib_name}"
)
OUTPUT_NAME "${GDEXTENSION_LIB_NAME}")

INCLUDE(cmake-utils)

PRINT_PROJECT_VARIABLES()
52 changes: 25 additions & 27 deletions cmake/clang-format.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,31 @@
## See the License for the specific language governing permissions and
## limitations under the License.
##
INCLUDE_GUARD()

find_program(CLANG_FORMAT_PROGRAM NAMES clang-format)
IF (CLANG_FORMAT_PROGRAM)
EXECUTE_PROCESS(
COMMAND "${CLANG_FORMAT_PROGRAM}" --version
OUTPUT_VARIABLE CLANG_FORMAT_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)

#if (CLANG_FORMAT_PROGRAM)
# execute_process(
# COMMAND "${CLANG_FORMAT_PROGRAM}" --version
# OUTPUT_VARIABLE CLANG_FORMAT_VERSION
# OUTPUT_STRIP_TRAILING_WHITESPACE
# )
#
# message("Using clang-format: ${CLANG_FORMAT_PROGRAM} (${CLANG_FORMAT_VERSION})")
#
# file(GLOB_RECURSE
# format_src_list
# RELATIVE
# "${CMAKE_CURRENT_SOURCE_DIR}"
# "src/*.[hc]"
# "src/*.[hc]pp"
# )
#
# foreach (_src_file ${format_src_list})
# message(" formatting => ${_src_file}")
# execute_process(
# COMMAND "${CLANG_FORMAT_PROGRAM}" --style=file -i "${_src_file}"
# WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
# )
# endforeach ()
#
# unset(CLANG_FORMAT_VERSION)
#endif ()
MESSAGE("Using clang-format: ${CLANG_FORMAT_PROGRAM} (${CLANG_FORMAT_VERSION})")

FILE(GLOB_RECURSE
format_src_list
RELATIVE
"${CMAKE_CURRENT_SOURCE_DIR}"
"src/*.[hc]"
"src/*.[hc]pp"
)

FOREACH (_src_file ${format_src_list})
MESSAGE(" formatting => ${_src_file}")
EXECUTE_PROCESS(
COMMAND "${CLANG_FORMAT_PROGRAM}" --style=file -i "${_src_file}"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
ENDFOREACH ()

UNSET(CLANG_FORMAT_VERSION)
ENDIF ()
6 changes: 6 additions & 0 deletions cmake/cmake-utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ FUNCTION( PRINT_PROJECT_VARIABLES )
MESSAGE( NOTICE " CMAKE_MINIMUM_REQUIRED_VERSION:..........: " ${CMAKE_MINIMUM_REQUIRED_VERSION} )
MESSAGE( NOTICE " VCPKG_TARGET_TRIPLET.....................: " ${VCPKG_TARGET_TRIPLET} )
MESSAGE( NOTICE " CMAKE_DEBUG_POSTFIX......................: " ${CMAKE_DEBUG_POSTFIX} )
MESSAGE( NOTICE " system_bits..............................: " ${system_bits} )
MESSAGE( NOTICE " GDEXTENSION_LIB_NAME.....................: " ${GDEXTENSION_LIB_NAME} )
MESSAGE( NOTICE " RESOLVED_VERSION.........................: " ${RESOLVED_VERSION} )
MESSAGE( NOTICE " GIT_COMMIT_HASH..........................: " ${GIT_COMMIT_HASH} )
MESSAGE( NOTICE " GODOT_CPP_GIT_COMMIT_HASH................: " ${GODOT_CPP_GIT_COMMIT_HASH} )
MESSAGE( NOTICE "" )
MESSAGE( NOTICE "CMake Paths" )
MESSAGE( NOTICE " CMAKE_CURRENT_SOURCE_DIR.................: " ${CMAKE_CURRENT_SOURCE_DIR} )
Expand All @@ -118,7 +122,9 @@ FUNCTION( PRINT_PROJECT_VARIABLES )
MESSAGE( NOTICE " CLANG_FORMAT_PROGRAM:....................: " ${CLANG_FORMAT_PROGRAM} )
MESSAGE( NOTICE " SCONS_PROGRAM:...........................: " ${SCONS_PROGRAM} )
MESSAGE( NOTICE " CMAKE_CXX_COMPILER:......................: " ${CMAKE_CXX_COMPILER} )
MESSAGE( NOTICE " CMAKE_CXX_FLAGS..........................: " ${CMAKE_CXX_FLAGS} )
MESSAGE( NOTICE " CMAKE_LINKER:............................: " ${CMAKE_LINKER} )
MESSAGE( NOTICE " CMAKE_EXE_LINKER_FLAGS...................: " ${CMAKE_EXE_LINKER_FLAGS} )
MESSAGE( NOTICE " CMAKE_BUILD_TOOL:........................: " ${CMAKE_BUILD_TOOL} )
MESSAGE( NOTICE " vcpkg_executable:........................: " ${vcpkg_executable} )
MESSAGE( NOTICE " godot_debug_editor_executable:...........: " ${godot_debug_editor_executable} )
Expand Down
3 changes: 2 additions & 1 deletion cmake/generate-authors.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
## See the License for the specific language governing permissions and
## limitations under the License.
##
INCLUDE_GUARD()

INCLUDE(markdown-utils)

Expand All @@ -35,5 +36,5 @@ FUNCTION( GENERATE_AUTHORS )
ENDIF()
MATH(EXPR index "${index} + 1")
ENDWHILE()
CONFIGURE_FILE(cmake/authors.h.in _generated/authors.gen.h @ONLY)
CONFIGURE_FILE(cmake/templates/authors.h.in _generated/authors.gen.h @ONLY)
ENDFUNCTION()
3 changes: 2 additions & 1 deletion cmake/generate-donors.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
## See the License for the specific language governing permissions and
## limitations under the License.
##
INCLUDE_GUARD()

INCLUDE(markdown-utils)

Expand All @@ -37,5 +38,5 @@ FUNCTION( GENERATE_DONORS )
ENDIF()
MATH(EXPR index "${index} + 1")
ENDWHILE()
CONFIGURE_FILE(cmake/donors.h.in _generated/donors.gen.h @ONLY)
CONFIGURE_FILE(cmake/templates/donors.h.in _generated/donors.gen.h @ONLY)
ENDFUNCTION()
3 changes: 2 additions & 1 deletion cmake/generate-license.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
## See the License for the specific language governing permissions and
## limitations under the License.
##
INCLUDE_GUARD()

FUNCTION( GENERATE_LICENSE )
FILE(READ LICENSE license_text)
STRING(REPLACE "\"" "\\042" license_text_formatted "${license_text}")
STRING(REPLACE "\n" "\\n\"\n \"" license_text_formatted "${license_text_formatted}")
CONFIGURE_FILE(cmake/license.h.in _generated/license.gen.h @ONLY)
CONFIGURE_FILE(cmake/templates/license.h.in _generated/license.gen.h @ONLY)
ENDFUNCTION()

3 changes: 2 additions & 1 deletion cmake/generate-version.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
## See the License for the specific language governing permissions and
## limitations under the License.
##
INCLUDE_GUARD()

FUNCTION( GENERATE_VERSION )
FILE(READ VERSION version_text)
Expand Down Expand Up @@ -54,7 +55,7 @@ FUNCTION( GENERATE_VERSION )
ENDFOREACH()
PAD_STRING("VERSION_HASH" ${version_max_length} version_hash)
SET(version_formatted "${version_formatted}#define ${version_hash}\t\"${GIT_COMMIT_HASH}\"")
CONFIGURE_FILE(cmake/version.h.in _generated/version.gen.h @ONLY)
CONFIGURE_FILE(cmake/templates/version.h.in _generated/version.gen.h @ONLY)

# Pass certain values up to the parent scope
# These are used to create windows DLL resource file details
Expand Down
2 changes: 1 addition & 1 deletion cmake/godot-docs-generator.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ FUNCTION( GENERATE_GODOT_DOCUMENTATION )
STRING(JOIN "," DOC_DATA_CPP_STR ${DOC_DATA_CPP_FILE})
# Run python to generate the doc_data.cpp file
EXECUTE_PROCESS(
COMMAND cmd /c py ${CMAKE_CURRENT_SOURCE_DIR}/cmake/generate_godot_docs.py ${DOC_DATA_CPP_STR} ${XML_FILES_STR}
COMMAND cmd /c py ${CMAKE_CURRENT_SOURCE_DIR}/cmake/scripts/generate_godot_docs.py ${DOC_DATA_CPP_STR} ${XML_FILES_STR}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
ENDFUNCTION()
7 changes: 4 additions & 3 deletions cmake/godot-extension-db-generator.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
## See the License for the specific language governing permissions and
## limitations under the License.
##
INCLUDE_GUARD()

FUNCTION( GENERATE_GODOT_EXTENSION_DB )
EXECUTE_PROCESS(
COMMAND cmd /c py ${CMAKE_CURRENT_SOURCE_DIR}/cmake/generate_godot_extension_db.py ${CMAKE_CURRENT_SOURCE_DIR}/extern/godot-cpp/gdextension/extension_api.json
COMMAND cmd /c py ${CMAKE_CURRENT_SOURCE_DIR}/cmake/scripts/generate_godot_extension_db.py ${CMAKE_CURRENT_SOURCE_DIR}/extern/godot-cpp/gdextension/extension_api.json
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE godot_extension_db
)
Expand All @@ -26,7 +27,7 @@ FUNCTION( GENERATE_GODOT_EXTENSION_DB )
STRING(SUBSTRING "${godot_extension_db}" 0 ${pos} godot_extension_db_hpp)
MATH(EXPR pos "${pos} + 5")
STRING(SUBSTRING "${godot_extension_db}" ${pos} -1 godot_extension_db_cpp)
CONFIGURE_FILE(cmake/extension_db.h.in ${CMAKE_CURRENT_SOURCE_DIR}/src/api/extension_db.h @ONLY NEWLINE_STYLE LF)
CONFIGURE_FILE(cmake/extension_db.cpp.in ${CMAKE_CURRENT_SOURCE_DIR}/src/api/extension_db.cpp @ONLY NEWLINE_STYLE LF)
CONFIGURE_FILE(cmake/templates/extension_db.h.in ${CMAKE_CURRENT_SOURCE_DIR}/src/api/extension_db.h @ONLY NEWLINE_STYLE LF)
CONFIGURE_FILE(cmake/templates/extension_db.cpp.in ${CMAKE_CURRENT_SOURCE_DIR}/src/api/extension_db.cpp @ONLY NEWLINE_STYLE LF)
ENDIF()
ENDFUNCTION()
1 change: 1 addition & 0 deletions cmake/markdown-utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
## See the License for the specific language governing permissions and
## limitations under the License.
##
INCLUDE_GUARD()

FUNCTION( TRIM text out )
STRING(REGEX REPLACE "^[ \t\n\r]+" "" text "${text}")
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion cmake/windows.rc.in → cmake/templates/windows.rc.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <windows.h>
#include <winres.h>

VS_VERSION_INFO VERSIONINFO
FILEVERSION @win32_file_version@
Expand Down
Loading
Loading