接上一篇博客,打架已经对CMake有了一个初步的认识,从这篇博客开始,将会逐步对CMake的学习进行更新。推荐的参考网站时CMake的官网,上面有非常详细的讲解,这里我们简化了一下方便大家快速上手。
一、单源码工程
最基本的工程是由源码编译生成的可执行文件,其CMakeLists.txt文件也只需要简单的几行代码就ok了,CMakeLists.txt文件代码如下:
cmake_minimum_required (VERSION 2.6)
project (Tutorial)
add_executable(Tutorial tutorial.cxx)
注意,这里使用了小写命令,我们在上一篇博客中已经提到,CMake是不区分大小写的,但是我们自己在编程的过程中最好保证统一。
tutorial.cxx的功能是计算一个数的平方根,代码如下:
// A simple program that computes the square root of a number
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main (int argc, char *argv[])
{
if (argc < 2)