Our CMakeFile.txt contains the following for SunCC code paths. SunCC uses -xarch=XXX rather than GCC style -mXXX.
CHECK_CXX_COMPILER_FLAG("-xarch=sha" CRYPTOPP_IA32_SHA)
When we run CMake under Sun's compiler it results in:
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test CRYPTOPP_IA32_SSSE3
-- Performing Test CRYPTOPP_IA32_SSSE3 - Success
-- Performing Test CRYPTOPP_IA32_SSE4
-- Performing Test CRYPTOPP_IA32_SSE4 - Success
-- Performing Test CRYPTOPP_IA32_CLMUL
-- Performing Test CRYPTOPP_IA32_CLMUL - Success
-- Performing Test CRYPTOPP_IA32_AES
-- Performing Test CRYPTOPP_IA32_AES - Success
-- Performing Test CRYPTOPP_IA32_SHA
-- Performing Test CRYPTOPP_IA32_SHA - Success
...
However, when we compile it results in:
$ make sha-simd.o shacal2-simd.o VERBOSE=1
make -f CMakeFiles/cryptopp-object.dir/build.make CMakeFiles/cryptopp-object.dir/sha-simd.cpp.o
Building CXX object CMakeFiles/cryptopp-object.dir/sha-simd.cpp.o
/opt/solarisstudio12.4/bin/CC -m32 -template=no%extdef -g -xO2 -DNDEBUG -xarch=sha -o CMakeFiles/cryptopp-object.dir/sha-simd.cpp.o -c /export/home/test/sha-simd.cpp
CC: Warning: illegal use of -xarch option, illegal value ignored: sha
make -f CMakeFiles/cryptopp-object.dir/build.make CMakeFiles/cryptopp-object.dir/shacal2-simd.cpp.o
Building CXX object CMakeFiles/cryptopp-object.dir/shacal2-simd.cpp.o
/opt/solarisstudio12.4/bin/CC -m32 -template=no%extdef -g -xO2 -DNDEBUG -xarch=sha -o CMakeFiles/cryptopp-object.dir/shacal2-simd.cpp.o -c /export/home/test/shacal2-simd.cpp
CC: Warning: illegal use of -xarch option, illegal value ignored: sha
Adding SunCC's -errwarn and -errwarn=%all does not help CMake to detect the failure.
The message could cause a lot of problems for users. It also violates our governance for clean compiles. We would like to clean it up and avoid any trouble.
How do we tell CMake to fail the CHECK_CXX_COMPILER_FLAG test on an illegal value?
I guess, when checks a compiler flag, CMake simply verifies result of the compilation command. As "Warning" message doesn't affect on result, CMake cannot detect that the flag is actually ignored.
You may manually test the flag with try_compile command, so you can check output for some patterns (e.g., for "Warning").
There is also CHECK_CXX_SOURCE_COMPILES macro, which already accepts pattern for match.
See also that question and my answer for it.