From a026207a2d12a099549853b5b2fcc48610c9b859 Mon Sep 17 00:00:00 2001 From: scawful Date: Tue, 14 Oct 2025 01:06:35 -0400 Subject: [PATCH] refactor(build): update CMake configurations and toolchain for macOS - Modified CMake settings to ensure consistent use of the Homebrew LLVM/Clang installation on macOS. - Added a new toolchain file to specify the correct compiler and header search paths, resolving potential conflicts. - Updated CMake presets to enable the EMU build and set appropriate compiler flags. Benefits: - Enhances build reliability and compatibility on macOS by utilizing the Homebrew LLVM toolchain. - Streamlines the build process with improved configuration management. --- .clangd | 13 ++++----- CMakeLists.txt | 8 ++---- CMakePresets.json | 11 +++++--- cmake/llvm-brew.toolchain.cmake | 45 ++++++++++++++++++++++++++++++ src/app/gfx/util/palette_manager.h | 1 + 5 files changed, 62 insertions(+), 16 deletions(-) create mode 100644 cmake/llvm-brew.toolchain.cmake diff --git a/.clangd b/.clangd index 510a269d..2c0aa26a 100644 --- a/.clangd +++ b/.clangd @@ -1,8 +1,5 @@ CompileFlags: - Add: - - -std=c++23 - - -Wall - - -Wextra + CompilationDatabase: build Remove: - -mllvm - -xclang @@ -20,14 +17,16 @@ Hover: ShowAKA: Yes Diagnostics: + MissingIncludes: Strict ClangTidy: Add: - # - readability-* - # - modernize-* - performance-* - Remove: + - bugprone-* - readability-* - modernize-* + Remove: + # - readability-* + # - modernize-* - modernize-use-trailing-return-type - readability-braces-around-statements - readability-magic-numbers diff --git a/CMakeLists.txt b/CMakeLists.txt index 34e5c8b4..19cbb463 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,9 @@ set(CMAKE_POLICY_VERSION_MINIMUM 3.5 CACHE STRING "Minimum policy version for su # Set policies for compatibility cmake_policy(SET CMP0091 NEW) + +# Ensure we consistently use the dynamic MSVC runtime (/MD, /MDd) even when cached +set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>DLL" CACHE STRING "" FORCE) cmake_policy(SET CMP0048 NEW) cmake_policy(SET CMP0077 NEW) @@ -22,11 +25,6 @@ else() LANGUAGES CXX C) endif() -# Align Windows static builds (MSVC, clang-cl) with vcpkg's /MT runtime -if(MSVC OR (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND WIN32)) - set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") -endif() - # Enable ccache for faster rebuilds if available find_program(CCACHE_FOUND ccache) if(CCACHE_FOUND) diff --git a/CMakePresets.json b/CMakePresets.json index 1d96ac79..b6246892 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -17,7 +17,7 @@ "YAZE_BUILD_APP": "ON", "YAZE_BUILD_LIB": "ON", "YAZE_BUILD_Z3ED": "ON", - "YAZE_BUILD_EMU": "OFF" + "YAZE_BUILD_EMU": "ON" } }, { @@ -57,8 +57,12 @@ "lhs": "${hostSystemName}", "rhs": "Darwin" }, + "toolchainFile": "${sourceDir}/cmake/llvm-brew.toolchain.cmake", "cacheVariables": { - "CMAKE_OSX_DEPLOYMENT_TARGET": "11.0" + "CMAKE_OSX_DEPLOYMENT_TARGET": "11.0", + "CMAKE_C_COMPILER": "/opt/homebrew/opt/llvm@18/bin/clang", + "CMAKE_CXX_COMPILER": "/opt/homebrew/opt/llvm@18/bin/clang++", + "CMAKE_CXX_FLAGS": "-isystem /opt/homebrew/opt/llvm@18/include/c++/v1" } }, { @@ -162,6 +166,7 @@ "displayName": "macOS z3ed", "description": "macOS z3ed CLI with agent support", "inherits": "mac-ai", + "toolchainFile": "${sourceDir}/cmake/llvm-brew.toolchain.cmake", "binaryDir": "${sourceDir}/build", "cacheVariables": { "Z3ED_AI": "ON", @@ -170,8 +175,6 @@ "YAZE_BUILD_Z3ED": "ON", "YAZE_BUILD_EMU": "ON", "YAZE_BUILD_TESTS": "ON", - "YAZE_ENABLE_UI_TESTS": "ON", - "YAZE_ENABLE_IMGUI_TEST_ENGINE": "ON", "CMAKE_BUILD_TYPE": "Debug" } }, diff --git a/cmake/llvm-brew.toolchain.cmake b/cmake/llvm-brew.toolchain.cmake new file mode 100644 index 00000000..ab460685 --- /dev/null +++ b/cmake/llvm-brew.toolchain.cmake @@ -0,0 +1,45 @@ +# cmake/toolchains/homebrew-llvm.toolchain.cmake +# +# CMake Toolchain File for using the Homebrew LLVM/Clang installation on macOS. +# This ensures that the main project and all dependencies (like gRPC) use the +# correct compiler and header search paths. + +# 1. Set the target system (macOS) +set(CMAKE_SYSTEM_NAME Darwin) + +# 2. Find the Homebrew LLVM installation path +# We use execute_process to make this portable across machine architectures. +execute_process( + COMMAND brew --prefix llvm@18 + OUTPUT_VARIABLE HOMEBREW_LLVM_PREFIX + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +if(NOT EXISTS "${HOMEBREW_LLVM_PREFIX}") + message(FATAL_ERROR "Homebrew LLVM not found. Please run 'brew install llvm'. Path: ${HOMEBREW_LLVM_PREFIX}") +endif() + +message(STATUS "Using Homebrew LLVM from: ${HOMEBREW_LLVM_PREFIX}") + +# 3. Set the C and C++ compilers +set(CMAKE_C_COMPILER "${HOMEBREW_LLVM_PREFIX}/bin/clang") +set(CMAKE_CXX_COMPILER "${HOMEBREW_LLVM_PREFIX}/bin/clang++") + +# 4. Set the system root (sysroot) to the macOS SDK +# This correctly points to the system-level headers and libraries. +execute_process( + COMMAND xcrun --show-sdk-path + OUTPUT_VARIABLE CMAKE_OSX_SYSROOT + OUTPUT_STRIP_TRAILING_WHITESPACE +) +set(CMAKE_SYSROOT "${CMAKE_OSX_SYSROOT}") +message(STATUS "Using macOS SDK at: ${CMAKE_SYSROOT}") + +# 5. **[THE CRITICAL FIX]** Explicitly define the C++ standard library include directory. +# This forces CMake to add Homebrew's libc++ headers to the search path *before* +# any other system paths, resolving the header conflict for the main project + # and all dependencies. +set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES "${HOMEBREW_LLVM_PREFIX}/include/c++/v1") + +# 6. Set the default installation path for macOS frameworks +set(CMAKE_FIND_FRAMEWORK FIRST) \ No newline at end of file diff --git a/src/app/gfx/util/palette_manager.h b/src/app/gfx/util/palette_manager.h index 42cf08b9..fb0b9bb8 100644 --- a/src/app/gfx/util/palette_manager.h +++ b/src/app/gfx/util/palette_manager.h @@ -1,6 +1,7 @@ #ifndef YAZE_APP_GFX_PALETTE_MANAGER_H #define YAZE_APP_GFX_PALETTE_MANAGER_H +#include #include #include #include