Cmake tutorial 官网翻译

1. 开始

The most basic project is an executable built from source code files. For simple projects a two line CMakeLists.txt file is all that is required. This will be the starting point for our tutorial. The CMakeLists.txt file looks like:
最基本的项目是一个可以从源代码文件执行构建。简单的工程在CMakeLists.txt中两行就足够了。这是我们开始的第一步。CMakeLists.txt看起来像这样。

cmake_minimum_required (VERSION 2.6)
project (Tutorial)
add_executable(Tutorial tutorial.cxx)

Note that this example uses lower case commands in the CMakeLists.txt file. Upper, lower, and mixed case commands are supported by CMake. The source code for tutorial.cxx will compute the square root of a number and the first version of it is very simple, as follows:

注意这个例子中用小写命令,其实,大写小写混合的都支持。这个项目中的源代码的内容就是计算一个数的平方根并且第一个版本十分的简单。

// 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)
    {
    fprintf(stdout,"Usage: %s number\n",argv[0]);
    return 1;
    }
  double inputValue = atof(argv[1]);
  double outputValue = sqrt(inputValue);
  fprintf(stdout,"The square root of %g is %g\n",
          inputValue, outputValue);
  return 0;
}

Adding a Version Number and Configured Header File

增加版本号以及配置头文件

The first feature we will add is to provide our executable and project with a version number. While you can do this exclusively in the source code, doing it in the CMakeLists.txt file provides more flexibility. To add a version number we modify the CMakeLists.txt file as follows:
我们将要加的第一个特征就是给我们的可执行程序和项目加上一个版本号。其实你可以在你的源代码中做这个事情,但是在CMakeLists.txt中做会提供更多的灵活性。添加一个版本号我们需要对 CMakeLists.txt做如下修改。

cmake_minimum_required (VERSION 2.6)
project (Tutorial)
# The version number.
set (Tutorial_VERSION_MAJOR 1)
set (Tutorial_VERSION_MINOR 0)
 
# configure a header file to pass some of the CMake settings
# to the source code
configure_file (
  "${PROJECT_SOURCE_DIR}/TutorialConfig.h.in"
  "${PROJECT_BINARY_DIR}/TutorialConfig.h"
  )
 
# add the binary tree to the search path for include files
# so that we will find TutorialConfig.h
include_directories("${PROJECT_BINARY_DIR}")
 
# add the executable
add_executable(Tutorial tutorial.cxx)

看了后面一下。感觉翻译这个没有什么用啊。。。
也没讲一些核心的东西。先暂时不翻译了,完全没有讲怎么实现对编译器,路径的一些设置什么的。makefile看起来还直观一些。再去看看别的教程。

推荐阅读更多精彩内容

  • Correctness AdapterViewChildren Summary: AdapterViews can...
    MarcusMa阅读 7,635评论 0 6
  • 这个世界开始变得复杂,孤独的人也不爱回家,热闹的人也躲在屋下。结束宿命与狂欢的缪论,嘈杂的空气里模糊着人生,...
    苏木卡夫阅读 247评论 2 4
  • 前几天,在罗辑思维上听了一集:“怎样成为某一领域的顶尖高手?“可能大家都能想到的一个答案:练习1万小时。那么,谁愿...
    儿女时光机阅读 183评论 0 0
  • ​1.鼓励你,让你看到自己优点的人。 2.帮你理清生活、工作思路的人。 3.给你分享新观念,带来好消息的人。 4....
    运安阁阁主阅读 189评论 0 0