Debian 安装最新版本CMake

debian 10自带的版本是3.13.4,一般情况下够用了。今天不知道啥问题,发现无法正常编译,ZLIB 包找不到。

网上转了一圈,没找到方法。debian使用的ZLIB包 zlib1g zlib1g-dev 都安装过

sudo apt install zlib1g
sudo apt install zlib1g-dev

看到有个帖子用了3.16版本能通过编译,赶脚升级CMake版本。

一、测试ZLib的CMake信息

主要问题是c代码会出现这个问题,c++版本不会有这个问题。

CMakeLists.txt 的测试内容

cmake_minimum_required(VERSION 3.5)
project(test C)

find_package(ZLIB REQUIRED)

执行编辑命令报ZLIB 包找不到

[cmake] CMake Error at /usr/share/cmake-3.13/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
[cmake]   Could NOT find ZLIB (missing: ZLIB_LIBRARY) (found version "1.2.11")
[cmake] Call Stack (most recent call first):
[cmake]   /usr/share/cmake-3.13/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
[cmake]   /usr/share/cmake-3.13/Modules/FindZLIB.cmake:114 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
[cmake]   CMakeLists.txt:4 (find_package)
[cmake] 
[cmake] 
[cmake] Configuring incomplete, errors occurred!
[cmake] See also "/home/iucalc/expsvr/build/CMakeFiles/CMakeOutput.log".
[cmake] See also "/home/iucalc/expsvr/build/CMakeFiles/CMakeError.log".

二、安装CMake

2021-6-28号最新的版本是 ver 3.21.0, 直接下载cmake-3.21.0-rc1.tar.gz源码包编译。

注:cmake默认使用 ssl的库
sudo apt-get install libssl-dev

$ wget https://github.com/Kitware/CMake/releases/download/v3.21.0-rc1/cmake-3.21.0-rc1.tar.gz
$ tar -zxvf cmake-3.21.0-rc1.tar.gz
$ cd cmake-3.21.0-rc1
$ ./bootstrap
$ make
$ sudo make install
$ cmake --version

cmake version 3.21.0-rc1

CMake suite maintained and supported by Kitware (kitware.com/cmake).

官网: https://cmake.org/download/

三、升级完成,问题完美解决

新版本的确实已经解决了ZLIB在c工程下,找不到Zlib的问题。

新版本的FindZLIB.cmake里有个 select_library_configurations

  ...
  include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
  select_library_configurations(ZLIB)
  ...

END(Moguf.com)