Use of target_compile_features() prevents build with uncommon compiler
I am building a project that uses CMake (jsoncpp). This works cleanly on all platforms I support, with the exception of Linux-on-POWER using the IBM XL C++ compiler:
CMake Error at src/lib_json/CMakeLists.txt:89 (target_compile_features):
target_compile_features The compiler feature "cxx_auto_type" is not known
to CXX compiler
"XL"
version 16.1.1.4.
I tracked down this issue. It is occurring not because the compiler lacks support for the specified feature (indeed, it is C++14 compliant), but due to a lack of a Modules/Compiler/*-CXX-FeatureTests.cmake
script containing version-vs.-feature information for the compiler.
Perhaps such a script could be written for XL C/C++, but I would argue that it is incorrect behavior for CMake to assume that the compiler is unsuitable if no script exists for it.
Rather, CMake should allow the build to proceed, and the user to deal with any resulting compile errors, as would be the case in most other build systems. For extra niceness, CMake could print a warning like "I don't know about this compiler, I can't perform the requested feature check, proceed at your own risk." It should certainly not error out with a misleading message, without allowing a way forward. I ended up having to comment out the target_compile_features()
call to get a working build (which completed successfully).
(I would further suggest that CMake should have a fallback path, where if no compiler-feature script is available, it runs a series of compile/exec tests to determine whether a feature is supported or not. This would allow target_compile_features()
to have universal coverage, and render the feature scripts more of a speed optimization than a necessity.)