【Cmake 教程】

from: https://cliutils.gitlab.io/modern-cmake/chapters/basics/example.html

A simple example

这是一个简单但完整的适当CMakeList示例。对于这个程序,我们有一个带有头文件和源文件的库(MyLibExample),以及一个带有源文件的应用程序MyExample。

# Almost all CMake files should start with this
# You should always specify a range with the newest
# and oldest tested versions of CMake. This will ensure
# you pick up the best policies.
#几乎所有CMake文件都应该以此开头
#您应该始终使用最新的
#和CMake的最旧测试版本。这将确保
#你会选择最好的政策。
cmake_minimum_required(VERSION 3.1...3.24)

# This is your project statement. You should always list languages;
# Listing the version is nice here since it sets lots of useful variables
#这是你的项目说明。你应该经常列出语言;
#在这里列出版本很好,因为它设置了许多有用的变量
project(
  ModernCMakeExample
  VERSION 1.0
  LANGUAGES CXX)

# If you set any CMAKE_ variables, that can go here.
# (But usually don't do this, except maybe for C++ standard)

# Find packages go here.

# You should usually split this into folders, but this is a simple example

# This is a "default" library, and will match the *** variable setting.
# Other common choices are STATIC, SHARED, and MODULE
# Including header files here helps IDEs but is not required.
# Output libname matches target name, with the usual extensions on your system
#如果您设置了任何CMAKE_变量,可以转到此处。
#(但通常不会这样做,除非是C++标准)
#在此处查找包裹。
#通常应该将其拆分为文件夹,但这是一个简单的示例
#这是一个“默认”库,将匹配***变量设置。
#其他常见选项包括STATIC、SHARED和MODULE
#此处包含头文件有助于IDE,但不是必需的。
#输出库名称与目标名称匹配,具有系统上常用的扩展名
add_library(MyLibExample simple_lib.cpp simple_lib.hpp)

# Link each target with other targets or add options, etc.

# Adding something we can run - Output name matches target name
#将每个目标与其他目标链接或添加选项等。
#添加我们可以运行的内容-输出名称与目标名称匹配
add_executable(MyExample simple_example.cpp)

# Make sure you link your targets with this command. It can also link libraries and
# even flags, so linking a target that does not exist will not give a configure-time error.
#确保使用此命令链接目标。它还可以链接库和
#甚至标记,因此链接不存在的目标不会产生配置时间错误。
target_link_libraries(MyExample PRIVATE MyLibExample)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值