当前位置:网站首页>[untitled] use of cmake
[untitled] use of cmake
2022-07-03 09:10:00 【BBQ】
1. Single directory single file
Insert a code chip here
CMAKE_MINIMUM_REQUIRED(VERSION 3.10) # Declare the minimum required to compile the code Cmake edition
PROJECT(demo1) ## Name of the project to compile
ADD_EXECUTABLE(demo1 main.cpp)##demo1 The name of the executable file generated for is demo1.exe main.cpp For the object to compile , File dependency
2. Single directory and multiple files
#AUX_SOURCE_DIRECTORY(dir VAR)
# Find all source code files in a directory and store the list in a variable
# Assign all the source file names in the current directory to the variable DIR_HELLO_SRCS
AUX_SOURCE_DIRECTORY(./ DIR_SRCS)
ADD_EXECUTABLE(demo2 ${
DIR_SRCS})
3. Multiple directories and multiple files ( The source file is in the top-level directory )
First write the CMakeLists.txt
# Find all source code files in a directory and store the list in a variable
AUX_SOURCE_DIRECTORY(. DIR_LIB_SRCS)
# Set the file to be called by the main function under the subdirectory as the static library
ADD_LIBRARY(Mylib STATIC ${
DIR_LIBSRCS})
# Or set it as a dynamic library
ADD_LIBRARY(Mylib SHARED ${
DIR_LIBSRCS})
Next, write the top-level directory
CMAKE_MINIMUM_REQUIRED(VERSION 3.1)
PROJECT(demo3)
# Add subdirectories , That is, the name of other folders
ADD_SUBDIRECTORY(./mylib)
AUX_SOURCE_DIRECTORY(./ DIR_SRCS)
ADD_EXECUTABLE(demo3 ${
DIR_SRCS})
demo3 Is the name of the executable Mylib Name of the generated static library Link to the executable
TARGET_LINK_LIBRARIES(demo3 Mylib)
4. Multiple directories and multiple files ( standard That is, a folder of source files src Library files a folder mylib camke File a folder build )
stay demo3 On the basis of Write in the source folder CMakeLists.txt
# Be similar to stm32 If you want to add header file , Get a magic wand to increase the header file path
#${
PROJECT_SOURCE_DIR} Indicates the root directory path You can use . Instead of
# Here is the path of the library file
INCLUDE_DIRECTORIES(${
PROJECT_SOURCE_DIR}/mylib)
AUX_SOURCE_DIRECTORY(./ DIR_SRCS)
ADD_EXECUTABLE(demo4 ${
DIR_SRCS})
TARGET_LINK_LIBRARIES(demo4 Mylib)
Write in top-level file CMakeLists.txt
CMAKE_MINIMUM_REQUIRED(VERSION 3.10)
PROJECT(demo4)
ADD_SUBDIRECTORY(./mylib)
Add the source file path in the project
ADD_SUBDIRECTORY(./src)
And then in build Execute under the document cmake
2. improvement
In the library file CMakeLists Add such a sentence
AUX_SOURCE_DIRECTORY(. DIR_LIB_SRCS)
# Generate library files Mylib.a File placement path
# ${
PROJECT_BINARY_DIR} stay build perform cmake, So for build File path
SET(LIBRARY_OUTPUT_PATH ${
PROJECT_BINARY_DIR}/lib)
ADD_LIBRARY(Mylib STATIC ${
DIR_LIBSRCS})
In the source file CMakeLists Add such a sentence
INCLUDE_DIRECTORIES(${
PROJECT_SOURCE_DIR}/mylib)
SET(EXECUTABLE_OUTPUT_PATH ${
PROJECT_BINARY_DIR}/bin)
AUX_SOURCE_DIRECTORY(./ DIR_SRCS)
ADD_EXECUTABLE(demo4 ${
DIR_SRCS})
TARGET_LINK_LIBRARIES(demo4 Mylib)
边栏推荐
- excel一小时不如JNPF表单3分钟,这样做报表,领导都得点赞!
- Wonderful review | i/o extended 2022 activity dry goods sharing
- Complex character + number pyramid
- [point cloud processing paper crazy reading classic version 9] - pointwise revolutionary neural networks
- LeetCode 871. Minimum refueling times
- How to use Jupiter notebook
- [point cloud processing paper crazy reading frontier version 8] - pointview gcn: 3D shape classification with multi view point clouds
- The less successful implementation and lessons of RESNET
- Introduction to the basic application and skills of QT
- Methods of checking ports according to processes and checking processes according to ports
猜你喜欢

教育信息化步入2.0,看看JNPF如何帮助教师减负,提高效率?

传统企业数字化转型需要经过哪几个阶段?

Basic knowledge of network security

The "booster" of traditional office mode, Building OA office system, was so simple!

On a un nom en commun, maître XX.

【点云处理之论文狂读经典版11】—— Mining Point Cloud Local Structures by Kernel Correlation and Graph Pooling

Complex character + number pyramid
![[advanced feature learning on point clouds using multi resolution features and learning]](/img/f0/abed28e94eb4a95c716ab8cecffe04.png)
[advanced feature learning on point clouds using multi resolution features and learning]

Instant messaging IM is the countercurrent of the progress of the times? See what jnpf says

LeetCode 324. Swing sort II
随机推荐
状态压缩DP AcWing 291. 蒙德里安的梦想
State compression DP acwing 91 Shortest Hamilton path
Vscode connect to remote server
Solution of 300ms delay of mobile phone
Binary tree sorting (C language, int type)
求组合数 AcWing 885. 求组合数 I
LeetCode 30. 串联所有单词的子串
The difference between if -n and -z in shell
Noip 2002 popularity group selection number
LeetCode 1089. Duplicate zero
2022-1-6 Niuke net brush sword finger offer
Sword finger offer II 029 Sorted circular linked list
记忆化搜索 AcWing 901. 滑雪
Using DLV to analyze the high CPU consumption of golang process
数字化管理中台+低代码,JNPF开启企业数字化转型的新引擎
On a un nom en commun, maître XX.
The "booster" of traditional office mode, Building OA office system, was so simple!
20220630学习打卡
LeetCode 57. Insert interval
[point cloud processing paper crazy reading frontier version 10] - mvtn: multi view transformation network for 3D shape recognition