[cmake-developers] Policy CMP0054 warning (was: File Building issue)

Brad King brad.king at kitware.com
Wed Jun 10 10:23:47 EDT 2015


On 06/10/2015 10:11 AM, Arunava Nag wrote:
> cmake_minimum_required(VERSION 2.8)
[snip]
> if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
[snip]
> CMake Warning (dev) at CMakeLists.txt:6 (if):
>   Policy CMP0054 is not set: Only interpret if() arguments as variables or

The policy is documented here:

 http://www.cmake.org/cmake/help/v3.3/policy/CMP0054.html

In this case CMAKE_CXX_COMPILER_ID is "MSVC" so

 if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")

after expansion of variable references becomes:

 if ("MSVC" STREQUAL "Clang")

but there is also a variable named "MSVC" set to "1" meant
for code to be able to do if(MSVC) to check for that compiler
(left from before we had CMAKE_<LANG>_COMPILER_ID).  The
if() command expands that variable so it becomes

 if ("1" STREQUAL "Clang")

This is not the check that was intended by the above code but
happens to get the right answer by accident.  For this reason
CMP0054 was introduced to get rid of the if() command's
auto-dereference behavior in quoted arguments.

You can either change your cmake_minimum_required call to

 cmake_minimum_required(VERSION 3.1)

or add the lines

 if (POLICY CMP0054)
   cmake_policy(SET CMP0054 NEW)
 endif()

to fix evaluation of the conditional.  Or you can change the
conditional to another form that does not hit this case at all:

 if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")

-Brad



More information about the cmake-developers mailing list