博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CMakeList.txt 案例
阅读量:4521 次
发布时间:2019-06-08

本文共 1657 字,大约阅读时间需要 5 分钟。

# 参考: https://www.hahack.com/codes/cmake/# CMake 最低版本号要求cmake_minimum_required (VERSION 2.8)# 项目信息project (hello)# [1]# 指定生成目标# 对于单个文件,只有写下面这一行。表示使用main.cpp生成可执行程序hello# ps: main.cpp 只是一个普通的hello world# add_executable(hello main.cpp)# [2]# 对于多个文件,如果在源文件中引用顺序正确,那么我们只要把所有引用文件写在后面即可# add_executable(hello main.cpp hello.cpp hello.h)# 目录结构如下# .# ├── build# ├── CMakeLists.txt# ├── hello.cpp# ├── hello.h# └── main.cpp# =============================================# [hello.cpp]# #include 
# void print()# {# printf("Hello \n");# }# =============================================# [hello.h]## #ifndef _HELLO_H# #define _HELLO_H# extern void print();# #endif# =============================================# [main.cpp]# #include
# #include "hello.h"## using namespace std;# int main()# {# print();# return 0;# }# =============================================# [3]# 但是现在我们发现我们如果每次写一个文件就加一个源文件显然不合理# 当然是有集成写法到# 查找当前目录下的所有源文件# 并将名称保存到 DIR_SRCS 变量# aux_source_directory(. DIR_SRCS)# 指定生成目标# add_executable(hello ${DIR_SRCS})# =============================================# [4]# 多级别目录操作# 修改后目录如下,只简单修改了代码中到文件引用# .# ├── build# ├── CMakeLists.txt# ├── hello# │   ├── CMakeLists.txt# │   ├── hello.cpp# │   └── hello.h# └── main.cpp# 经过测试子目录到文件名不能和镜头库到名字冲突aux_source_directory(. DIR_SRCS)# 把子目录的CMakeList.txt引入add_subdirectory(hello)add_executable(sol main.cpp)# 添加链接库target_link_libraries(sol Test)# 在hello 目录下的CMakeList.txt如下# # 子目录中到CMakeList.txt# # 查找当前目录下的所有源文件# # 并将名称保存到 DIR_LIB_SRCS 变量# aux_source_directory(. DIR_LIB_SRCS)# # 生成链接库# add_library (Test ${DIR_LIB_SRCS})

转载于:https://www.cnblogs.com/Q1143316492/p/11047218.html

你可能感兴趣的文章
ELK-Elasticsearch安装
查看>>
Android 模拟器(Emulator)访问模拟器所在主机
查看>>
删除字符串中指定子串
查看>>
day40-socket编程
查看>>
SpringBoot里mybatis查询结果为null的列不返回问题的解决方案
查看>>
为什么留不住优秀的员工
查看>>
Django后台管理admin笔记
查看>>
JavaScript中的变量
查看>>
iptables基本原理和规则配置
查看>>
ArcGIS JS 学习笔记4 实现地图联动
查看>>
ubuntu 12.04 lts安装golang并设置vim语法高亮
查看>>
编程题目:PAT 1004. 成绩排名 (20)
查看>>
使用分层实现业务处理
查看>>
Microsoft Windows平台的NoSQL数据存储引擎
查看>>
浅谈虚拟机
查看>>
Ubuntu系统Linux编译osg库
查看>>
BootstrapTable-导出数据
查看>>
Linux学习笔记 -- 系统目录结构
查看>>
[转载]ExtJs4 笔记(9) Ext.Panel 面板控件、 Ext.window.Window 窗口控件、 Ext.container.Viewport 布局控件...
查看>>
将数组排序组成最小的整数
查看>>