与添加的消毒剂重新配置的cmake并非触发忍者以重新编译
让我们假设一个最小的顶级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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
设置变量时,将其设置在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. Theoption.... OFF
, only set's the option toOFF
if it is unset. Evenset(ENABLE_SANITIZER OFF)
will not set the variable if it is in cache, onlyset(.... CACHE "" "" FORCE)
, refer to documentation.