当前位置: 首页 > news >正文

cmake命令set、option、find_package、target_link_libraries、add_executable使用方法

cmake下载:https://cmake.org/download/
set:cmake命令之set使用案例 命令行输入函数接口的参数
option:cmake命令之option使用案例
cmake命令之使用静态库(include_directories,link_directories,target_link_directories)
add_library:cmake命令之add_library案例(生成动态库和静态库)
cmake find_package的基本原理与详细示例

CMake使用总结:
https://blog.csdn.net/a740169405/article/details/82755458?187
https://blog.csdn.net/yntcsb/article/details/83333437?spm=1001.2101.3001.6650
Linux下CMake简明教程

案例1:option

test.cpp

#include <iostream>
 
int main() {
#ifdef TEST_DEBUG
    std::cout<<"123------------------> Hello,Test"<<std::endl;
#endif
    std::cout << "456 Hello------------> World!" << std::endl;
    return 0;
}

CMakeLists.tx:

cmake_minimum_required(VERSION 3.13)
project(cmaks)
 
set(CMAKE_CXX_STANDARD 14)
 
option(TEST_DEBUG "option for TEST" OFF)
if(TEST_DEBUG)
    add_definitions(-DTEST_DEBUG)
endif()
add_executable(cmaks test.cpp)

run.sh:

#!/bin/sh
rm -rf build
ls
mkdir build 
cd build
cmake -DTEST_DEBUG=OFF ..
# cmake --build ..
make 
./cmaks 

cd ../
rm -rf build
mkdir build 
cd build
cmake -DTEST_DEBUG=ON ..
make 
./cmaks 

执行结果:bash run.sh

bash run.sh 
CMakeLists.txt  run.sh  test.cpp
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /data/spleeter_cmake/test2020/cmaks/build
[ 50%] Building CXX object CMakeFiles/cmaks.dir/test.cpp.o
[100%] Linking CXX executable cmaks
[100%] Built target cmaks
456 Hello------------> World!
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /data/spleeter_cmake/test2020/cmaks/build
[ 50%] Building CXX object CMakeFiles/cmaks.dir/test.cpp.o
[100%] Linking CXX executable cmaks
[100%] Built target cmaks
123------------------> Hello,Test
456 Hello------------> World!

案例2:list

cmake_minimum_required(VERSION 2.8)
set(mylist aaa)
list(APPEND mylist bbb ccc 9) #追加
# MESSAGE("${mylist}")
list(LENGTH mylist ll)
#insert with index
list(INSERT mylist 1 xxx 3) #插入指定位置1之后的xxx 3
MESSAGE("${mylist}")  

#移除列表中的元素 
list(REMOVE_ITEM mylist 3)
MESSAGE("${mylist}")

aaa;xxx;3;bbb;ccc;9
aaa;xxx;bbb;ccc;9
-- Configuring done
-- Generating done

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 继续提bug
  • AI模型设计:C语言实现socket发送与接受深度学习文本数据集
  • 链接管理部分的bug已经修正
  • 终端一行命令更换ubuntu国内镜像源
  • 预计近两天将新增功能
  • 完美解决W: 无法下载 /shiftkey/desktop/any/dists/any/InRelease
  • 动态获取当前屏幕中光标所在位置的颜色
  • python使用技巧(二十五):*args, **kwargs生成可变列表与字典
  • 爱因斯坦在普朗克生日会上的演讲:探索的动机
  • python使用技巧(二十六):批量复制图片或文件到另一文件目录
  • 完美解决ubuntu系统的中文输入法无法写入VS Code的问题
  • 谁比谁活得更长 杜丽
  • AI模型设计:yolov1+darknet+yolov2,3,4,5,X全系列资料汇总[源码仓库]标星收藏
  • C++使用技巧(八):输入输出读写文件
  • C++使用技巧(九):ubuntu环境下Eigen线性代数库的简单使用(C++版本的numpy库))
  • 2017 年终总结 —— 在路上
  • conda常用的命令
  • Date型的使用
  • ES10 特性的完整指南
  • nginx(二):进阶配置介绍--rewrite用法,压缩,https虚拟主机等
  • open-falcon 开发笔记(一):从零开始搭建虚拟服务器和监测环境
  • Phpstorm怎样批量删除空行?
  • scala基础语法(二)
  • SpiderData 2019年2月23日 DApp数据排行榜
  • Vue实战(四)登录/注册页的实现
  • 编写符合Python风格的对象
  • 区块链将重新定义世界
  • 详解移动APP与web APP的区别
  • 因为阿里,他们成了“杭漂”
  • d²y/dx²; 偏导数问题 请问f1 f2是什么意思
  • ​Distil-Whisper:比Whisper快6倍,体积小50%的语音识别模型
  • # Python csv、xlsx、json、二进制(MP3) 文件读写基本使用
  • #LLM入门|Prompt#3.3_存储_Memory
  • #微信小程序:微信小程序常见的配置传旨
  • (14)目标检测_SSD训练代码基于pytorch搭建代码
  • (3)nginx 配置(nginx.conf)
  • (pojstep1.3.1)1017(构造法模拟)
  • (zt)最盛行的警世狂言(爆笑)
  • (附源码)c#+winform实现远程开机(广域网可用)
  • (三)模仿学习-Action数据的模仿
  • (十六)串口UART
  • (四)stm32之通信协议
  • (一)pytest自动化测试框架之生成测试报告(mac系统)
  • (正则)提取页面里的img标签
  • (转)Java socket中关闭IO流后,发生什么事?(以关闭输出流为例) .
  • (转)socket Aio demo
  • (自适应手机端)响应式新闻博客知识类pbootcms网站模板 自媒体运营博客网站源码下载
  • .net core开源商城系统源码,支持可视化布局小程序
  • .NET Entity FrameWork 总结 ,在项目中用处个人感觉不大。适合初级用用,不涉及到与数据库通信。
  • .net 提取注释生成API文档 帮助文档
  • .NET 应用启用与禁用自动生成绑定重定向 (bindingRedirect),解决不同版本 dll 的依赖问题
  • .NET6 命令行启动及发布单个Exe文件
  • .NETCORE 开发登录接口MFA谷歌多因子身份验证
  • .NET中的Event与Delegates,从Publisher到Subscriber的衔接!
  • .Net组件程序设计之线程、并发管理(一)