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閱讀 8,908評論 0 6
  • 這個世界開始變得復雜,孤獨的人也不愛回家,熱鬧的人也躲在屋下。結束宿命與狂歡的繆論,嘈雜的空氣里模糊著人生,...
    蘇木卡夫閱讀 416評論 2 4
  • 前幾天,在羅輯思維上聽了一集:“怎樣成為某一領域的頂尖高手?“可能大家都能想到的一個答案:練習1萬小時。那么,誰愿...
    兒女時光機閱讀 343評論 0 0
  • ?1.鼓勵你,讓你看到自己優點的人。 2.幫你理清生活、工作思路的人。 3.給你分享新觀念,帶來好消息的人。 4....
    運安閣閣主閱讀 404評論 0 0