From 24dcab054c98bc09c600e7f4a2c39947f5fa1683 Mon Sep 17 00:00:00 2001 From: sal Date: Thu, 12 Oct 2023 06:35:40 -0400 Subject: [PATCH] added macos support to cmake/vscode/gdext project files --- .vscode/c_cpp_properties.json | 11 ++++++-- .vscode/launch.json | 43 +++++++++++++++++++++++++++++ CMakeLists.txt | 18 ++++++------ CMakePresets.json | 11 ++++++-- cmake/godot-dev-configuration.cmake | 22 ++++++++++----- cmake/vcpkg-init.cmake | 26 ++++++++++++++++- cmake/vcpkg-install-deps.cmake | 7 ----- project/bin/roguelite.gdextension | 11 -------- project/roguelite.gdextension | 13 +++++++++ src/entity/character/character.cpp | 6 ++-- src/entity/level.cpp | 8 +++--- src/util/bind.hpp | 2 +- 12 files changed, 131 insertions(+), 47 deletions(-) delete mode 100644 project/bin/roguelite.gdextension create mode 100644 project/roguelite.gdextension diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index ec003f2..b8b434c 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -6,14 +6,21 @@ "configurationProvider": "ms-vscode.cmake-tools", "intelliSenseMode": "linux-gcc-x64", "cppStandard": "gnu++23", - "compilerPath": "/usr/bin/g++" + "compilerPath": "g++" }, { "name": "GDNative C++ (Clang)", "configurationProvider": "ms-vscode.cmake-tools", "intelliSenseMode": "linux-clang-x64", "cppStandard": "gnu++23", - "compilerPath": "/usr/bin/clang++" + "compilerPath": "clang++" + }, + { + "name": "Mac GDNative C++ (Clang)", + "configurationProvider": "ms-vscode.cmake-tools", + "intelliSenseMode": "macos-clang-x64", + "cppStandard": "gnu++23", + "compilerPath": "clang++" }, { "name": "GDNative C++ (MSVC)", diff --git a/.vscode/launch.json b/.vscode/launch.json index 3651dc0..9784576 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -123,6 +123,49 @@ "visualizerFile": "${workspaceFolder}/extern/godot-engine/platform/windows/godot.natvis", "internalConsoleOptions": "openOnSessionStart", "console": "internalConsole", + }, + { + "name": "project (lldb)", + "type": "lldb", + "request": "launch", + "cwd": "${workspaceFolder}", + "args": [ + "--debug", + "--verbose", + "--path", + "${workspaceFolder}/project" + ], + "linux": { + "program": "${workspaceFolder}/extern/godot-engine/bin/godot.linuxbsd.editor.dev.x86_64" + }, + "windows": { + "program": "${workspaceFolder}/extern/godot-engine/bin/godot.windows.editor.dev.x86_64.exe" + }, + "osx": { + "program": "${workspaceFolder}/extern/godot-engine/bin/godot.macos.editor.dev.arm64" + } + }, + { + "name": "editor (lldb)", + "type": "lldb", + "request": "launch", + "cwd": "${workspaceFolder}", + "args": [ + "--editor", + "--debug", + "--verbose", + "--path", + "${workspaceFolder}/project" + ], + "linux": { + "program": "${workspaceFolder}/extern/godot-engine/bin/godot.linuxbsd.editor.dev.x86_64" + }, + "windows": { + "program": "${workspaceFolder}/extern/godot-engine/bin/godot.windows.editor.dev.x86_64.exe" + }, + "osx": { + "program": "${workspaceFolder}/extern/godot-engine/bin/godot.macos.editor.dev.arm64" + } } ] } diff --git a/CMakeLists.txt b/CMakeLists.txt index be8ab78..a9784ce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -129,14 +129,16 @@ target_include_directories(${PROJECT_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src" ) -# linker options for the gdextension library -target_link_options(${PROJECT_NAME} PRIVATE - $<$: - -static-libgcc - -static-libstdc++ - -Wl,-R,'$$ORIGIN' - > -) +if (NOT APPLE) + # linker options for the gdextension library + target_link_options(${PROJECT_NAME} PRIVATE + $<$: + -static-libgcc + -static-libstdc++ + -Wl,-R,'$$ORIGIN' + > + ) +endif() # ======================================================================= # Optional configuration / build features diff --git a/CMakePresets.json b/CMakePresets.json index c640c99..2e44c71 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -11,6 +11,10 @@ "value": "x64", "strategy": "external" }, + "toolset": { + "value": "host=x64", + "strategy": "external" + }, "environment": { "NINJA_STATUS": "%p [%es] (%f/%t) -" } @@ -29,7 +33,8 @@ "hidden": true, "cacheVariables": { "CMAKE_C_COMPILER": "cl", - "CMAKE_CXX_COMPILER": "cl" + "CMAKE_CXX_COMPILER": "cl", + "VCPKG_TARGET_TRIPLET": "x64-windows-static-md" }, "condition": { "type": "equals", @@ -108,9 +113,9 @@ "CMAKE_CXX_COMPILER": "clang++" }, "condition": { - "type": "equals", + "type": "notEquals", "lhs": "${hostSystemName}", - "rhs": "Linux" + "rhs": "Windows" } }, { diff --git a/cmake/godot-dev-configuration.cmake b/cmake/godot-dev-configuration.cmake index 2bb66df..6196c3d 100644 --- a/cmake/godot-dev-configuration.cmake +++ b/cmake/godot-dev-configuration.cmake @@ -43,9 +43,14 @@ endif() # Godot editor/engine debug build # ======================================================================= +string(TOLOWER "${CMAKE_SYSTEM_NAME}" host_os) + # define variable to be used in the engine build when specifying platform. set(host_os_engine "${host_os}") -if(UNIX) +if (APPLE) + # ${CMAKE_SYSTEM_NAME} returns Darwin, but the scons platform name will be macos + set(host_os_engine "macos") +elseif(UNIX) # the scons build expects linuxbsd to be passed in as the platform # when building on linux, so just append bsd to CMAKE_SYSTEM_NAME set(host_os_engine "${host_os}bsd") @@ -70,16 +75,19 @@ message(NOTICE "godot_debug_editor_executable = ${godot_debug_editor_executable} if(NOT EXISTS "${godot_debug_editor_executable}") message("Godot engine debug binaries not found, invoking debug build of engine...") - execute_process( - COMMAND scons platform=${host_os} arch=x64 target=editor use_static_cpp=yes dev_build=yes debug_symbols=yes optimize=none use_lto=no --clean - WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/extern/godot-engine" - COMMAND_ERROR_IS_FATAL ANY - ) + set(GODOT_ENGINE_CLEAN_BUILD OFF) + if (GODOT_ENGINE_CLEAN_BUILD MATCHES ON) + execute_process( + COMMAND "${SCONS_PROGRAM}" arch=x64 target=editor use_static_cpp=yes dev_build=yes debug_symbols=yes optimize=none use_lto=no --clean + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/extern/godot-engine" + COMMAND_ERROR_IS_FATAL ANY + ) + endif() # this build should only ever need to be run once (unless the enging debug binaries # are deleted or you want to change the build configuration/command invoked below). execute_process( - COMMAND scons platform=${host_os} arch=x64 target=editor use_static_cpp=yes dev_build=yes debug_symbols=yes optimize=none use_lto=no + COMMAND "${SCONS_PROGRAM}" arch=x64 target=editor use_static_cpp=yes dev_build=yes debug_symbols=yes optimize=none use_lto=no WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/extern/godot-engine" COMMAND_ERROR_IS_FATAL ANY ) diff --git a/cmake/vcpkg-init.cmake b/cmake/vcpkg-init.cmake index 7da3779..362cf62 100644 --- a/cmake/vcpkg-init.cmake +++ b/cmake/vcpkg-init.cmake @@ -9,9 +9,33 @@ if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/extern/vcpkg/ports") ) endif() +# ======================================================================= +# VCPKG triplet definition (should enforce static linkage for all deps) +# This would typically be passed in from CMakePresets.json, but if +# the cmake configuration is invoked without using a preset this fallback +# should define a preset that prefers static linkage for 3rd party libs. +# ======================================================================= + +if (NOT VCPKG_TARGET_TRIPLET) + if (WIN32) + # static-md enforces static linkage to all dependencies, + # as well as dynamic linkage to the C runtime for consistency. + # if this gives you trouble change to "x64-windows-static". + set(VCPKG_TARGET_TRIPLET "x64-windows-static-md") + elseif(APPLE) + if ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "arm64") + set(VCPKG_TARGET_TRIPLET "arm64-macos") + else() + set(VCPKG_TARGET_TRIPLET "x64-macos") + endif() + elseif(UNIX) + set(VCPKG_TARGET_TRIPLET "x64-linux") + endif() +endif() + # ======================================================================= # Define VCPKG toolchain file. This would typically be passed in from -# CMakePresets.json, but if the cmake configuration is invoked without +# CMakePresets.json, but if the cmake configuration is invoked without # using a preset this fallback should detect that the path is missing. # ======================================================================= if(NOT CMAKE_TOOLCHAIN_FILE) diff --git a/cmake/vcpkg-install-deps.cmake b/cmake/vcpkg-install-deps.cmake index b378559..057c0db 100644 --- a/cmake/vcpkg-install-deps.cmake +++ b/cmake/vcpkg-install-deps.cmake @@ -1,10 +1,3 @@ -# ======================================================================= -# VCPKG triplet definition (should enforce static linkage for all deps) -# ======================================================================= - -string(TOLOWER "${CMAKE_SYSTEM_NAME}" host_os) -set(VCPKG_TARGET_TRIPLET "x64-${host_os}-static") - # ======================================================================= # VCPKG bootstrap / initialization. # ======================================================================= diff --git a/project/bin/roguelite.gdextension b/project/bin/roguelite.gdextension deleted file mode 100644 index 8f52392..0000000 --- a/project/bin/roguelite.gdextension +++ /dev/null @@ -1,11 +0,0 @@ -[configuration] - -entry_symbol = "extension_library_init" -compatibility_minimum = 4.1 - -[libraries] - -windows.debug.x86_64 = "res://bin/roguelite.windows.64.debug.dll" -windows.release.x86_64 = "res://bin/roguelite.windows.64.release.dll" -linux.debug.x86_64 = "res://bin/roguelite.linux.64.debug.so" -linux.release.x86_64 = "res://bin/roguelite.linux.64.release.so" diff --git a/project/roguelite.gdextension b/project/roguelite.gdextension new file mode 100644 index 0000000..ba3ff49 --- /dev/null +++ b/project/roguelite.gdextension @@ -0,0 +1,13 @@ +[configuration] + +entry_symbol = "extension_library_init" +compatibility_minimum = 4.1 + +[libraries] + +windows.debug.x86_64 = "res://bin/roguelite.windows.64.debug.dll" +windows.release.x86_64 = "res://bin/roguelite.windows.64.release.dll" +linux.debug.x86_64 = "res://bin/libroguelite.linux.64.debug.so" +linux.release.x86_64 = "res://bin/libroguelite.linux.64.release.so" +macos.debug = "res://bin/libroguelite.darwin.64.debug.dylib" +macos.release = "res://bin/libroguelite.darwin.64.release.dylib" diff --git a/src/entity/character/character.cpp b/src/entity/character/character.cpp index 498b18d..1031d48 100644 --- a/src/entity/character/character.cpp +++ b/src/entity/character/character.cpp @@ -49,13 +49,13 @@ namespace rl if (m_character_controller != nullptr) { signal::connect(m_character_controller) - <=> slot(this, on_character_movement); + <=> signal_callback(this, on_character_movement); signal::connect(m_character_controller) - <=> slot(this, on_character_rotate); + <=> signal_callback(this, on_character_rotate); signal::connect(m_character_controller) - <=> slot(this, on_character_shoot); + <=> signal_callback(this, on_character_shoot); } } diff --git a/src/entity/level.cpp b/src/entity/level.cpp index b6d51d0..539693c 100644 --- a/src/entity/level.cpp +++ b/src/entity/level.cpp @@ -36,10 +36,10 @@ namespace rl if (controller != nullptr) { signal::connect(controller) - <=> slot(this, on_character_position_changed); + <=> signal_callback(this, on_character_position_changed); signal::connect(m_player) - <=> slot(this, on_player_spawn_projectile); + <=> signal_callback(this, on_player_spawn_projectile); } } @@ -100,10 +100,10 @@ namespace rl projectile->set_rotation(firing_pt->get_global_rotation()); signal::connect(projectile) - <=> slot(this, on_physics_box_entered); + <=> signal_callback(this, on_physics_box_entered); signal::connect(projectile) - <=> slot(this, on_physics_box_exited); + <=> signal_callback(this, on_physics_box_exited); } this->add_child(projectile); diff --git a/src/util/bind.hpp b/src/util/bind.hpp index 8801555..1d45c44 100644 --- a/src/util/bind.hpp +++ b/src/util/bind.hpp @@ -22,7 +22,7 @@ #define bind_member_function(class_name, func_name) method<&class_name::func_name>::bind(#func_name) -#define slot(slot_owner, slot_callback) \ +#define signal_callback(slot_owner, slot_callback) \ std::forward_as_tuple(godot::Callable(slot_owner, #slot_callback), slot_owner) #define bind_property(class_name, prop_name, prop_type) \