dune_require_cxx_standard() not working on current macOS with AppleClang
System Specs
- macOS: 10.15.5 (Catalina)
- AppleClang: 11.0.0
- CMake: 3.18.2
Problem Description
On recent versions of macOS, dune_require_cxx_standard()
is not working and a fallback C++ standard below the standard specified in the command is used.
In our particular problem, we set
dune_require_cxx_standard(MODULE "dorie" VERSION 17)
However, we end up with both a -std=c++17
and a -std=gnu++11
flag in the list of CXX compiler flags. The compiler then uses the lowest standard in the list and cannot compile our code (which is intended for C++17).
Workaround
The problem could be remedied by either
-
Setting the
CXX_STANDARD
andCXX_STANDARD_REQUIRED
property of the targets explicitly:target_set_property(${target} PROPERTIES # Set standard to C++17 CXX_STANDARD 17 # Avoid "fallback" to lower standards if the compiler does not support the requested one CXX_STANDARD_REQUIRED TRUE )
OR...
-
Setting the C++ standard as target compile feature (preferred solution):
target_compile_features(${target} PUBLIC cxx_std_17)
Possible Cause
CMake is actually skipping the compiler check. It might therefore not know the supported standard versions by AppleClang v11 or incorrectly set the flags checked in the code of dune_require_cxx_standard()
. This might be an issue on CMake side. From the CMake output:
-- The CXX compiler identification is AppleClang 11.0.0.11000033
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Checking for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
Conclusion
Workaround 1) demonstrates that dune_require_cxx_standard()
is somehow failing its purpose on a system with the given specs.