我不确定在哪里设置 cmake_policy。此链接解释了 cmake_policy。但不确定在哪里设置 cmake 策略。我使用 cmake 来构建 Opencv,我有很多警告,比如
CMake Warning (dev) at cuda_compile_generated_row_filter.2.cu.o.cmake:137 (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.
Run Code Online (Sandbox Code Playgroud)
我需要像 cmake_policy(SET CMP0054 NEW). 在哪里设置此策略?我喜欢
ppp@ppp-Inspiron-7537:~/Softwares/opencv-2.4.9/build$ cmake_policy(SET CMP0054 NEW)
bash: syntax error near unexpected token `SET'
Run Code Online (Sandbox Code Playgroud)
但我有错误。如何设置策略?
使用-Wno-dev选项用于cmake抑制针对开发人员的警告:
cmake -Wno-dev <other-options> <source-dir>
Run Code Online (Sandbox Code Playgroud)
或者,如果要为项目设置策略,则需要修改其CMakeLists.txt文件并添加行
cmake_policy(SET CMP0054 OLD)
Run Code Online (Sandbox Code Playgroud)
一开始的某个地方。
请注意,您需要对属性使用OLD值,因为项目很可能依赖于此类变量的取消引用。设置NEW值可能会破坏项目的功能。
当项目的代码被修复时,即使没有明确的策略设置也不会产生警告。