cmake-hello

一, 目录结构

├── CMakeLists.txt
├── main.cpp

* link:CMakeLists.txt[CMakeLists.txt] - Contains the CMake commands you wish to run
* link:main.cpp[main.cpp] - A simple "Hello World" cpp file.

 

二,cmake基本脚本

cmake_minimum_required(VERSION 3.5)

# Set the project name
project (hello_cmake)

aux_source_directory(. DIR_TOOT_SRCS)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")

# Add an executable
add_executable(hello_cmake ${DIR_TOOT_SRCS})

 

三,cmake代码分析

 

### cmake最低版本

When creating a project using CMake, you can specify the minimum version
of CMake that is supported.

cmake_minimum_required(VERSION 3.5)


### 项目名称

A CMake build can include a project name to make referencing certain
variables easier when using multiple projects.

project (hello_cmake)


### 创建可执行程序

The +add_executable()+ command specifies that an executable should be
build from the specified source files, in this example main.cpp. The
first argument to the +add_executable()+ function is the name of the
executable to be built, and the second argument is the list of source files to compile.

add_executable(hello_cmake main.cpp) 或者 add_executable(${PROJECT_NAME} main.cpp)

PROJECT_NAME为cmake内置的变量名,代表工程名。

 

posted @ 2019-04-13 21:55  流浪侠客  阅读(279)  评论(0编辑  收藏  举报