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?
The best we have been able to do is add a custom
CheckCompilerOption
. However, it has other problems because CMake does not supply accurateCXXFLAGS
when CMakeLists.txt is executed. The problem surfaces during cross-compiles. Also see CMake Issue 18813.The first version with the dereference was wrong. The CMake docs for"${${variable}}"
looks strange, but I believe its correct based on some existing code.function
don't discuss it and don't offer an example, so we were flying blind again. It is mentioned in What's the CMake syntax to set and use variables? on Stack Overflow.It can be called like expected:
If you need to go back further than CMake 3.0 (like to Ubuntu 10 or CentOS 5 with CMake 2.8), then abandon
CHECK_CXX_COMPILER_FLAG
and use the top part of the function for Clang, GCC, ICC, etc.GCC's syntax for checking is an option is shown below. The command uses SSSE3 as an example.