《CMake Practice》的第三章,在t2中创建工程后,运行cmake …之后出现如下警告:“
CMake Warning (dev) in CMakeLists.txt:
No cmake_minimum_required command is present. A line of code such as
cmake_minimum_required(VERSION 3.10)
should be added at the top of the file. The version specified may be lower
if you wish to support older CMake versions for this project. For more
information run "cmake --help-policy CMP0000".
This warning is for project developers. Use -Wno-dev to suppress it.
-- Configuring done
-- Generating done
-- Build files have been written to: /home/cxj/backup/cmake/t2/build
该警告其实是告诉我们:没有给出编译目标工程的最低的cmake版本
解决办法,在工程根目录t2下的CMakeLists.txt文件最前面添加上目标工程的最低cmake版本
CMAKE_MINIMUM_REQUIRED(VERSION 3.10)
当然也可添加:
#务必安装的cmake版本高于给定的最低版本,否则终止构建
CMAKE_MINIMUM_REQUIRED(VERSION 3.10 FATAL_ERROR)
注意:有时候你会发现添加了这句代码,还是出现No cmake_minimum_required command is present,这是因为这句代码务必放在根目录的CMakeLists.txt的第一行。就是PROJECT()的上面
备注:
#查看cmake的版本
cmake --version