I installed SFML on MacOS with
brew install sfml
a sample project compiles just fine with the default c++ compiler on MacOS which is Clang16 on my machine.
CMake's "find_package" works flawlessly and finds SFML. Great!
However, Clang 16 seems to not support C++20-Modules, so I installed Clang19 and GCC-14.2 via homebrew, which both do support Modules:
brew install llvm
brew install gcc
When i setup the Toolchain in Clion with these compilers i can run a hello-world example printing to std::cout without problems. However, the moment i include the SFML Libraries both Compilers give me a plethora of weird error messages.
I did the same thing with GCC-14.2 on Windows with the difference, that here i compiled SFML with that same GCC-14.2 Compiler and i can run the project using SFML and Modules on Windows.
So i assume that the installed version of SFML, that i got with brew, is not compatible with GCC-14.2 or Clang 19.
How would i proceed from here?
Is there a way to reinstall SFML with brew in a "GCC-14.2" or "Clang19" version? Or do i need to compile the SFML Source Code with one of these compilers and replace the files brew installed with the new files?
I cannot find anywhere information how to make brew installed libraries to work with other compilers. Maybe someone can give me a push in the right direction, thanks!
EDIT: I got it to compile after some detours.
1. I uninstalled the SFML version i got via brew with
brew uninstall sfml
2. I installed the newest llvm version (llvm 19) with brew:
brew install llvm
3. I added it to the path, so i could use the new compiler via the terminal
echo 'export PATH="/opt/homebrew/opt/llvm/bin:$PATH"' >> ~/.zshrc
4. next i got the newest SFML version, compiling it with the new clang19 compiler and enabling shared libs and finally installed it:
git clone https://github.com/SFML/SFML.git
cd SFML
mkdir build && cd build
cmake .. -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -DBUILD_SHARED_LIBS=ON
make
sudo make install
An interesting note: I was not allowed to compile it with GCC. CMake outright refused it with a message stating that SFML is only allowed to be compiled with clang on MacOS" or someting like that. Thats why i used Clang and not GCC for compiling SFML on MacOS.
All relevant SFML libraries were now being saved to /usr/local/lib
5. The CMakeLists.txt File looks like this:
cmake_minimum_required(VERSION 3.28)
project(myProject LANGUAGES CXX)
find_package(SFML COMPONENTS System Graphics)
set(SOURCES main.cpp)
include_directories(/Users/UserName/Documents/Programming/SFML/include)
add_executable(myProject ${SOURCES})
target_sources(myProject
PUBLIC
FILE_SET CXX_MODULES FILES
Window.cppm
Game.cppm
)
target_compile_features(myProject PRIVATE cxx_std_23)
target_link_libraries(myProject /Users/UserName/Documents/Programming/SFML/extlibs/libs-macos/Frameworks/freetype.framework/Versions/A/freetype SFML::System SFML::Graphics)
I had problems with FreeType which would not be recognized, even when installed via "brew install freetype". I had to link against the provided freetype file that comes with the SFML Source Code in the folder "extlibs". Also, despite find_package(...) being able to find SFML, the SFML Include Files were not available, thus i had to include them manually via "include_directories(...) in CMakeLists.txt. After that, the program finally compiled. I can now use C++ Modules with SFML 3 RC on my MacOS System.