警告提示
使用cmake时出现CMP0074警告。
CMake Warning (dev) at CMakeLists.txt:5 (find_package):
Policy CMP0074 is not set: find_package uses <PackageName>_ROOT variables.
Run "cmake --help-policy CMP0074" for policy details. Use the cmake_policy
command to set the policy and suppress this warning.
Environment variable Eigen3_ROOT is set to:
C:\Program Files (x86)\Eigen3
For compatibility, CMake is ignoring the variable.
This warning is for project developers. Use -Wno-dev to suppress it.
问题分析
根据警告提示信息,_ROOT变量被忽略了,如果不想忽略需要使用cmake_policy指令设置变量CMP0074。
解决方法
在CMakeLists.txt中第二行添加一条cmake_policy(SET CMP0074 NEW) 或者 cmake_policy(SET CMP0074 OLD),前面所示的警告就消失了。在Windows中使用cmake的一些无法找到库文件的错误提示,比如常见 xxx not found 也是因为这个变量没有设置忽略了<PackageName>_ROOT导致的。
参考链接
https://cmake.org/cmake/help/latest/policy/CMP0074.html
https://cmake.org/cmake/help/latest/command/cmake_policy.html#command:cmake_policy