当前位置:网站首页>Cmake learning notes (1) compile single source programs with cmake
Cmake learning notes (1) compile single source programs with cmake
2022-07-07 23:53:00 【Raring_ Ringtail】
This is what I'm learning to use CMake Notes taken when , Main reference 《CMake Cookbook》 This book .
use CMake Compile single source program , The example program is as follows :
#include <cstdlib>
#include <iostream>
#include <string>
std::string say_hello() {
return std::string("Hello, CMake world!"); }
int main() {
std::cout << say_hello() << std::endl;
return EXIT_SUCCESS;
}
CMakeLists.txt as follows :
# CMake Version for
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
# Declare the project name and language
project(recipe-01 LANGUAGES CXX)
# To guide the CMake Create target program
add_executable(hello-world hello-world.cpp)
Build command :
mkdir -p build
cd build
cmake ..
# The above three items are equivalent to cmake -H. -Bbuild
cmake --build .
cmake -H. -Bbuild Medium -H. Means to find in the current folder CMakeList.txt file ,-Bbuild It means in build Folder to generate files needed for compilation . The command is still in standardization, so it is more recommended to use the traditional way .
In the created build There are the following files under the folder :
- Makefile: To guide the make Build the configuration file of the project .
- CMakeFiles: Storage of temporary documents ,CMake Detecting the operating system 、 Temporary files generated when the compiler waits . besides , According to the selected generator ( stay Unix Class system is Unix Makefiles generator, stay Windows The default is Visual Studio) Different , It will also include project related files .
- cmake_install.cmake: Contains installation rules CMake Script , Use during installation .
- CMakeCache.txt:CMake cache
cmake --build . Is a cross platform command , Will call the platform's native build commands , stay linux Call in make.
Build options
In this example, the only construction goal is hello-world This executable file , But in fact cmake Support more build options . Run the command cmake --build . --target help You can see the available build items :
$ cmake --build . --target help
The following are some of the valid targets for this Makefile:
... all (the default if no target is provided)
... clean
... depend
... rebuild_cache
... hello-world
... edit_cache
... hello-world.o
... hello-world.i
... hello-world.s
These build options are available through cmake --build . --target <target-name> Generate .
- all ( stay VS Generator is ALL_BUILD) Is the default build option , All goals in the project will be built
- clean Clear all generated files
- depend call CMake Generate dependencies for source code
- rebuild_cache call CMake The reconstruction CMakeCache.txt. This is needed when adding new entries to the source .
- edit_cache Allow direct editing of cache entries
For more complex projects with testing links and installation rules ,CMake The following additional build options are generated
- test ( stay VS Generator is RUN_TESTS) Will be in CTest Run the test sample with the support of
- install Run the installation rules of the project .
- package call CPack Generate a redistributable package for the project .
Welcome to my WeChat official account. Notes on Jiangda
边栏推荐
- Apng2gif solutions to various problems
- DataGuard active / standby cleanup archive settings
- 95. (cesium chapter) cesium dynamic monomer-3d building (building)
- QT and OpenGL: load 3D models using the open asset import library (assimp)
- 网上买基金安全么?
- PostGIS learning
- Pypharm uses, and the third-party library has errors due to version problems
- Binary sort tree [BST] - create, find, delete, output
- Gorm Association summary
- Is it safe to buy funds online?
猜你喜欢

HB 5469民用飞机机舱内部非金属材料燃烧试验方法

QT and OpenGL: loading 3D models using the open asset import library (assimp) - Part 2

AITM3.0005 烟雾毒性测试

How did a fake offer steal $540million from "axie infinity"?

Aitm3.0005 smoke toxicity test

FFA and ICGA angiography

At the age of 35, I made a decision to face unemployment

FFA与ICGA造影

An example analysis of MP4 file format parsing

QT and OpenGL: load 3D models using the open asset import library (assimp)
随机推荐
Possible SQL for Oracle table lookup information
数据湖(十五):Spark与Iceberg整合写操作
【leetcode】day1
[summary] some panels and videos seen
go time包常用函数
【LeetCode】20、有效的括号
507 field D - extraterrestrial relics
AITM3.0005 烟雾毒性测试
Les mots ont été écrits, la fonction est vraiment puissante!
redis缓存工具类,值得拥有~
Is it safe for tongdaxin to buy funds?
How did a fake offer steal $540million from "axie infinity"?
机器人(自动化)等专业课程创新的结果
Pigsty:开箱即用的数据库发行版
postgres timestamp转人眼时间字符串或者毫秒值
HB 5469民用飞机机舱内部非金属材料燃烧试验方法
Oracle statistics by time
Rock-paper-scissors
DataGuard active / standby cleanup archive settings
HDU - 1260 Tickets(线性DP)