Skip to content

Add support for CMake on macOS and Clang #1522

Closed

Description

@aaronfranke

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:

cmake .
cmake --build .

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:

target_link_options(${PROJECT_NAME} PRIVATE
	$<$<NOT:${compiler_is_msvc}>:
		-static-libgcc
		-static-libstdc++
		-Wl,-R,'$$ORIGIN'
	>
)

To fix this, in the CMakeLists.txt file, we should:

  • Add support for Clang.
  • Add support for macOS.
  • Add a CI job to build and test CMake on macOS.

Steps to reproduce

Try to build with CMake on macOS.

Minimal reproduction project

Master branch of godot-cpp.

Activity

  1. added
    bug
    topic:buildsystem
    on Aug 7, 2024
  2. Max-Beier commented on Sep 4, 2024

    @Max-Beier

    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})
    
  3. enetheru commented on Nov 23, 2024

    @enetheru
    Collaborator

    @aaronfranke Can we mark this as resolved now that the modernise PR is merged?

  4. aaronfranke commented on Nov 26, 2024

    @aaronfranke
    MemberAuthor

    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.

  5. added this to the 4.x milestone on Jan 21, 2025
  6. enetheru commented on Mar 6, 2025

    @enetheru
    Collaborator

    I have a CI PR which compiles for macos, but I am missing iOS support. #1726

  7. enetheru commented on Oct 16, 2025

    @enetheru
    Collaborator

    @aaronfranke the CI job for macos has been working for a while now, can this be closed now?

  8. aaronfranke commented on Oct 16, 2025

    @aaronfranke
    MemberAuthor

    Yes, closing as implemented. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcmakeplatform:macostopic:buildsystem

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions