From fe21845ca0bd6a57360eb0360fdaa86e5f48a6ec Mon Sep 17 00:00:00 2001 From: Vano Date: Sun, 31 Dec 2023 18:17:28 +0200 Subject: [PATCH 1/6] CMake rewrite, reflecting default SCons variables --- CMakeLists.txt | 209 +++++++----------------- cmake/GodotCompilerWarnings.cmake | 38 ++--- cmake/android.cmake | 67 ++++++++ cmake/godotcpp.cmake | 254 ++++++++++++++++++++++++++++++ cmake/ios.cmake | 68 ++++++++ cmake/linux.cmake | 61 +++++++ cmake/macos.cmake | 53 +++++++ cmake/web.cmake | 25 +++ cmake/windows.cmake | 53 +++++++ 9 files changed, 650 insertions(+), 178 deletions(-) create mode 100644 cmake/android.cmake create mode 100644 cmake/godotcpp.cmake create mode 100644 cmake/ios.cmake create mode 100644 cmake/linux.cmake create mode 100644 cmake/macos.cmake create mode 100644 cmake/web.cmake create mode 100644 cmake/windows.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index e7151026..91ba7c49 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,140 +1,79 @@ # cmake arguments -# CMAKE_BUILD_TYPE: Compilation target (Debug or Release defaults to Debug) +# CMAKE_BUILD_TYPE: Compilation target (editor, template_debug, template_release) # -# godot-cpp cmake arguments -# GODOT_GDEXTENSION_DIR: Path to the directory containing GDExtension interface header and API JSON file -# GODOT_CPP_SYSTEM_HEADERS Mark the header files as SYSTEM. This may be useful to supress warnings in projects including this one. -# GODOT_CPP_WARNING_AS_ERROR Treat any warnings as errors -# GODOT_CUSTOM_API_FILE: Path to a custom GDExtension API JSON file (takes precedence over `gdextension_dir`) -# FLOAT_PRECISION: Floating-point precision level ("single", "double") +# PLATFORM: Platform type (LINUX, MACOS, WINDOWS, ANDROID, IOS, WEB) +# Auto-detected by default depending on current OS or chosen toolchain # -# Android cmake arguments -# CMAKE_TOOLCHAIN_FILE: The path to the android cmake toolchain ($ANDROID_NDK/build/cmake/android.toolchain.cmake) -# ANDROID_NDK: The path to the android ndk root folder -# ANDROID_TOOLCHAIN_NAME: The android toolchain (arm-linux-androideabi-4.9 or aarch64-linux-android-4.9 or x86-4.9 or x86_64-4.9) -# ANDROID_PLATFORM: The android platform version (android-23) -# More info here: https://godot.readthedocs.io/en/latest/development/compiling/compiling_for_android.html +# other global and chosen platform-specific options: +# +# cmake -LH +# +# Note: use -Bbuild_dir option to build in separate directories +# for different configurations +# +# cmake -Bbuild && cmake --build build # # Examples # -# Builds a debug version: +# Builds default configuration: # cmake . # cmake --build . # -# Builds a release version with clang -# CC=/usr/bin/clang CXX=/usr/bin/clang++ cmake -DCMAKE_BUILD_TYPE=Release -G "Unix Makefiles" . +# Builds template_release version +# +# cmake -DCMAKE_BUILD_TYPE=template_release . # cmake --build . # +# Creates multi-config setup and builds 2 library versions (example for Linux) +# +# cmake -G "Ninja Multi-Config" . +# cmake --build . --config editor +# cmake --build . --config template_release +# +# Builds web version, using Emscripten toolchain +# +# cmake --toolchain /usr/lib/emscripten/cmake/Modules/Platform/Emscripten.cmake . +# cmake --build . +# +# # Builds an android armeabi-v7a debug version: -# cmake -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake -DANDROID_NDK=$ANDROID_NDK \ -# -DANDROID_TOOLCHAIN_NAME=arm-linux-androideabi-4.9 -DANDROID_PLATFORM=android-23 -DCMAKE_BUILD_TYPE=Debug . +# cmake --toolchain $ANDROID_NDK/build/cmake/android.toolchain.cmake \ +# -DANDROID_TOOLCHAIN_NAME=arm-linux-androideabi-4.9 -DANDROID_TOOLCHAIN=clang -DANDROID_PLATFORM=21 . # cmake --build . # -# Protip -# Generate the buildfiles in a sub directory to not clutter the root directory with build files: -# mkdir build && cd build && cmake -G "Unix Makefiles" .. && cmake --build . # # Todo # Test build for Windows, Mac and mingw. -cmake_minimum_required(VERSION 3.12) +cmake_minimum_required(VERSION 3.24) project(godot-cpp LANGUAGES CXX) -option(GENERATE_TEMPLATE_GET_NODE "Generate a template version of the Node class's get_node." ON) -option(GODOT_CPP_SYSTEM_HEADERS "Expose headers as SYSTEM." ON) -option(GODOT_CPP_WARNING_AS_ERROR "Treat warnings as errors" OFF) +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/") -# Add path to modules -list( APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/" ) - -# Set some helper variables for readability -set( compiler_is_clang "$,$>" ) -set( compiler_is_gnu "$" ) -set( compiler_is_msvc "$" ) - -# Default build type is Debug in the SConstruct -if("${CMAKE_BUILD_TYPE}" STREQUAL "") - set(CMAKE_BUILD_TYPE Debug) -endif() - -if(NOT DEFINED BITS) - set(BITS 32) - if(CMAKE_SIZEOF_VOID_P EQUAL 8) - set(BITS 64) - endif(CMAKE_SIZEOF_VOID_P EQUAL 8) -endif() - -# Input from user for GDExtension interface header and the API JSON file -set(GODOT_GDEXTENSION_DIR "gdextension" CACHE STRING "") -set(GODOT_CUSTOM_API_FILE "" CACHE STRING "") - -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() - -set(FLOAT_PRECISION "single" CACHE STRING "") -if ("${FLOAT_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 - 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) - - 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). -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() +# Handles all global and platform-specific variables +include(godotcpp) # Generate source from the bindings file find_package(Python3 3.4 REQUIRED) # pathlib should be present + +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)" + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT_VARIABLE GENERATED_FILES_LIST + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +string(TOLOWER ${FLOAT_PRECISION} FLOAT_PRECISION_ARG) if(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)" - 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}\", \"${FLOAT_PRECISION}\", \"${CMAKE_CURRENT_BINARY_DIR}\")" + 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}\")" VERBATIM WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - MAIN_DEPENDENCY ${GODOT_GDEXTENSION_API_FILE} + MAIN_DEPENDENCY ${GDEXTENSION_API_FILE} DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/binding_generator.py COMMENT "Generating bindings" ) @@ -144,73 +83,41 @@ 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 +add_library(${PROJECT_NAME} ${GODOT_CPP_LIBRARY_TYPE} ${SOURCES} ${HEADERS} ${GENERATED_FILES_LIST} ) add_library(godot::cpp ALIAS ${PROJECT_NAME}) -include(GodotCompilerWarnings) - -target_compile_features(${PROJECT_NAME} - PRIVATE - cxx_std_17 -) - -target_compile_definitions(${PROJECT_NAME} PUBLIC - $<$: - DEBUG_ENABLED - DEBUG_METHODS_ENABLED - > - $<${compiler_is_msvc}: - TYPED_METHOD_BIND - > -) - -target_link_options(${PROJECT_NAME} PRIVATE - $<$: - -static-libgcc - -static-libstdc++ - -Wl,-R,'$$ORIGIN' - > -) - -# Optionally mark headers as SYSTEM -set(GODOT_CPP_SYSTEM_HEADERS_ATTRIBUTE "") -if (GODOT_CPP_SYSTEM_HEADERS) - set(GODOT_CPP_SYSTEM_HEADERS_ATTRIBUTE SYSTEM) -endif () - target_include_directories(${PROJECT_NAME} ${GODOT_CPP_SYSTEM_HEADERS_ATTRIBUTE} PUBLIC include ${CMAKE_CURRENT_BINARY_DIR}/gen/include - ${GODOT_GDEXTENSION_DIR} + ${GDEXTENSION_DIR} ) -# Add the compile flags -set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY COMPILE_FLAGS ${GODOT_COMPILE_FLAGS}) +target_compile_features(${PROJECT_NAME} PUBLIC + cxx_std_17 +) -# Create the correct name (godot.os.build_type.system_bits) -string(TOLOWER "${CMAKE_SYSTEM_NAME}" SYSTEM_NAME) -string(TOLOWER "${CMAKE_BUILD_TYPE}" BUILD_TYPE) +target_compile_options(${PROJECT_NAME} PRIVATE + ${GODOT_CC_FLAGS} + ${GODOT_CXX_FLAGS} + ${GODOT_COMPILE_WARNING_FLAGS} +) -if(ANDROID) - # Added the android abi after system name - set(SYSTEM_NAME ${SYSTEM_NAME}.${ANDROID_ABI}) +target_link_options(${PROJECT_NAME} PRIVATE ${GODOT_LINK_FLAGS}) - # 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}") -else() - set(OUTPUT_NAME "godot-cpp.${SYSTEM_NAME}.${BUILD_TYPE}.${BITS}") -endif() +target_compile_definitions(${PROJECT_NAME} PRIVATE ${GODOT_DEFINITIONS}) set_target_properties(${PROJECT_NAME} PROPERTIES CXX_EXTENSIONS OFF + COMPILE_WARNING_AS_ERROR ${GODOT_CPP_WARNING_AS_ERROR} POSITION_INDEPENDENT_CODE ON 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}" + OUTPUT_NAME "${PROJECT_NAME}${LIBRARY_SUFFIX}" ) + diff --git a/cmake/GodotCompilerWarnings.cmake b/cmake/GodotCompilerWarnings.cmake index 423e6366..5695e135 100644 --- a/cmake/GodotCompilerWarnings.cmake +++ b/cmake/GodotCompilerWarnings.cmake @@ -1,13 +1,18 @@ +# Set some helper variables for readability +set(compiler_is_clang "$,$>") +set(compiler_is_gnu "$") +set(compiler_is_msvc "$") + # Add warnings based on compiler & version # Set some helper variables for readability -set( compiler_less_than_v8 "$,8>" ) -set( compiler_greater_than_or_equal_v9 "$,9>" ) -set( compiler_greater_than_or_equal_v11 "$,11>" ) -set( compiler_less_than_v11 "$,11>" ) -set( compiler_greater_than_or_equal_v12 "$,12>" ) +set(compiler_less_than_v8 "$,8>") +set(compiler_greater_than_or_equal_v9 "$,9>") +set(compiler_greater_than_or_equal_v11 "$,11>") +set(compiler_less_than_v11 "$,11>") +set(compiler_greater_than_or_equal_v12 "$,12>") # These compiler options reflect what is in godot/SConstruct. -target_compile_options( ${PROJECT_NAME} PRIVATE +list(APPEND GODOT_COMPILE_WARNING_FLAGS # MSVC only $<${compiler_is_msvc}: /W4 @@ -71,24 +76,3 @@ target_compile_options( ${PROJECT_NAME} PRIVATE -Wno-return-type > ) - -# 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> - $<$:-Werror> - ) - endif() -endfunction() - -if ( GODOT_CPP_WARNING_AS_ERROR ) - set_warning_as_error() -endif() diff --git a/cmake/android.cmake b/cmake/android.cmake new file mode 100644 index 00000000..1262e906 --- /dev/null +++ b/cmake/android.cmake @@ -0,0 +1,67 @@ +# Used with android toolchain at $ANDROID_NDK/build/cmake/android.toolchain.cmake + +set(ARCH "arm64" CACHE STRING "Target architecture (arm64, x86_64, arm32, x86_32, CUSTOM") + +if(${ANDROID_PLATFORM} VERSION_LESS 21) + message(FATAL_ERROR "Minimum supported API level is 21 (-DANDROID_PLATFORM=21)") +endif() + +# This must be kept in sync with the value in https://github.com/godotengine/godot/blob/master/platform/android/detect.py#L58. +set(ANDROID_NDK_VERSION_EXPECTED "23.2.8568313") +if(NOT "${ANDROID_NDK_REVISION}" STREQUAL "${ANDROID_NDK_VERSION_EXPECTED}") + message(FATAL_ERROR "Android NDK version '${ANDROID_NDK_VERSION_EXPECTED}' expected, got '${ANDROID_NDK_REVISION}'") +endif() + +string(REGEX MATCH "32$|64$" DEFAULT_BITS "${ARCH}") +set(BITS "${DEFAULT_BITS}" CACHE STRING "Architecture bits. Needs to be set manually for custom architecture") + + +list(APPEND GODOT_DEFINITIONS + ANDROID_ENABLED + UNIX_ENABLED +) + +list(APPEND GODOT_CC_FLAGS + $<$: + --target=armv7a-linux-androideabi${ANDROID_PLATFORM} + -march=armv7-a + + -mfpu=neon + > + $<$: + --target=aarch64-linux-android${ANDROID_PLATFORM} + -march=armv8-a + > + $<$: + --target=i686-linux-android${ANDROID_PLATFORM} + -march=i686 + + -mstackrealign + > + $<$: + --target=x86_64-linux-android${ANDROID_PLATFORM} + -march=x86-64 + > +) + +list(APPEND GODOT_LINK_FLAGS + $<$: + --target=armv7a-linux-androideabi${ANDROID_PLATFORM} + -march=armv7-a + > + $<$: + --target=aarch64-linux-android${ANDROID_PLATFORM} + -march=armv8-a + > + $<$: + --target=i686-linux-android${ANDROID_PLATFORM} + -march=i686 + > + $<$: + --target=x86_64-linux-android${ANDROID_PLATFORM} + -march=x86-64 + > +) + +string(APPEND LIBRARY_SUFFIX ".${ARCH}") + diff --git a/cmake/godotcpp.cmake b/cmake/godotcpp.cmake new file mode 100644 index 00000000..d3b4001f --- /dev/null +++ b/cmake/godotcpp.cmake @@ -0,0 +1,254 @@ +# This file contains variables needed by all platforms + +### Options + +set(CMAKE_CONFIGURATION_TYPES "template_debug;editor;template_release") + +if("${CMAKE_BUILD_TYPE}" STREQUAL "") + set(CMAKE_BUILD_TYPE template_debug) +endif() + +# Auto-detect platform +if(CMAKE_SYSTEM_NAME STREQUAL "Linux") + set(DEFAULT_PLATFORM "LINUX") +elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows") + set(DEFAULT_PLATFORM "WINDOWS") +elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") + set(DEFAULT_PLATFORM "MACOS") +elseif(CMAKE_SYSTEM_NAME STREQUAL "Emscripten") # Set by providing Emscripten toolchain + set(DEFAULT_PLATFORM "WEB") +elseif(CMAKE_SYSTEM_NAME STREQUAL "Android") # Set by providing Android toolchain + set(DEFAULT_PLATFORM "ANDROID") +else() + message(FATAL_ERROR "Could not auto-detect platform for \"${CMAKE_SYSTEM_NAME}\" automatically, please specify with -DPLATFORM=") +endif() +set(PLATFORM "${DEFAULT_PLATFORM}" CACHE STRING "[Auto-detected] Target platform (LINUX, MACOS, WINDOWS, ANDROID, IOS, WEB)") + +set(GDEXTENSION_DIR "${CMAKE_CURRENT_SOURCE_DIR}/gdextension" CACHE FILEPATH "Path to a directory containing GDExtension interface header") + +set(GDEXTENSION_API_FILE "${CMAKE_CURRENT_SOURCE_DIR}/gdextension/extension_api.json" CACHE FILEPATH "Path to GDExtension API JSON file") + +set(FLOAT_PRECISION "SINGLE" CACHE STRING "Floating-point precision level (SINGLE, DOUBLE)") + +set(OPTIMIZE "AUTO" CACHE STRING "The desired optimization flags (NONE, CUSTOM, DEBUG, SPEED, SPEED_TRACE, SIZE)") + +set(SYMBOLS_VISIBILITY "AUTO" CACHE STRING "Symbols visibility on GNU platforms (AUTO, VISIBLE, HIDDEN)") + +#TODO: custom .gdextension template file to add shared library as dependency +set(GODOT_CPP_LIBRARY_TYPE "STATIC" CACHE STRING "[Experimental] Library type (STATIC, SHARED)") + + +option(DEV_BUILD "Developer build with dev-only debugging code" OFF) + +option(DEBUG_SYMBOLS "Build with debugging symbols" ON) + +option(USE_HOT_RELOAD "Enable the extra accounting required to support hot reload" ON) + +# 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) + +# Optionally mark headers as SYSTEM +option(GODOT_CPP_SYSTEM_HEADERS "Mark the header files as SYSTEM. This may be useful to supress warnings in projects including this one" OFF) +set(GODOT_CPP_SYSTEM_HEADERS_ATTRIBUTE "") +if(GODOT_CPP_SYSTEM_HEADERS) + set(GODOT_CPP_SYSTEM_HEADERS_ATTRIBUTE SYSTEM) +endif() + +# Enable by default when building godot-cpp only +set(DEFAULT_WARNING_AS_ERROR OFF) +if(${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME}) + set(DEFAULT_WARNING_AS_ERROR ON) +endif() +set(GODOT_CPP_WARNING_AS_ERROR ${DEFAULT_WARNING_AS_ERROR} CACHE BOOL "Treat warnings as errors") + +option(GENERATE_TEMPLATE_GET_NODE "Generate a template version of the Node class's get_node" ON) + +### + +# Compiler warnings and compiler check generators +include(GodotCompilerWarnings) + +# Create the correct name (godot-cpp.platform.target.arch) +if(${DEV_BUILD}) + string(APPEND LIBRARY_SUFFIX ".dev") +endif() + +if(${FLOAT_PRECISION} STREQUAL "DOUBLE") + string(APPEND LIBRARY_SUFFIX ".double") +endif() + +# Workaround of $ expanding to "" when default build set +set(CONFIG "$>,${CMAKE_BUILD_TYPE},$>") + +string(TOLOWER ".${PLATFORM}" platform) +string(PREPEND LIBRARY_SUFFIX "${platform}.${CONFIG}") + +# Default optimization levels if OPTIMIZE=AUTO, for multi-config support +set(DEFAULT_OPTIMIZATION_DEV "$,$>") +set(DEFAULT_OPTIMIZATION_DEBUG_FEATURES "$,$,$,$>>") +set(DEFAULT_OPTIMIZATION "$<$>,STREQUAL:${OPTIMIZE},AUTO>>") + +list(APPEND GODOT_DEFINITIONS + GDEXTENSION + + $<${compiler_is_msvc}: + $<$: + _HAS_EXCEPTIONS=0 + > + > + + $<$: + REAL_T_IS_DOUBLE + > + $<$>,$>: + HOT_RELOAD_ENABLE + > + $<$: + TOOLS_ENABLED + > + + $<$: + DEV_ENABLED + > + $<$>: + NDEBUG + > + + $<$>: + DEBUG_ENABLED + DEBUG_METHODS_ENABLED + > +) + +list(APPEND GODOT_CC_FLAGS + $<${compiler_is_msvc}: + $<$: + /Zi + /FS + > + + $<$,${DEFAULT_OPTIMIZATION}>: + /O2 + > + $<$,${DEFAULT_OPTIMIZATION_DEBUG_FEATURES}>: + /O2 + > + $<$: + /O1 + > + $<$,$,${DEFAULT_OPTIMIZATION_DEV}>: + /Od + > + > + $<$: + $<$: + -gdwarf-4 + + $<$: + -g3 + > + $<$>: + -g2 + > + > + + $<$: + -fvisibility=default + > + $<$: + -fvisibility=hidden + > + + $<$>: + -O3 + > + $<$,${DEFAULT_OPTIMIZATION_DEBUG_FEATURES}>: + -O2 + > + $<$: + -Os + > + $<$: + -Og + > + $<$,${DEFAULT_OPTIMIZATION_DEV}>: + -O0 + > + > +) + +list(APPEND GODOT_CXX_FLAGS + $<${compiler_is_msvc}: + $<$>: + /EHsc + > + > + $<$: + $<$: + -fno-exceptions + > + > +) + +list(APPEND GODOT_LINK_FLAGS + $<${compiler_is_msvc}: + $<$: + /DEBUG:FULL + > + + $<$: + /OPT:REF + > + $<$,${DEFAULT_OPTIMIZATION_DEBUG_FEATURES}>: + /OPT:REF + /OPT:NOICF + > + $<$: + /OPT:REF + > + > + $<$: + $<$: + -fvisibility=default + > + $<$: + -fvisibility=hidden + > + + $<$>: + $<$: # SCons: not is_vanilla_clang(env) + "-Wl,-S" + "-Wl,-x" + "-Wl,-dead_strip" + > + $<$>: + "-s" + > + > + > +) + +# Platform-specific options +if("${PLATFORM}" STREQUAL "LINUX") + include(linux) +elseif("${PLATFORM}" STREQUAL "MACOS") + include(macos) +elseif("${PLATFORM}" STREQUAL "WINDOWS") + include(windows) +elseif("${PLATFORM}" STREQUAL "ANDROID") + include(android) +elseif("${PLATFORM}" STREQUAL "IOS") + include(ios) +elseif("${PLATFORM}" STREQUAL "WEB") + include(web) +else() + message(FATAL_ERROR "Platform not supported: ${PLATFORM}") +endif() + +# Write all flags to file for cmake configuration debug +file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/flags.txt" + CONTENT + "C_FLAGS '${GODOT_CC_FLAGS}'\nCXX_FLAGS '${GODOT_CXX_FLAGS}'\nLINK_FLAGS '${GODOT_LINK_FLAGS}'\nCOMPILE_WARNING_FLAGS '${GODOT_COMPILE_WARNING_FLAGS}'\n" + TARGET ${PROJECT_NAME} +) diff --git a/cmake/ios.cmake b/cmake/ios.cmake new file mode 100644 index 00000000..f863b951 --- /dev/null +++ b/cmake/ios.cmake @@ -0,0 +1,68 @@ +message(WARNING "IOS configuration is not tested and may not work.") + +set(ARCH "universal" CACHE STRING "Target architecture (universal, arm64, x86_64, CUSTOM)") + +set(IOS_MIN_VERSION "12.0" CACHE STRING "Target minimum iphoneos/iphonesimulator version") + +option(IOS_SIMULATOR "Target iOS Simulator" OFF) + +if (${ARCH} STREQUAL "universal") + set(DEFAULT_BITS 64) +else() + string(REGEX MATCH "32$|64$" DEFAULT_BITS "${ARCH}") +endif() +set(BITS "${DEFAULT_BITS}" CACHE STRING "Architecture bits. Needs to be set manually for custom architecture") + + +list(APPEND GODOT_DEFINITIONS + IOS_ENABLED + UNIX_ENABLED +) + +list(APPEND GODOT_CC_FLAGS + $<$: + -stdlib=libc++ + > + + $<$: + -mios-simulator-version-min=${IOS_MIN_VERSION} + > + $<$>: + -miphoneos-version-min=${IOS_MIN_VERSION} + > + + $<$: + $<$: + "SHELL:-arch x86_64" + "SHELL:-arch arm64" + > + $<$>: + "SHELL:-arch arm64" + > + > + $<$>: + "-arch ${ARCH}" + > +) + +list(APPEND GODOT_LINK_FLAGS + $<$: + $<$: + "SHELL:-arch x86_64" + "SHELL:-arch arm64" + > + $<$>: + "SHELL:-arch arm64" + > + > + $<$>: + "SHELL:-arch ${ARCH}" + > +) + +string(APPEND LIBRARY_SUFFIX ".${ARCH}") + +if(${IOS_SIMULATOR}) + string(APPEND LIBRARY_SUFFIX ".simulator") +endif() + diff --git a/cmake/linux.cmake b/cmake/linux.cmake new file mode 100644 index 00000000..9266b3e6 --- /dev/null +++ b/cmake/linux.cmake @@ -0,0 +1,61 @@ +set(ARCH "x86_64" CACHE STRING "Target architecture (x86_32, x86_64, arm64, rv64, CUSTOM)") + +string(REGEX MATCH "32$|64$" DEFAULT_BITS "${ARCH}") +set(BITS "${DEFAULT_BITS}" CACHE STRING "Architecture bits. Needs to be set manually for custom architecture") + + +list(APPEND GODOT_DEFINITIONS + LINUX_ENABLED + UNIX_ENABLED +) + +list(APPEND GODOT_CC_FLAGS + # -fPIC is controlled by POSITION_INDEPENDENT_CODE property + + $<$: + -m64 + -march=x86-64 + > + $<$: + -m32 + -march=i686 + > + $<$: + -march=armv8-a + > + $<$: + -march=rv64gc + > +) + +list(APPEND GODOT_CXX_FLAGS + $<$,${compiler_is_gnu}>: + -fno-gnu-unique + > +) + +list(APPEND GODOT_LINK_FLAGS + -Wl,-R,'$$ORIGIN' + + $<$: + -m64 + -march=x86-64 + > + $<$: + -m32 + -march=i686 + > + $<$: + -march=armv8-a + > + $<$: + -march=rv64gc + > +) + +list(APPEND GODOT_COMPILE_WARNING_FLAGS + -Wwrite-strings +) + +string(APPEND LIBRARY_SUFFIX ".${ARCH}") + diff --git a/cmake/macos.cmake b/cmake/macos.cmake new file mode 100644 index 00000000..55b632ca --- /dev/null +++ b/cmake/macos.cmake @@ -0,0 +1,53 @@ +message(WARNING "MacOS configuration is not tested and may not work.") + +set(ARCH "universal" CACHE STRING "Target architecture (universal, arm64, x86_64, CUSTOM)") + +set(MACOS_DEPLOYMENT_TARGET "DEFAULT" CACHE STRING "") + +if (${ARCH} STREQUAL "universal") + set(DEFAULT_BITS 64) +else() + string(REGEX MATCH "32$|64$" DEFAULT_BITS "${ARCH}") +endif() +set(BITS "${DEFAULT_BITS}" CACHE STRING "Architecture bits. Needs to be set manually for custom architecture") + + +list(APPEND GODOT_DEFINITIONS + MACOS_ENABLED + UNIX_ENABLED +) + +list(APPEND GODOT_CC_FLAGS + $<$: + "SHELL:-arch x86_64" + "SHELL:-arch arm64" + > + $<$>: + "SHELL:-arch ${ARCH}" + > + + $<$>: + -mmacosx-version-min=${MACOS_DEPLOYMENT_TARGET} + > +) + +list(APPEND GODOT_LINK_FLAGS + -framework + Cocoa + -Wl,-undefined,dynamic_lookup + + $<$: + "SHELL:-arch x86_64" + "SHELL:-arch arm64" + > + $<$>: + "SHELL:-arch ${ARCH}" + > + + $<$>: + -mmacosx-version-min=${MACOS_DEPLOYMENT_TARGET} + > +) + +string(APPEND LIBRARY_SUFFIX ".${ARCH}") + diff --git a/cmake/web.cmake b/cmake/web.cmake new file mode 100644 index 00000000..9426bae4 --- /dev/null +++ b/cmake/web.cmake @@ -0,0 +1,25 @@ +# Used with Emscripted toolchain at *toolchain_dir*/cmake/Modules/Platform/Emscripten.cmake + +set(ARCH "wasm32" CACHE STRING "Target architecture (wasm32, CUSTOM)") + +string(REGEX MATCH "32$|64$" DEFAULT_BITS "${ARCH}") +set(BITS "${DEFAULT_BITS}" CACHE STRING "Architecture bits. Needs to be set manually for custom architecture") + + +list(APPEND GODOT_DEFINITIONS + WEB_ENABLED + UNIX_ENABLED +) + +list(APPEND GODOT_CC_FLAGS + -sUSE_PTHREADS=1 +) + +list(APPEND GODOT_CXX_FLAGS + -sSIDE_MODULE=1 +) + +list(APPEND GODOT_LINK_FLAGS + -sUSE_PTHREADS=1 + -sSIDE_MODULE=1 +) diff --git a/cmake/windows.cmake b/cmake/windows.cmake new file mode 100644 index 00000000..d7c9270c --- /dev/null +++ b/cmake/windows.cmake @@ -0,0 +1,53 @@ +set(ARCH "x86_64" CACHE STRING "Target architecture (x86_32, x86_64, CUSTOM)") + +option(USE_STATIC_CPP "Link MinGW/MSVC C++ runtime libraries statically" ON) + +string(REGEX MATCH "32$|64$" DEFAULT_BITS "${ARCH}") +set(BITS "${DEFAULT_BITS}" CACHE STRING "Architecture bits. Needs to be set manually for custom architecture") + + +list(APPEND GODOT_DEFINITIONS + WINDOWS_ENABLED + + $<${compiler_is_msvc}: + TYPED_METHOD_BIND + NOMINMAX + > +) + +list(APPEND GODOT_CC_FLAGS + $<${compiler_is_msvc}: + /utf-8 + + $<$: + /MT + > + $<$>: + /MD + > + > +) + +list(APPEND GODOT_LINK_FLAGS + $<${compiler_is_msvc}: + /WX + > + $<$: + -Wl,--no-undefined + + $<$: + -static + -static-libgcc + -static-libstdc++ + > + > +) + +list(APPEND GODOT_COMPILE_WARNING_FLAGS + $<$: + -Wwrite-strings + > +) + +string(APPEND LIBRARY_SUFFIX ".${ARCH}") + From 1320634d356af82b08607976bdeeacca36946942 Mon Sep 17 00:00:00 2001 From: Vano Date: Sun, 31 Dec 2023 19:17:35 +0200 Subject: [PATCH 2/6] CMake test project rewrite, test script exports before running test --- test/CMakeLists.txt | 176 +++++++++----------------------- test/project/export_presets.cfg | 39 +++++++ test/run-tests.sh | 3 + 3 files changed, 88 insertions(+), 130 deletions(-) create mode 100644 test/project/export_presets.cfg diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 67f3c5c8..88176b55 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,143 +1,59 @@ -project(godot-cpp-test) -cmake_minimum_required(VERSION 3.6) +cmake_minimum_required(VERSION 3.24) +project(gdexample) -set(GODOT_GDEXTENSION_DIR ../gdextension/ CACHE STRING "Path to GDExtension interface header directory") -set(CPP_BINDINGS_PATH ../ CACHE STRING "Path to C++ bindings") - -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") - - 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() +add_subdirectory( + ../ # path to godot-cpp + ${CMAKE_CURRENT_BINARY_DIR}/godot-cpp # needed because godot-cpp is top directory +) # 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}) +if(${PLATFORM} STREQUAL "WEB") + # wasm libraries loaded with dlopen() are created like this in cmake + add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS}) + set_target_properties(${PROJECT_NAME} + PROPERTIES + PREFIX "lib" + SUFFIX ".wasm" + ) +elseif(${PLATFORM} STREQUAL "MACOS") + # TODO: create framework with cmake FRAMEWORK property + # or with template file + message(WARNING "Mac/IOS framework configuration is not tested and may not work.") -target_include_directories(${PROJECT_NAME} SYSTEM - PRIVATE - ${CPP_BINDINGS_PATH}/include - ${CPP_BINDINGS_PATH}/gen/include - ${GODOT_GDEXTENSION_DIR} + add_library(${PROJECT_NAME} SHARED ${SOURCES} ${HEADERS}) + set_target_properties(${PROJECT_NAME} PROPERTIES + FRAMEWORK TRUE + MACOSX_FRAMEWORK_IDENTIFIER com.godotengine.${PROJECT_NAME} + MACOSX_FRAMEWORK_INFO_PLIST Info.plist + ) +else() + add_library(${PROJECT_NAME} SHARED ${SOURCES} ${HEADERS}) +endif() + +target_link_libraries(${PROJECT_NAME} PUBLIC godot-cpp) + +get_directory_property(GODOT_CC_FLAGS DIRECTORY ../ DEFINITION GODOT_CC_FLAGS) +get_directory_property(GODOT_CXX_FLAGS DIRECTORY ../ DEFINITION GODOT_CXX_FLAGS) +target_compile_options(${PROJECT_NAME} PRIVATE + ${GODOT_CC_FLAGS} + ${GODOT_CXX_FLAGS} ) -# Create the correct name (godot.os.build_type.system_bits) -# Synchronized with godot-cpp's CMakeLists.txt +get_directory_property(GODOT_LINK_FLAGS DIRECTORY ../ DEFINITION GODOT_LINK_FLAGS) +target_link_options(${PROJECT_NAME} PRIVATE ${GODOT_LINK_FLAGS}) -set(BITS 32) -if(CMAKE_SIZEOF_VOID_P EQUAL 8) - set(BITS 64) -endif(CMAKE_SIZEOF_VOID_P EQUAL 8) -if(CMAKE_BUILD_TYPE MATCHES Debug) - set(GODOT_CPP_BUILD_TYPE Debug) -else() - set(GODOT_CPP_BUILD_TYPE Release) -endif() +get_directory_property(LIBRARY_SUFFIX DIRECTORY ../ DEFINITION LIBRARY_SUFFIX) +set_target_properties(${PROJECT_NAME} + PROPERTIES + ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/project/bin" + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/project/bin" + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/project/bin" + + OUTPUT_NAME "${PROJECT_NAME}${LIBRARY_SUFFIX}" +) -string(TOLOWER ${CMAKE_SYSTEM_NAME} SYSTEM_NAME) -string(TOLOWER ${GODOT_CPP_BUILD_TYPE} BUILD_TYPE) - -if(ANDROID) - # Added the android abi after system name - set(SYSTEM_NAME ${SYSTEM_NAME}.${ANDROID_ABI}) -endif() - -if(CMAKE_VERSION VERSION_GREATER "3.13") - target_link_directories(${PROJECT_NAME} - PRIVATE - ${CPP_BINDINGS_PATH}/bin/ - ) - - target_link_libraries(${PROJECT_NAME} - godot-cpp.${SYSTEM_NAME}.${BUILD_TYPE}$<$>:.${BITS}> - ) -else() - target_link_libraries(${PROJECT_NAME} - ${CPP_BINDINGS_PATH}/bin/libgodot-cpp.${SYSTEM_NAME}.${BUILD_TYPE}$<$>:.${BITS}>.a - ) -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") diff --git a/test/project/export_presets.cfg b/test/project/export_presets.cfg new file mode 100644 index 00000000..1e672b73 --- /dev/null +++ b/test/project/export_presets.cfg @@ -0,0 +1,39 @@ +[preset.0] + +name="" +platform="Linux/X11" +runnable=false +dedicated_server=false +custom_features="" +export_filter="all_resources" +include_filter="" +exclude_filter="" +export_path="" +encryption_include_filters="" +encryption_exclude_filters="" +encrypt_pck=false +encrypt_directory=false + +[preset.0.options] + +custom_template/debug="" +custom_template/release="" +debug/export_console_wrapper=1 +binary_format/embed_pck=false +texture_format/bptc=true +texture_format/s3tc=true +texture_format/etc=false +texture_format/etc2=false +binary_format/architecture="x86_64" +ssh_remote_deploy/enabled=false +ssh_remote_deploy/host="user@host_ip" +ssh_remote_deploy/port="22" +ssh_remote_deploy/extra_args_ssh="" +ssh_remote_deploy/extra_args_scp="" +ssh_remote_deploy/run_script="#!/usr/bin/env bash +export DISPLAY=:0 +unzip -o -q \"{temp_dir}/{archive_name}\" -d \"{temp_dir}\" +\"{temp_dir}/{exe_name}\" {cmd_args}" +ssh_remote_deploy/cleanup_script="#!/usr/bin/env bash +kill $(pgrep -x -f \"{temp_dir}/{exe_name} {cmd_args}\") +rm -rf \"{temp_dir}\"" diff --git a/test/run-tests.sh b/test/run-tests.sh index 728f6d4c..cb13c133 100755 --- a/test/run-tests.sh +++ b/test/run-tests.sh @@ -5,6 +5,9 @@ GODOT=${GODOT:-godot} END_STRING="==== TESTS FINISHED ====" FAILURE_STRING="******** FAILED ********" +# Import to get GDExtension library working +$GODOT --headless --path project --export-pack '' /dev/null + OUTPUT=$($GODOT --path project --debug --headless --quit) ERRCODE=$? From 18aa34d9f29f02c431abf05345a577911361f946 Mon Sep 17 00:00:00 2001 From: Vano Date: Tue, 9 Jan 2024 23:35:20 +0200 Subject: [PATCH 3/6] cmake version revert, single and multi-config support, default cmake configuration types, cmdline example fix, output path for multi-config fix, clean default CXX flags, public definitions fix --- CMakeLists.txt | 53 ++++++----- cmake/GodotCompilerWarnings.cmake | 17 ++++ cmake/android.cmake | 2 - cmake/godotcpp.cmake | 148 ++++++++++++++++++++---------- cmake/ios.cmake | 6 -- cmake/linux.cmake | 4 +- cmake/macos.cmake | 2 - cmake/web.cmake | 1 + cmake/windows.cmake | 4 +- test/CMakeLists.txt | 19 +++- 10 files changed, 161 insertions(+), 95 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 91ba7c49..68e7ca0e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,51 +1,57 @@ -# cmake arguments -# CMAKE_BUILD_TYPE: Compilation target (editor, template_debug, template_release) +# 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) # # 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: # -# cmake -LH +# cmake -LH # -# Note: use -Bbuild_dir option to build in separate directories +# Note: use `-B ` option to build in separate directories # for different configurations # -# cmake -Bbuild && cmake --build build +# cmake -B build && cmake --build build # # Examples # # Builds default configuration: -# cmake . -# cmake --build . +# cmake . -Bbuild +# cmake --build build # # Builds template_release version # -# cmake -DCMAKE_BUILD_TYPE=template_release . -# cmake --build . +# cmake -DTARGET=TEMPLATE_RELEASE -Bbuild +# cmake --build build # -# Creates multi-config setup and builds 2 library versions (example for Linux) +# Creates multi-config setup and builds Release version (example for Linux) # -# cmake -G "Ninja Multi-Config" . -# cmake --build . --config editor -# cmake --build . --config template_release +# cmake -G "Ninja Multi-Config" -Bbuild +# cmake --build build --config Release # # Builds web version, using Emscripten toolchain # -# cmake --toolchain /usr/lib/emscripten/cmake/Modules/Platform/Emscripten.cmake . -# cmake --build . +# cmake --toolchain /usr/lib/emscripten/cmake/Modules/Platform/Emscripten.cmake -Bbuild +# cmake --build build # # # Builds an android armeabi-v7a debug version: # cmake --toolchain $ANDROID_NDK/build/cmake/android.toolchain.cmake \ -# -DANDROID_TOOLCHAIN_NAME=arm-linux-androideabi-4.9 -DANDROID_TOOLCHAIN=clang -DANDROID_PLATFORM=21 . -# cmake --build . +# -DANDROID_TOOLCHAIN_NAME=arm-linux-androideabi-4.9 -DANDROID_TOOLCHAIN=clang -DANDROID_PLATFORM=21 -Bbuild +# cmake --build build # # -# Todo -# Test build for Windows, Mac and mingw. +# TODO: +# Test builds for MacOS/IOS -cmake_minimum_required(VERSION 3.24) +cmake_minimum_required(VERSION 3.12) project(godot-cpp LANGUAGES CXX) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/") @@ -108,16 +114,17 @@ target_compile_options(${PROJECT_NAME} PRIVATE target_link_options(${PROJECT_NAME} PRIVATE ${GODOT_LINK_FLAGS}) -target_compile_definitions(${PROJECT_NAME} PRIVATE ${GODOT_DEFINITIONS}) +target_compile_definitions(${PROJECT_NAME} PUBLIC ${GODOT_DEFINITIONS}) set_target_properties(${PROJECT_NAME} PROPERTIES CXX_EXTENSIONS OFF - COMPILE_WARNING_AS_ERROR ${GODOT_CPP_WARNING_AS_ERROR} POSITION_INDEPENDENT_CODE ON 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 "${PROJECT_NAME}${LIBRARY_SUFFIX}" ) - +if(${GODOT_CPP_WARNING_AS_ERROR}) + set_warning_as_error(${PROJECT_NAME}) +endif() diff --git a/cmake/GodotCompilerWarnings.cmake b/cmake/GodotCompilerWarnings.cmake index 5695e135..6b1c6a64 100644 --- a/cmake/GodotCompilerWarnings.cmake +++ b/cmake/GodotCompilerWarnings.cmake @@ -76,3 +76,20 @@ list(APPEND GODOT_COMPILE_WARNING_FLAGS -Wno-return-type > ) + +# Treat warnings as errors +function(set_warning_as_error TARGET_NAME) + message(STATUS "[${TARGET_NAME}] Treating warnings as errors") + if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24") + set_target_properties(${TARGET_NAME} + PROPERTIES + COMPILE_WARNING_AS_ERROR ON + ) + else() + target_compile_options(${TARGET_NAME} + PRIVATE + $<${compiler_is_msvc}:/WX> + $<$:-Werror> + ) + endif() +endfunction() diff --git a/cmake/android.cmake b/cmake/android.cmake index 1262e906..cf8ae87a 100644 --- a/cmake/android.cmake +++ b/cmake/android.cmake @@ -63,5 +63,3 @@ list(APPEND GODOT_LINK_FLAGS > ) -string(APPEND LIBRARY_SUFFIX ".${ARCH}") - diff --git a/cmake/godotcpp.cmake b/cmake/godotcpp.cmake index d3b4001f..d9c20a95 100644 --- a/cmake/godotcpp.cmake +++ b/cmake/godotcpp.cmake @@ -2,12 +2,14 @@ ### Options -set(CMAKE_CONFIGURATION_TYPES "template_debug;editor;template_release") +set(CONFIGS_WITH_DEBUG "Debug;RelWithDebInfo" CACHE STRING "Configurations that should have debug symbols (Modify if support for custom configurations is needed)") +# Default config if("${CMAKE_BUILD_TYPE}" STREQUAL "") - set(CMAKE_BUILD_TYPE template_debug) + set(CMAKE_BUILD_TYPE "Debug") endif() +set(TARGET "TEMPLATE_DEBUG" CACHE STRING "Target platform (EDITOR, TEMPLATE_DEBUG, TEMPLATE_RELEASE)") # Auto-detect platform if(CMAKE_SYSTEM_NAME STREQUAL "Linux") set(DEFAULT_PLATFORM "LINUX") @@ -40,7 +42,7 @@ set(GODOT_CPP_LIBRARY_TYPE "STATIC" CACHE STRING "[Experimental] Library type (S option(DEV_BUILD "Developer build with dev-only debugging code" OFF) -option(DEBUG_SYMBOLS "Build with debugging symbols" ON) +option(DEBUG_SYMBOLS "Force build with debugging symbols" OFF) option(USE_HOT_RELOAD "Enable the extra accounting required to support hot reload" ON) @@ -69,7 +71,8 @@ option(GENERATE_TEMPLATE_GET_NODE "Generate a template version of the Node class # Compiler warnings and compiler check generators include(GodotCompilerWarnings) -# Create the correct name (godot-cpp.platform.target.arch) +# Create the correct name (godot-cpp.platform.target) +# See more prefix appends in platform-specific configs if(${DEV_BUILD}) string(APPEND LIBRARY_SUFFIX ".dev") endif() @@ -81,13 +84,21 @@ endif() # Workaround of $ expanding to "" when default build set set(CONFIG "$>,${CMAKE_BUILD_TYPE},$>") -string(TOLOWER ".${PLATFORM}" platform) -string(PREPEND LIBRARY_SUFFIX "${platform}.${CONFIG}") +string(TOLOWER ".${PLATFORM}.${TARGET}" platform_target) +string(PREPEND LIBRARY_SUFFIX ${platform_target}) # Default optimization levels if OPTIMIZE=AUTO, for multi-config support -set(DEFAULT_OPTIMIZATION_DEV "$,$>") -set(DEFAULT_OPTIMIZATION_DEBUG_FEATURES "$,$,$,$>>") -set(DEFAULT_OPTIMIZATION "$<$>,STREQUAL:${OPTIMIZE},AUTO>>") +set(DEFAULT_OPTIMIZATION_DEBUG_FEATURES "$,$>") +set(DEFAULT_OPTIMIZATION "$") + +set(DEBUG_SYMBOLS_ENABLED "$,$>") + +# Clean default options +set(CMAKE_CXX_FLAGS "") +set(CMAKE_CXX_FLAGS_DEBUG "") +set(CMAKE_CXX_FLAGS_RELEASE "") +set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "") +set(CMAKE_CXX_FLAGS_MINSIZEREL "") list(APPEND GODOT_DEFINITIONS GDEXTENSION @@ -101,10 +112,10 @@ list(APPEND GODOT_DEFINITIONS $<$: REAL_T_IS_DOUBLE > - $<$>,$>: + $<$>,$>: HOT_RELOAD_ENABLE > - $<$: + $<$: TOOLS_ENABLED > @@ -115,7 +126,7 @@ list(APPEND GODOT_DEFINITIONS NDEBUG > - $<$>: + $<$>: DEBUG_ENABLED DEBUG_METHODS_ENABLED > @@ -123,28 +134,40 @@ list(APPEND GODOT_DEFINITIONS list(APPEND GODOT_CC_FLAGS $<${compiler_is_msvc}: - $<$: + $<${DEBUG_SYMBOLS_ENABLED}: /Zi /FS > - $<$,${DEFAULT_OPTIMIZATION}>: - /O2 + $<$: + $<$: + $<${DEFAULT_OPTIMIZATION}: + /O2 + > + $<${DEFAULT_OPTIMIZATION_DEBUG_FEATURES}: + /O2 + > + > + $<$: + /O1 + > + $<$: + /Od + > > - $<$,${DEFAULT_OPTIMIZATION_DEBUG_FEATURES}>: - /O2 - > - $<$: - /O1 - > - $<$,$,${DEFAULT_OPTIMIZATION_DEV}>: - /Od + $<$>: + $<$:/O2> + $<$:/O2> + $<$:/O1> + $<$:/Od> + $<$:/Od> > + > $<$: - $<$: + $<${DEBUG_SYMBOLS_ENABLED}: -gdwarf-4 - + $<$: -g3 > @@ -160,20 +183,28 @@ list(APPEND GODOT_CC_FLAGS -fvisibility=hidden > - $<$>: - -O3 + $<$: + $<$: + $<${DEFAULT_OPTIMIZATION}: + -O3 + > + $<${DEFAULT_OPTIMIZATION_DEBUG_FEATURES}: + -O2 + > + > + $<$: + -Os + > + $<$: + -Og + > > - $<$,${DEFAULT_OPTIMIZATION_DEBUG_FEATURES}>: - -O2 - > - $<$: - -Os - > - $<$: - -Og - > - $<$,${DEFAULT_OPTIMIZATION_DEV}>: - -O0 + $<$>: + $<$:-O3> + $<$:-O2> + $<$:-Os> + $<$:-Og> + $<$:-O0> > > ) @@ -186,26 +217,35 @@ list(APPEND GODOT_CXX_FLAGS > $<$: $<$: - -fno-exceptions + -fno-exceptions > > ) list(APPEND GODOT_LINK_FLAGS $<${compiler_is_msvc}: - $<$: + $<${DEBUG_SYMBOLS_ENABLED}: /DEBUG:FULL > - $<$: - /OPT:REF + $<$: + $<$: + $<${DEFAULT_OPTIMIZATION}: + /OPT:REF + > + $<${DEFAULT_OPTIMIZATION_DEBUG_FEATURES}: + /OPT:REF + /OPT:NOICF + > + > + $<$: + /OPT:REF + > > - $<$,${DEFAULT_OPTIMIZATION_DEBUG_FEATURES}>: - /OPT:REF - /OPT:NOICF - > - $<$: - /OPT:REF + $<$>: + $<$:/OPT:REF> + $<$:/OPT:REF /OPT:NOICF> + $<$:/OPT:REF> > > $<$: @@ -216,7 +256,7 @@ list(APPEND GODOT_LINK_FLAGS -fvisibility=hidden > - $<$>: + $<$: $<$: # SCons: not is_vanilla_clang(env) "-Wl,-S" "-Wl,-x" @@ -246,9 +286,15 @@ else() message(FATAL_ERROR "Platform not supported: ${PLATFORM}") endif() +string(APPEND LIBRARY_SUFFIX ".${ARCH}") + +if(${IOS_SIMULATOR}) + string(APPEND LIBRARY_SUFFIX ".simulator") +endif() + # Write all flags to file for cmake configuration debug -file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/flags.txt" +file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/flags-${CONFIG}.txt" CONTENT - "C_FLAGS '${GODOT_CC_FLAGS}'\nCXX_FLAGS '${GODOT_CXX_FLAGS}'\nLINK_FLAGS '${GODOT_LINK_FLAGS}'\nCOMPILE_WARNING_FLAGS '${GODOT_COMPILE_WARNING_FLAGS}'\n" + "C_FLAGS '${GODOT_CC_FLAGS}'\nCXX_FLAGS '${GODOT_CXX_FLAGS}'\nLINK_FLAGS '${GODOT_LINK_FLAGS}'\nCOMPILE_WARNING_FLAGS '${GODOT_COMPILE_WARNING_FLAGS}'\nDEFINITIONS '${GODOT_DEFINITIONS}'" TARGET ${PROJECT_NAME} ) diff --git a/cmake/ios.cmake b/cmake/ios.cmake index f863b951..41831420 100644 --- a/cmake/ios.cmake +++ b/cmake/ios.cmake @@ -60,9 +60,3 @@ list(APPEND GODOT_LINK_FLAGS > ) -string(APPEND LIBRARY_SUFFIX ".${ARCH}") - -if(${IOS_SIMULATOR}) - string(APPEND LIBRARY_SUFFIX ".simulator") -endif() - diff --git a/cmake/linux.cmake b/cmake/linux.cmake index 9266b3e6..48e9ff47 100644 --- a/cmake/linux.cmake +++ b/cmake/linux.cmake @@ -10,7 +10,7 @@ list(APPEND GODOT_DEFINITIONS ) list(APPEND GODOT_CC_FLAGS - # -fPIC is controlled by POSITION_INDEPENDENT_CODE property + # -fPIC is controlled by POSITION_INDEPENDENT_CODE property $<$: -m64 @@ -57,5 +57,3 @@ list(APPEND GODOT_COMPILE_WARNING_FLAGS -Wwrite-strings ) -string(APPEND LIBRARY_SUFFIX ".${ARCH}") - diff --git a/cmake/macos.cmake b/cmake/macos.cmake index 55b632ca..29c02719 100644 --- a/cmake/macos.cmake +++ b/cmake/macos.cmake @@ -49,5 +49,3 @@ list(APPEND GODOT_LINK_FLAGS > ) -string(APPEND LIBRARY_SUFFIX ".${ARCH}") - diff --git a/cmake/web.cmake b/cmake/web.cmake index 9426bae4..7148a952 100644 --- a/cmake/web.cmake +++ b/cmake/web.cmake @@ -23,3 +23,4 @@ list(APPEND GODOT_LINK_FLAGS -sUSE_PTHREADS=1 -sSIDE_MODULE=1 ) + diff --git a/cmake/windows.cmake b/cmake/windows.cmake index d7c9270c..05883460 100644 --- a/cmake/windows.cmake +++ b/cmake/windows.cmake @@ -18,7 +18,7 @@ list(APPEND GODOT_DEFINITIONS list(APPEND GODOT_CC_FLAGS $<${compiler_is_msvc}: /utf-8 - + $<$: /MT > @@ -49,5 +49,3 @@ list(APPEND GODOT_COMPILE_WARNING_FLAGS > ) -string(APPEND LIBRARY_SUFFIX ".${ARCH}") - diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 88176b55..5a184b47 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.24) +cmake_minimum_required(VERSION 3.6) project(gdexample) add_subdirectory( @@ -18,6 +18,11 @@ if(${PLATFORM} STREQUAL "WEB") PROPERTIES PREFIX "lib" SUFFIX ".wasm" + RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_CURRENT_SOURCE_DIR}/project/bin" + RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_CURRENT_SOURCE_DIR}/project/bin" + RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_CURRENT_SOURCE_DIR}/project/bin" + RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL "${CMAKE_CURRENT_SOURCE_DIR}/project/bin" + ) elseif(${PLATFORM} STREQUAL "MACOS") # TODO: create framework with cmake FRAMEWORK property @@ -50,10 +55,14 @@ target_link_options(${PROJECT_NAME} PRIVATE ${GODOT_LINK_FLAGS}) get_directory_property(LIBRARY_SUFFIX DIRECTORY ../ DEFINITION LIBRARY_SUFFIX) set_target_properties(${PROJECT_NAME} PROPERTIES - ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/project/bin" - LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/project/bin" - RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/project/bin" - + LIBRARY_OUTPUT_DIRECTORY_DEBUG "${CMAKE_CURRENT_SOURCE_DIR}/project/bin" + LIBRARY_OUTPUT_DIRECTORY_RELEASE "${CMAKE_CURRENT_SOURCE_DIR}/project/bin" + LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_CURRENT_SOURCE_DIR}/project/bin" + LIBRARY_OUTPUT_DIRECTORY_MINSIZEREL "${CMAKE_CURRENT_SOURCE_DIR}/project/bin" + OUTPUT_NAME "${PROJECT_NAME}${LIBRARY_SUFFIX}" ) +if(${GODOT_CPP_WARNING_AS_ERROR}) + set_warning_as_error(${PROJECT_NAME}) +endif() From a37226e1062ab01c1462510f22ac1bbf9f3c06cc Mon Sep 17 00:00:00 2001 From: Vano Date: Sat, 13 Jan 2024 14:21:13 +0200 Subject: [PATCH 4/6] test project config types, verbose test configfile --- CMakeLists.txt | 12 ++++++++---- cmake/godotcpp.cmake | 1 - test/CMakeLists.txt | 20 +++++++++++++------- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 68e7ca0e..e069342e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,10 +1,12 @@ +# Configuration for building godot-cpp only +# See `tests/CMakeLists.txt` for example configuration +# # 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) +# in top project config or via cmdline (see `test/CMakeLists.txt`) # # TARGET Godot build target (EDITOR, TEMPLATE_DEBUG, TEMPLATE_RELEASE) # @@ -31,9 +33,11 @@ # cmake -DTARGET=TEMPLATE_RELEASE -Bbuild # cmake --build build # -# Creates multi-config setup and builds Release version (example for Linux) +# Creates multi-config setup and builds Release version # -# cmake -G "Ninja Multi-Config" -Bbuild +# cmake -G "Ninja Multi-Config" -Bbuild # For Linux/non-MSVC +# OR +# cmake -G "Visual Studio 16 2019" -A x64 -Bbuild # For Windows/MSVC # cmake --build build --config Release # # Builds web version, using Emscripten toolchain diff --git a/cmake/godotcpp.cmake b/cmake/godotcpp.cmake index d9c20a95..c123c202 100644 --- a/cmake/godotcpp.cmake +++ b/cmake/godotcpp.cmake @@ -94,7 +94,6 @@ set(DEFAULT_OPTIMIZATION "$") set(DEBUG_SYMBOLS_ENABLED "$,$>") # Clean default options -set(CMAKE_CXX_FLAGS "") set(CMAKE_CXX_FLAGS_DEBUG "") set(CMAKE_CXX_FLAGS_RELEASE "") set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "") diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 5a184b47..97e9bcd8 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,14 +1,18 @@ +# Configuration can be used as a template for custom project, read comments cmake_minimum_required(VERSION 3.6) -project(gdexample) +project(gdexample LANGUAGES CXX) + +set(CMAKE_CONFIGURATION_TYPES "Debug;Release;RelWithDebInfo;MinSizeRel") +set(GODOT_CPP_PATH ../) # path to godot-cpp repository add_subdirectory( - ../ # path to godot-cpp + ${GODOT_CPP_PATH} ${CMAKE_CURRENT_BINARY_DIR}/godot-cpp # needed because godot-cpp is top directory ) # Get Sources file(GLOB_RECURSE SOURCES src/*.c**) -file(GLOB_RECURSE HEADERS include/*.h**) +file(GLOB_RECURSE HEADERS src/*.h**) # Define our godot-cpp library if(${PLATFORM} STREQUAL "WEB") @@ -18,6 +22,7 @@ if(${PLATFORM} STREQUAL "WEB") PROPERTIES PREFIX "lib" SUFFIX ".wasm" + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/project/bin" RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_CURRENT_SOURCE_DIR}/project/bin" RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_CURRENT_SOURCE_DIR}/project/bin" RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_CURRENT_SOURCE_DIR}/project/bin" @@ -41,20 +46,21 @@ endif() target_link_libraries(${PROJECT_NAME} PUBLIC godot-cpp) -get_directory_property(GODOT_CC_FLAGS DIRECTORY ../ DEFINITION GODOT_CC_FLAGS) -get_directory_property(GODOT_CXX_FLAGS DIRECTORY ../ DEFINITION GODOT_CXX_FLAGS) +get_directory_property(GODOT_CC_FLAGS DIRECTORY ${GODOT_CPP_PATH} DEFINITION GODOT_CC_FLAGS) +get_directory_property(GODOT_CXX_FLAGS DIRECTORY ${GODOT_CPP_PATH} DEFINITION GODOT_CXX_FLAGS) target_compile_options(${PROJECT_NAME} PRIVATE ${GODOT_CC_FLAGS} ${GODOT_CXX_FLAGS} ) -get_directory_property(GODOT_LINK_FLAGS DIRECTORY ../ DEFINITION GODOT_LINK_FLAGS) +get_directory_property(GODOT_LINK_FLAGS DIRECTORY ${GODOT_CPP_PATH} DEFINITION GODOT_LINK_FLAGS) target_link_options(${PROJECT_NAME} PRIVATE ${GODOT_LINK_FLAGS}) -get_directory_property(LIBRARY_SUFFIX DIRECTORY ../ DEFINITION LIBRARY_SUFFIX) +get_directory_property(LIBRARY_SUFFIX DIRECTORY ${GODOT_CPP_PATH} DEFINITION LIBRARY_SUFFIX) set_target_properties(${PROJECT_NAME} PROPERTIES + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/project/bin" LIBRARY_OUTPUT_DIRECTORY_DEBUG "${CMAKE_CURRENT_SOURCE_DIR}/project/bin" LIBRARY_OUTPUT_DIRECTORY_RELEASE "${CMAKE_CURRENT_SOURCE_DIR}/project/bin" LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_CURRENT_SOURCE_DIR}/project/bin" From ba81210150cc3ada1465dbb8a0ae811dd46ee889 Mon Sep 17 00:00:00 2001 From: Vano Date: Tue, 30 Jan 2024 01:18:12 +0200 Subject: [PATCH 5/6] fixed typo --- cmake/godotcpp.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/godotcpp.cmake b/cmake/godotcpp.cmake index c123c202..288d7adf 100644 --- a/cmake/godotcpp.cmake +++ b/cmake/godotcpp.cmake @@ -112,7 +112,7 @@ list(APPEND GODOT_DEFINITIONS REAL_T_IS_DOUBLE > $<$>,$>: - HOT_RELOAD_ENABLE + HOT_RELOAD_ENABLED > $<$: TOOLS_ENABLED From 4861eb1c3e17aa87f1a91be565e76d94574a5c9b Mon Sep 17 00:00:00 2001 From: Vano Date: Sat, 3 Feb 2024 22:04:24 +0200 Subject: [PATCH 6/6] MSVC lib prefix and path fix --- test/CMakeLists.txt | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 97e9bcd8..52f7d5db 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -20,14 +20,7 @@ if(${PLATFORM} STREQUAL "WEB") add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS}) set_target_properties(${PROJECT_NAME} PROPERTIES - PREFIX "lib" SUFFIX ".wasm" - RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/project/bin" - RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_CURRENT_SOURCE_DIR}/project/bin" - RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_CURRENT_SOURCE_DIR}/project/bin" - RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_CURRENT_SOURCE_DIR}/project/bin" - RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL "${CMAKE_CURRENT_SOURCE_DIR}/project/bin" - ) elseif(${PLATFORM} STREQUAL "MACOS") # TODO: create framework with cmake FRAMEWORK property @@ -60,11 +53,17 @@ target_link_options(${PROJECT_NAME} PRIVATE ${GODOT_LINK_FLAGS}) get_directory_property(LIBRARY_SUFFIX DIRECTORY ${GODOT_CPP_PATH} DEFINITION LIBRARY_SUFFIX) set_target_properties(${PROJECT_NAME} PROPERTIES + PREFIX "lib" LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/project/bin" LIBRARY_OUTPUT_DIRECTORY_DEBUG "${CMAKE_CURRENT_SOURCE_DIR}/project/bin" LIBRARY_OUTPUT_DIRECTORY_RELEASE "${CMAKE_CURRENT_SOURCE_DIR}/project/bin" LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_CURRENT_SOURCE_DIR}/project/bin" LIBRARY_OUTPUT_DIRECTORY_MINSIZEREL "${CMAKE_CURRENT_SOURCE_DIR}/project/bin" + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/project/bin" + RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_CURRENT_SOURCE_DIR}/project/bin" + RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_CURRENT_SOURCE_DIR}/project/bin" + RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_CURRENT_SOURCE_DIR}/project/bin" + RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL "${CMAKE_CURRENT_SOURCE_DIR}/project/bin" OUTPUT_NAME "${PROJECT_NAME}${LIBRARY_SUFFIX}" )