【问题标题】:CMake not respecting command line optionsCMake不尊重命令行选项
【发布时间】:2017-04-27 13:56:12
【问题描述】:

Ubuntu 14_04、gcc 4.8.4、cmake 2.8.12.2

我希望为UnitTest++ 添加其他选项。我通过 UTPP_CODE_COVERAGE 添加了代码覆盖率,但在常规构建时将其关闭。这似乎失败了 - Makefile 中没有任何内容可以通过 set(CMAKE_CXX_FLAGS 选项指定。

所以我查看了UTPP_AMPLIFY_WARNINGS 命令是否有效

无论我是打开还是关闭它进行编译,Makefile 都没有区别。

在终端我用

编译

$ cmake -G "Unix Makefiles" -DUTPP_AMPLIFY_WARNINGS=ON ../

但是当我分析生成的 Makefile -Wall 在输出中找不到。它甚至不在 CMakeCache.txt 中

我做错了什么?

【问题讨论】:

  • 'make VERBOSE=1' 的输出是否显示 -Wall?此项目的 CMakeLists.txt 不会将更新后的 CMAKE_CXX_FLAGS 写回缓存,因此 -Wall 不会出现在 CMakeCache.txt 中。递归地为 -Wall 查找构建目录以查看它的指定位置。

标签: cmake


【解决方案1】:

我可以确认您观察到的情况。似乎所需的警告级别在CMakeLists.txt 文件中已经是默认值,并且设置 -Wall 标志的命令set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror") 已达到并执行(已使用 message() 对此进行了测试。如果这里没有其他答案,在至少你知道你不是一个人想知道它是怎么来的。

cmake_minimum_required(VERSION 2.8.1)
project(UnitTest++)

option(UTPP_USE_PLUS_SIGN
    "Set this to OFF if you wish to use '-cpp' instead of '++' in lib/include paths"
    ON)
option(UTPP_INCLUDE_TESTS_IN_BUILD
    "Set this to OFF if you do not wish to automatically build or run unit tests as part of the default cmake --build"
    ON)
option(UTPP_AMPLIFY_WARNINGS
    "Set this to OFF if you wish to use CMake default warning levels; should generally only use to work around support issues for your specific compiler"
    ON)

...

# up warning level for project
if (${UTPP_AMPLIFY_WARNINGS})
    # instead of getting compiler specific, we're going to try making an assumption that an existing /W# means
    # we are dealing with an MSVC or MSVC-like compiler (e.g. Intel on Windows)
    if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
        # message(STATUS "CMAKE_CXX_FLAGS MATCHES")
        string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX")
    else()
        # message(STATUS "set(CMAKE_CXX_FLAGS")
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror")
    endif()
endif()

【讨论】:

  • 即使我尝试将其关闭,makefile 中也不会出现任何内容。我希望将我自己的选项添加到 makefile 中,但默认情况下会关闭。我没有得到预期的输出,所以我开始查看它附带的输出。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-25
  • 2015-11-17
相关资源
最近更新 更多