不同的开发平台有不同的Make 工具,例如 GNU Make ,QT 的 qmake ,微软的 MS nmake,BSD Make(pmake)等等。这些 Make 工具遵循着不同的规范和标准,所执行的 Makefile 格式也千差万别。这样就带来了一个严峻的问题:如果软件想跨平台,必须要保证能够在不同平台编译。CMake 就是针对上面问题所设计的工具。
对于初学者怎么去学习cmake,可以参考cmake 官方网站的demo,足够我们去学习并且通俗易懂,上手很快。
链接1:https://cmake.org/cmake/help/book/mastering-cmake/cmake/Help/guide/tutorial/index.html
链接2:ttps://github.com/Kitware/CMake/tree/master/Help/guide/tutorial
Step1~Step12从易到难,寻隙渐进。
git clone https://github.com/Kitware/CMake.git
对于这么简单的项目,只需要一个三行的 CMakeLists.txt 文件即可,这是本篇教程的起点。在 目录中创建一个 CMakeLists.txt 文件,如下所示:
cmake_minimum_required(VERSION 3.15)
# set the project name
project(Tutorial)
# add the executable
add_executable(Tutorial tutorial.cpp)