使用CMake编写CMakeLists.txt文件

本文介绍了如何使用CMake构建项目,包括创建目标如静态库,设置源文件属性,以及通过PROJECT命令定义项目和指定使用的语言。CMakeLists.txt文件通过add_library等命令管理源文件,并可通过BUILD_SHARED_LIBS变量切换库类型。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

target

Targets represent executables, libraries, and utilities built by CMake. Every add_library, add_executable, and add_custom_target command creates a target. For example, the follwing command will create a target named foo that is a static library, with foo1.c and foo2.c as source file

add_library(foo STATIC foo1.c foo2.c)

可以通过变量BUILD_SHARED_LIBS指定需要编译库的类型。

Source Files

可以设置一些源文件的属性,比如编译选项。

变量

通过set commands进行设置。

The first command the toplevel CMakeLists file should have is the PROJECT command. This command both names the project and optionally specifies what languages will

be used by it.

project (projectname [CXX] [C] [Java] [NONE])

If no languages are specified then CMake defaults to supporting C and C++.

The project will contain all targets that are in the CMakeLists.txt file, and any of its subdirectories as specified by the add_subdirectory command.



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值