Ignore warnings in external modules when using CMake

后端 未结 1 1364
傲寒
傲寒 2020-12-19 14:22

I am using CMake GUI (no version) with CMake 3.6.1. I am using an external module with add_subdirectory that shows me some warnings th

相关标签:
1条回答
  • 2020-12-19 14:31

    Turning my comments into an answer

    That sounds like your external module does have a project() command. This resets the policies for this sub-module and below.

    To demonstrate a possible solution, lets say you have a external project as the following:

    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()
    

    You can now set CMAKE_POLICY_DEFAULT_CMP0054 to OLD (or even better to NEW; nobody really wanted the "OLD" behavior) to get rid of the "Policy CMP0054 is not set" warnings you will get 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 a default for policy CMP0054 to be used if none is explicitly given in your project or one of the external projects you are using.

    0 讨论(0)
提交回复
热议问题