cmake命令set、option、find_package、target_link_libraries、add_executable使用方法
2023-09-14 09:15:32 时间
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
相关文章
- MySQL 的 find_in_set 函数使用方法
- 【PHP面向对象(OOP)编程入门教程】10.__set(),__get(),__isset(),__unset()四个方法的应用
- 【Mongodb】 replica set 两种添加节点方法的日志分析
- 掌握SortSet接口和Set接口的关系,以及常用方法。
- [Spring Boot] Set Context path for application in application.properties
- [Unit Testing] Set the timeout of a Test in Mocha
- [Angular] Omit relative path by set up in tsconfig.json
- EasyPusher华为手机直播推流硬编码[OMX.IMG.TOPAZ.Encoder] failed to set input port definition parameters.
- [NPM] Set default values for package.json using npm set
- helm --set的使用示例及基本使用命令整理
- Vue Nuxtjs Cannot set property 'render' of undefined解决方法
- java中List、Array、Map、Set等集合相互转换的最佳方法
- lombok标签之@Data @AllArgsConstructor @@NoArgsConstructor -如何去除get,set方法。@Data注解和如何使用,lombok
- set容器的大小和交换
- Error message COM_PRODUCT 503 Data cannot be maintained for set type COM_TA_R3_ID
- java中List、Array、Map、Set等集合相互转换的最佳方法
- Angular jasmine fixture.detectChanges如何触发directive的set方法
- Android 的json的set方法
- python将redis中set类型的大数据,写入到parquet文件中
- Java学习路线-36:Set集合
- Error attempting to get column ‘xxx‘ from result set. Cause: java.sql.SQLDataException错误的解决方法
- nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping错误的决方法
- cargo报错:no override and no default toolchain set
- leetcode 762. Prime Number of Set Bits in Binary Representation
- python中set和frozenset方法和区别
- 遍历一个Set的方法只有一个:迭代器(interator)。
- 解决svn "cannot set LC_CTYPE locale"的问题
- FIND_IN_SET(str,strlist)函数解析
- DISPLAY not set. Please set the DISPLAY and try again 的处理方法(Oracle安装比较常出现)