标签:hello lis cout object c scan been patch add min
project(<PROJECT-NAME> [<language-name>...])
project(<PROJECT-NAME>
[VERSION <major>[.<minor>[.<patch>[.<tweak>]]]]
[DESCRIPTION <project-description-string>]
[HOMEPAGE_URL <url-string>]
[LANGUAGES <language-name>...])
project
主要用于提供项目的名称、版本、使用编译语言等信息
注意:
- 在当前系统版本下面,实际上 Project 并不支持 document 提供的 DESCRIPTION
、HOMEPAGE_URL
- project 必须放在最上面, 且不能通过 include
来包含
CMAKE_PROJECT_NAME
变量中以 10.2.1.3 为例
名称 | 变量名 | 值 |
---|---|---|
major(主版本号) | PROJECT_VERSION_MAJOR | 10 |
minor(次版本号) | PROJECT_VERSION_MINOR | 2 |
patch(补丁版本号) | PROJECT_VERSION_PATCH | 1 |
tweak | PROJECT_VERSION_TWEAK | 3 |
VERSION | CMAKE_PROJECT_NAME | 10.2.1.3 |
文件目录结构如下:
rs:cmake-project$ tree
.
├── CMakeLists.txt
├── main.cpp
└── make.sh
CMakeLists.txt 文件内容:
cmake_minimum_required(VERSION 3.5)
project(DEMO VERSION 10.2.1.3 LANGUAGES CXX C ASM )
message("CMAKE_PROJECT_NAME = ${CMAKE_PROJECT_NAME}")
message("PROJECT_VERSION = ${PROJECT_VERSION}")
message("PROJECT_VERSION_MAJOR = ${PROJECT_VERSION_MAJOR}")
message("PROJECT_VERSION_MINOR = ${PROJECT_VERSION_MINOR}")
message("PROJECT_VERSION_PATCH = ${PROJECT_VERSION_PATCH}")
message("PROJECT_VERSION_TWEAK = ${PROJECT_VERSION_TWEAK}")
add_executable(DEMO main.cpp)
main.cpp 文件内容
#include <iostream>
using namespace std;
int main(int argv, const char *argc[])
{
cout << "hello world" << endl;
return 0;
}
make.sh 保存一些指令(这个非必须)
#!/bin/sh
rm -rf CMakeFiles
cmake ./
make
./DEMO
sh make.sh
.....
CMAKE_PROJECT_NAME = DEMO
PROJECT_VERSION = 10.2.1.3
PROJECT_VERSION_MAJOR = 10
PROJECT_VERSION_MINOR = 2
PROJECT_VERSION_PATCH = 1
PROJECT_VERSION_TWEAK = 3
-- Configuring done
-- Generating done
-- Build files have been written to: /home/rs/Documents/study/cmake-project
Scanning dependencies of target DEMO
[ 50%] Building CXX object CMakeFiles/DEMO.dir/main.cpp.o
[100%] Linking CXX executable DEMO
[100%] Built target DEMO
hello world
rs:cmake-project$
https://cmake.org/cmake/help/latest/command/project.html
DESCRIPTION
以及 HOMEPAGE_URL
暂时不支持,不知道使用!
标签:hello lis cout object c scan been patch add min
原文地址:https://www.cnblogs.com/gaox97329498/p/10957786.html