cmake-hello

it2022-05-21  70

一, 目录结构

├── 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 nameproject (hello_cmake)

aux_source_directory(. DIR_TOOT_SRCS)

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

# Add an executableadd_executable(hello_cmake ${DIR_TOOT_SRCS})

 

三,cmake代码分析

 

### cmake最低版本

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

cmake_minimum_required(VERSION 3.5)

### 项目名称

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

project (hello_cmake)

### 创建可执行程序

The +add_executable()+ command specifies that an executable should bebuild from the specified source files, in this example main.cpp. Thefirst argument to the +add_executable()+ function is the name of theexecutable 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内置的变量名,代表工程名。

 

转载于:https://www.cnblogs.com/svenzhang9527/p/10703117.html

相关资源:cmake-3.10.1-win32-x86.msi

最新回复(0)