We catch errors during testing for policy violations CMP0054. An example can be found on the Internet at Build 367 .
cmake : CMake Warning (dev) at CMakeLists.txt:364 (if): At line:8 char:5 + cmake -G "Visual Studio 15 2017" -DCMAKE_BUILD_TYPE=$env:configur ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (CMake Warning (...s.txt:364 (if)::String) [], RemoteException + FullyQualifiedErrorId : NativeCommandError Policy CMP0054 is not set: Only interpret if() arguments as variables or keywords when unquoted. Run "cmake --help-policy CMP0054" for policy details. Use the cmake_policy command to set the policy and suppress this warning. Quoted variables like "MSVC" will no longer be dereferenced when the policy is set to NEW. Since the policy is not set the OLD behavior will be used. This warning is for project developers. Use -Wno-dev to suppress it.
This should be done like this:
if ("${CRYPTOPP_AMD64}" STREQUAL "1" OR "${CRYPTOPP_I386}" STREQUAL "1") ... endif()
The above statements are consistent with the CMake syntax for setting and using variables? , and this is the only thing that seemed to “just work” everywhere, regardless of whether the variable was set, was empty, had a value of 0, had a value of 1, or had a different value.
We removed the quotation marks from the variable to satisfy god’s damn policy, and all hell broke. Now we are lucky that we went through the CMake configuration without errors. We tried:
if (${CRYPTOPP_AMD64} STREQUAL "1" OR ${CRYPTOPP_I386} STREQUAL "1") ... endif()
and
if (${CRYPTOPP_AMD64} STREQUAL 1 OR ${CRYPTOPP_I386} STREQUAL 1) ... endif()
and
if (${CRYPTOPP_AMD64} EQUAL 1 OR ${CRYPTOPP_I386} EQUAL 1) ... endif()
Basically they lead to the error "CMake Error on CMakeLists.txt ... if arguments are given ...". For example, here is testing on Solaris 11:
CMake Error at CMakeLists.txt:507 (if): if given arguments: "EQUAL" "1" "AND" "NOT" "DISABLE_SSSE3" Unknown arguments specified
We do not control user machines, so changing the policy and running commands, such as cmake_policy, is out of the question for us. We do not expect users to do anything special. Users only need to create a directory, cd into the directory, and then run cmake. What is it.
What is the syntax we should use for variables that work everywhere, given the latest changes in CMake?
When we speak everywhere, we mean from Cmake 2.8 to Current and a variable that can be in any state, including set, empty, 0 value, 1 value or an unexpected value.
EDIT . We now catch error reports for unquoted variables on Windows machines. Another damn CMake error in Windows CMake Error when the compiler path has space .
CMake has been in the library for two years. This represents 18% of errors in our error reporter. This causes a disproportionate amount of problems for users.