与添加的消毒剂重新配置的cmake并非触发忍者以重新编译

发布于 2025-02-13 16:20:04 字数 1007 浏览 2 评论 0原文

让我们假设一个最小的顶级cmakelists.txt类似:

  1 cmake_minimum_required(VERSION 3.22)
  2 set(CMAKE_CXX_STANDARD 20)
  3 
  4 project(stackoverflow LANGUAGES CXX C)
  5 
  6 add_executable(prog src/main.cpp)
  7 
  8 option(ENABLE_SANITIZER "Enables sanitizer" OFF)
  9 if(ENABLE_SANITIZER)
 10   target_compile_options(prog PUBLIC -fsanitize=address)
 11   target_link_options(prog PUBLIC -fsanitize=address)
 12 endif()

其中选项enable_sanitizer在构建中添加了地址消毒剂。

当我使用消毒剂配置

cmake -S . -B ./build -G "Ninja Multi-Config" -DENABLE_SANITIZER=ON

并随着

cmake --build ./build/ --target prog 

应有的一切编译,但是当我重新配置

cmake -S . -B ./build -G "Ninja Multi-Config"

会发生这种情况:

ninja: no work to do.

并再次构建它时,忍者告诉我,当我明确删除编译选项和链接选项时,为什么 为什么会发生这种情况?

Let's assume a minimal top level CMakeLists.txt like this:

  1 cmake_minimum_required(VERSION 3.22)
  2 set(CMAKE_CXX_STANDARD 20)
  3 
  4 project(stackoverflow LANGUAGES CXX C)
  5 
  6 add_executable(prog src/main.cpp)
  7 
  8 option(ENABLE_SANITIZER "Enables sanitizer" OFF)
  9 if(ENABLE_SANITIZER)
 10   target_compile_options(prog PUBLIC -fsanitize=address)
 11   target_link_options(prog PUBLIC -fsanitize=address)
 12 endif()

Where the option ENABLE_SANITIZER adds an address sanitizer to the build.

When I configure with the sanitizer with

cmake -S . -B ./build -G "Ninja Multi-Config" -DENABLE_SANITIZER=ON

and build with

cmake --build ./build/ --target prog 

everything compiles as it should, but when I reconfigure with

cmake -S . -B ./build -G "Ninja Multi-Config"

and build it again, ninja tells me that there is nothing to do:

ninja: no work to do.

Why does this happen when I clearly removed a compile option and link option?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

零度° 2025-02-20 16:20:04

设置变量时,将其设置在CACHE CMAKECACHE.TXT中。当您在重新配置时不重置它时,它将保留其先前的值。 选项.... OFF,仅将选项设置为OFF如果未设置。甚至set(enable_sanitizer off) will 如果在缓存中设置该变量,则仅set(.... cache'“”“”“”“ force),请参阅文档。

When you set a variable, it is set inside cache CMakeCache.txt. When you don't reset it when reconfiguring, it preserves its previous value. The option.... OFF, only set's the option to OFF if it is unset. Even set(ENABLE_SANITIZER OFF) will not set the variable if it is in cache, only set(.... CACHE "" "" FORCE), refer to documentation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文