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:
最基本的項(xiàng)目是一個(gè)可以從源代碼文件執(zhí)行構(gòu)建醉者。簡(jiǎn)單的工程在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:
注意這個(gè)例子中用小寫命令粒竖,其實(shí)蕊苗,大寫小寫混合的都支持孩革。這個(gè)項(xiàng)目中的源代碼的內(nèi)容就是計(jì)算一個(gè)數(shù)的平方根并且第一個(gè)版本十分的簡(jiǎn)單。
// 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
增加版本號(hào)以及配置頭文件
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:
我們將要加的第一個(gè)特征就是給我們的可執(zhí)行程序和項(xiàng)目加上一個(gè)版本號(hào)熔掺。其實(shí)你可以在你的源代碼中做這個(gè)事情置逻,但是在CMakeLists.txt中做會(huì)提供更多的靈活性券坞。添加一個(gè)版本號(hào)我們需要對(duì) 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)
看了后面一下倍靡。感覺翻譯這個(gè)沒有什么用啊塌西。捡需。。
也沒講一些核心的東西呢撞。先暫時(shí)不翻譯了庵寞,完全沒有講怎么實(shí)現(xiàn)對(duì)編譯器捐川,路徑的一些設(shè)置什么的古沥。makefile看起來還直觀一些娇跟。再去看看別的教程苞俘。