-
-
Notifications
You must be signed in to change notification settings - Fork 620
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
Add support for CMake on macOS and Clang #1522
Comments
I've managed to compile it to a DyLib with apple's native Clang installed on 14.6.1. Not sure if that's the issue. cmake_minimum_required(VERSION 3.13)
project(Convenience VERSION 0.0.1 LANGUAGES CXX)
# Set C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_EXTENSIONS NO)
# Download Godot Bindings using FetchContent
include(FetchContent)
FetchContent_Declare(
GDExtension
GIT_REPOSITORY https://github.com/godotengine/godot-cpp.git
GIT_TAG godot-4.3-stable
)
FetchContent_MakeAvailable(GDExtension)
# Collect all source files (.h, .hpp, .cpp) in the src directory
file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/*.[ch]pp" "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp")
add_library(${PROJECT_NAME} SHARED ${SOURCES})
# Set output directory for DLLs/shared libraries
set(LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/project/bin")
# Determine architecture (x64 or x86)
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
set(ARCHITECTURE "x64")
else()
set(ARCHITECTURE "x86")
endif()
# Lowercase Build Type
string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER)
# Platform-specific settings
if (WIN32)
# Windows settings with architecture-specific output names
set_target_properties(${PROJECT_NAME} PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${LIBRARY_OUTPUT_DIRECTORY}"
ARCHIVE_OUTPUT_DIRECTORY "${LIBRARY_OUTPUT_DIRECTORY}"
RUNTIME_OUTPUT_DIRECTORY "${LIBRARY_OUTPUT_DIRECTORY}"
OUTPUT_NAME "convenience.windows.template_${ARCHITECTURE}_${CMAKE_BUILD_TYPE_LOWER}"
)
elseif (APPLE)
# macOS settings without architecture-specific output names
set_target_properties(${PROJECT_NAME} PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${LIBRARY_OUTPUT_DIRECTORY}"
ARCHIVE_OUTPUT_DIRECTORY "${LIBRARY_OUTPUT_DIRECTORY}"
RUNTIME_OUTPUT_DIRECTORY "${LIBRARY_OUTPUT_DIRECTORY}"
OUTPUT_NAME "convenience.macos.template_${CMAKE_BUILD_TYPE_LOWER}"
)
elseif (UNIX)
# Linux settings without architecture-specific output names
set_target_properties(${PROJECT_NAME} PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${LIBRARY_OUTPUT_DIRECTORY}"
ARCHIVE_OUTPUT_DIRECTORY "${LIBRARY_OUTPUT_DIRECTORY}"
RUNTIME_OUTPUT_DIRECTORY "${LIBRARY_OUTPUT_DIRECTORY}"
OUTPUT_NAME "convenience.linux.template_${CMAKE_BUILD_TYPE_LOWER}"
)
endif()
# Include the src directory for headers
target_include_directories(${PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src")
# Link the library with Godot's C++ bindings
target_link_libraries(${PROJECT_NAME} PUBLIC godot::cpp)
# Organize source files in the project tree
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/src" PREFIX src FILES ${SOURCES})
|
@aaronfranke Can we mark this as resolved now that the modernise PR is merged? |
Tested with commit a42b363, it compiles fine now. And the CMake code now has explicit support for both macOS and its different architectures, so that's great. The only thing mentioned in this issue that isn't done is adding a CI check for CMake on macOS, so that we can ensure everything keeps working. |
I have a CI PR which compiles for macos, but I am missing iOS support. #1726 |
Godot version
Master of godot-cpp
godot-cpp version
Master of godot-cpp
System information
macOS 14.5
Issue description
I'm not able to build using CMake on macOS:
Gives this error:
clang: error: unsupported option '-static-libgcc'
I believe this is caused by the current CMakeLists.txt file assuming that anything that isn't MSVC is GCC:
To fix this, in the CMakeLists.txt file, we should:
Steps to reproduce
Try to build with CMake on macOS.
Minimal reproduction project
Master branch of godot-cpp.
The text was updated successfully, but these errors were encountered: