I am trying to build a CMake C++ Project with C++20 because I want to use the <ranges> library. I have tested my gcc compiler with the -std=c++20 flag and it works. However, when I build a project with CMake, it always chooses my (Apple) system's clang compiler, which can't find the <ranges> library.
This is despite me putting
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
in my CMakeLists.txt file. I even tried set(CMAKE_CXX_EXTENSIONS ON), as well as including the line set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++20") (which I don't think is technically necessary but some stackoverflow post suggested it), and neither of them worked. How can I get CMake to automatically find the right compiler?