Ignore warnings in external modules when using CMake

I am using CMake GUI (no version) with CMake 3.6.1. I use an external module with add_subdirectory , which shows me some warnings that I don't like (due to annoying pollution):

 CMake Warning (dev) at D:/Sources/.../external/g3log/latest/Build.cmake:11 (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): D:/Sources/.../external/g3log/latest/CMakeLists.txt:72 (INCLUDE) This warning is for project developers. Use -Wno-dev to suppress it. 

I want to hide these warnings without touching external files. -Wno-dev will be fine if it only g3log external module ( g3log ).

I tried using cmake_policy as shown below with no effect:

 cmake_policy(PUSH) cmake_policy(SET CMP0054 OLD) add_subdirectory(${g3log_DIR} ${CMAKE_BINARY_DIR}/../g3log) cmake_policy(POP) 
+2
cmake suppress-warnings cmake-gui
Jan 17 '17 at 11:30
source share
1 answer

Turning my comments back

It looks like your external module has a project() command. This resets the policies for this submodule and below.

To demonstrate a possible solution, let's say you have an external project as follows:

g3log / CMakeLists.txt

 cmake_minimum_required(VERSION 2.8) project(g3log NONE) set(VAR1 "Hello World") set(VAR2 "VAR1") if ("${VAR2}" STREQUAL "${VAR1}") message("CMP0054 old behavior") endif() 

Now you can set CMAKE_POLICY_DEFAULT_CMP0054 to OLD (or even better to NEW ; no one wanted the "OLD" behavior) to get rid of the "CMP0054 Policy Not Installed" warnings that you will receive with newer versions of CMake:

CMakeLists.txt

 cmake_minimum_required(VERSION 3.1) project(PolicyOverwrite NONE) set(CMAKE_POLICY_DEFAULT_CMP0054 NEW) add_subdirectory(g3log) 

Now you have set the default value for the CMP0054 policy, which will be used if no projects or one of the external projects that you use are explicitly specified in your project.

+2
Jan 17 '17 at 20:22
source share
— -



All Articles