cginternals/cmake-init

CMake Warning: Policy CMP0054 is not set

j-o opened this issue · 6 comments

j-o commented

Output using CMake 3.6.1.:

Lib baselib
Lib fiblib
Example fibcmd
Example fibgui
CMake Warning (dev) at cmake/CompileOptions.cmake:52 (if):
  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.
Call Stack (most recent call first):
  source/tests/CMakeLists.txt:17 (include)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at cmake/CompileOptions.cmake:67 (if):
  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.
Call Stack (most recent call first):
  source/tests/CMakeLists.txt:17 (include)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at cmake/CompileOptions.cmake:94 (if):
  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.
Call Stack (most recent call first):
  source/tests/CMakeLists.txt:17 (include)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at cmake/CompileOptions.cmake:144 (if):
  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.
Call Stack (most recent call first):
  source/tests/CMakeLists.txt:17 (include)
This warning is for project developers.  Use -Wno-dev to suppress it.

Test fiblib-test
Configuring done

Seems like MSVC is a variable defined when running CMake with a Visual Studio generator. Then, the compiler id check against "MSVC" can be interpreted as a compiler id check against On if CMake would dereference "MSVC" instead of treating it as a string.
However, we intentionally set the policy CMP0054 to NEW so that this behavior should not occur and even the warning should not occur. Can someone with a MSVC generator can have a look at this?

It seems that the problem is in sources/tests/CMakeLists.txt: cmake_minimum_required resets the CMake policy settings and CompileOptions.cmake is included before setting CMP0054 to NEW.
I've seen this warning when building glbinding with tests (MSVC).

Thanks for investigating. I think this can be fixed. 😄

What happens when you build cmake-init based projects with CMake 3.0? I would assume that it implicitly dereferences MSVC to On or Off, so that CompileOptions.cmake would never be able to detect the MSVC compiler. I'm not sure if this is true, i never tested this behavior.
Note: CMP0054 was introduced in CMake 3.1, and you allow building your projects with CMake 3.0

The second problem I suppose is solved as our set_policy function tests internally if the policy is available with the current CMake version.
The old behavior that is active with CMake 3.0 should indeed result in wrong behavior using MSVC generators; we have to adjust the code accordingly.

I suggest we discuss the CMake 3.0 and MSVC compiler options issue in #49.