一, 目錄結構ui
├── CMakeLists.txt
├── main.cppthis
* link:CMakeLists.txt[CMakeLists.txt] - Contains the CMake commands you wish to run
* link:main.cpp[main.cpp] - A simple "Hello World" cpp file.ip
二,cmake基本腳本ci
cmake_minimum_required(VERSION 3.5)io
# Set the project name
project (hello_cmake)table
aux_source_directory(. DIR_TOOT_SRCS)function
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")require
# Add an executable
add_executable(hello_cmake ${DIR_TOOT_SRCS})變量
三,cmake代碼分析List
### 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內置的變量名,表明工程名。