From c3b38381ab2df6e6e4233e6ff3e7dd182414dc7b Mon Sep 17 00:00:00 2001 From: ethanol20924 <33417736+ethanol20924@users.noreply.github.com> Date: Fri, 16 Feb 2024 18:28:38 +0100 Subject: [PATCH] Small fix to allow for compiling with Homebrew installed Clang on Mac (#89) When building with Clang installed with Homebrew: ``` -- The C compiler identification is Clang 17.0.6 -- The CXX compiler identification is Clang 17.0.6 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: /opt/homebrew/opt/llvm/bin/clang - skipped -- Detecting C compile features -- Detecting C compile features - done -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /opt/homebrew/opt/llvm/bin/clang++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done ``` I get the following error: ``` /opt/homebrew/opt/llvm/bin/llvm-ranlib: error: Invalid option: '-no_warning_for_no_symbols' make[2]: *** [_deps/zstd-build/lib/libzstd.a] Error 1 make[2]: *** Deleting file `_deps/zstd-build/lib/libzstd.a' make[1]: *** [_deps/zstd-build/lib/CMakeFiles/libzstd_static.dir/all] Error 2 make: *** [all] Error 2 ``` If I instead build with AppleClang: ``` -- The C compiler identification is AppleClang 15.0.0.15000100 -- The CXX compiler identification is AppleClang 15.0.0.15000100 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang - skipped -- Detecting C compile features -- Detecting C compile features - done -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done ``` It works as expected. Source of the problem is found at `CMakeLists.txt:282`: ```CMake if(APPLE) SET(CMAKE_C_ARCHIVE_FINISH " -no_warning_for_no_symbols -c ") SET(CMAKE_CXX_ARCHIVE_FINISH " -no_warning_for_no_symbols -c ") endif() ``` Changing it to check specifically for AppleClang appears to fix the problem for me: ```CMake if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") SET(CMAKE_C_ARCHIVE_FINISH " -no_warning_for_no_symbols -c ") SET(CMAKE_CXX_ARCHIVE_FINISH " -no_warning_for_no_symbols -c ") endif() ``` --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e077cf8..7f4a34d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -279,7 +279,7 @@ target_compile_features( PRIVATE cxx_std_11 ) -if(APPLE) +if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") SET(CMAKE_C_ARCHIVE_FINISH " -no_warning_for_no_symbols -c ") SET(CMAKE_CXX_ARCHIVE_FINISH " -no_warning_for_no_symbols -c ") endif()