MantisBT - CMake
View Issue Details
0015571CMakeModulespublic2015-05-16 16:182015-11-02 09:15
grahamb 
Rolf Eike Beer 
normalminoralways
closedfixed 
CMake 3.2.2 
CMake 3.3CMake 3.3 
0015571: CheckTypeSize causes a CMP0054 warning
Using CheckTypeSize with CMake >= 3.1 causes a CMP0054 warning.

Setting the policy in the module to VERSION 3.1 fixes the issue. There may be other modules similarly afflicted.
Any use of CheckTypeSize, e.g.

check_type_size(off64_t OFF64_T)
Sample output:

CMake Warning (dev) at C:/ProgramData/Chocolatey/lib/cmake.3.1.3/content/cmake-3.1.3-win32-x86/share/cmake-3.1/Modules/CheckTypeSize.cmake:232 (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 "C" 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):
  C:/buildbot/wireshark/wireshark-master-32/Wireshark-win32-libs/zlib-1.2.8/CMakeLists.txt:43 (check_type_size)
This warning is for project developers. Use -Wno-dev to suppress it.

CMake Warning (dev) at C:/ProgramData/Chocolatey/lib/cmake.3.1.3/content/cmake-3.1.3-win32-x86/share/cmake-3.1/Modules/CheckTypeSize.cmake:115 (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 "C" 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):
  C:/ProgramData/Chocolatey/lib/cmake.3.1.3/content/cmake-3.1.3-win32-x86/share/cmake-3.1/Modules/CheckTypeSize.cmake:249 (__check_type_size_impl)
  C:/buildbot/wireshark/wireshark-master-32/Wireshark-win32-libs/zlib-1.2.8/CMakeLists.txt:43 (check_type_size)
This warning is for project developers. Use -Wno-dev to suppress it.
No tags attached.
Issue History
2015-05-16 16:18grahambNew Issue
2015-05-16 16:43Rolf Eike BeerNote Added: 0038751
2015-05-16 16:43Rolf Eike BeerAssigned To => Rolf Eike Beer
2015-05-16 16:43Rolf Eike BeerStatusnew => assigned
2015-05-16 16:43Rolf Eike BeerCategoryCMake => Modules
2015-05-16 17:39grahambNote Added: 0038752
2015-05-16 17:39grahambNote Edited: 0038752bug_revision_view_page.php?bugnote_id=38752#r1779
2015-05-17 04:13Rolf Eike BeerNote Added: 0038753
2015-05-17 17:17grahambNote Added: 0038754
2015-05-18 10:09Brad KingNote Added: 0038761
2015-05-18 10:10Brad KingStatusassigned => resolved
2015-05-18 10:10Brad KingResolutionopen => fixed
2015-05-18 10:10Brad KingFixed in Version => CMake 3.3
2015-05-18 10:10Brad KingTarget Version => CMake 3.3
2015-05-18 10:21Rolf Eike BeerNote Added: 0038762
2015-05-18 10:28Brad KingNote Added: 0038763
2015-05-18 13:56grahambNote Added: 0038769
2015-05-18 14:06Brad KingNote Added: 0038770
2015-05-18 14:13Brad KingNote Added: 0038771
2015-05-19 13:04Brad KingNote Edited: 0038771bug_revision_view_page.php?bugnote_id=38771#r1781
2015-11-02 09:15Robert MaynardNote Added: 0039815
2015-11-02 09:15Robert MaynardStatusresolved => closed

Notes
(0038751)
Rolf Eike Beer   
2015-05-16 16:43   
This should fix it:

 http://www.cmake.org/gitweb?p=cmake.git;a=commitdiff;h=e9d726b1c5f584c0e475b86e09d433c5f22b5cac [^]

Please test and report back.
(0038752)
grahamb   
2015-05-16 17:39   
Nope same warning. The problem seems to be the quoting of "C" rather than the language variable, as in the warning message.

(0038753)
Rolf Eike Beer   
2015-05-17 04:13   
Having a variable "C" will likely break a lot of stuff. Where does that come from?
(0038754)
grahamb   
2015-05-17 17:17   
I think it's a false warning as there is no C variable.

However I want to get rid of the warning but can't as setting the policy in CMakeLists.txt does nothing due to the cmake_policy(VERSION 3.0) in the module.
(0038761)
Brad King   
2015-05-18 10:09   
Here is another approach:

 CheckTypeSize: Avoid if() auto-dereferene in quoted arguments
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=92146f3e [^]

A variable called "C" could be getting leaked from somewhere and does not necessarily have to be something your project sets. You can check with

 if(DEFINED C)
   message(...)
 endif()

just before the check_type_size call.
(0038762)
Rolf Eike Beer   
2015-05-18 10:21   
Since that module already uses policy push/pop I think it would be better to use my version and bump the required policy version. Those new policies were introduced for exactly that case, no?
(0038763)
Brad King   
2015-05-18 10:28   
Re 0015571:0038762: Fine with me. Please extend my topic for that and we'll squash it later.
(0038769)
grahamb   
2015-05-18 13:56   
I have located the errant C variable within the main CMakeLists.txt, renaming it fixes the CMP0054 warnings. Sorry for the noise.

Shame CMake doesn't have "local" variables to prevent name clashes like this.
(0038770)
Brad King   
2015-05-18 14:06   
Re 0015571:0038769: Thanks, I'm glad you fixed it locally.

FYI, the purpose of CMP0054 is to reduce the cases where name clashes can occur.
(0038771)
Brad King   
2015-05-18 14:13   
(edited on: 2015-05-19 13:04)
Revised change with approach in 0015571:0038762:

 CheckTypeSize: Avoid if() auto-dereferene in quoted arguments
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=6784f0a6 [^]

(0039815)
Robert Maynard   
2015-11-02 09:15   
Closing resolved issues that have not been updated in more than 4 months.