当前位置:网站首页>[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)
边栏推荐
- Use the interface colmap interface of openmvs to generate the pose file required by openmvs mvs
- LeetCode 871. 最低加油次数
- 推荐一个 yyds 的低代码开源项目
- 高斯消元 AcWing 883. 高斯消元解线性方程组
- 浅谈企业信息化建设
- Phpstudy 80 port occupied W10 system
- [point cloud processing paper crazy reading classic version 7] - dynamic edge conditioned filters in revolutionary neural networks on Graphs
- 2022-2-14 learning xiangniuke project - generate verification code
- Using DLV to analyze the high CPU consumption of golang process
- LeetCode 715. Range 模块
猜你喜欢

On the setting of global variable position in C language

Introduction to the basic application and skills of QT

【点云处理之论文狂读前沿版10】—— MVTN: Multi-View Transformation Network for 3D Shape Recognition

【点云处理之论文狂读前沿版9】—Advanced Feature Learning on Point Clouds using Multi-resolution Features and Learni

Binary tree sorting (C language, int type)

State compression DP acwing 91 Shortest Hamilton path

树形DP AcWing 285. 没有上司的舞会

剑指 Offer II 091. 粉刷房子

Binary tree sorting (C language, char type)

LeetCode 532. K-diff number pairs in array
随机推荐
LeetCode 438. 找到字符串中所有字母异位词
The difference between if -n and -z in shell
【点云处理之论文狂读前沿版10】—— MVTN: Multi-View Transformation Network for 3D Shape Recognition
Debug debugging - Visual Studio 2022
LeetCode 1089. Duplicate zero
Shell script kills the process according to the port number
【点云处理之论文狂读经典版13】—— Adaptive Graph Convolutional Neural Networks
2022-2-13 learn the imitation Niuke project - Project debugging skills
LeetCode 241. Design priorities for operational expressions
On a un nom en commun, maître XX.
【点云处理之论文狂读经典版7】—— Dynamic Edge-Conditioned Filters in Convolutional Neural Networks on Graphs
Problems in the implementation of lenet
Markdown learning
Format - C language project sub file
AcWing 787. Merge sort (template)
Method of intercepting string in shell
[point cloud processing paper crazy reading classic version 8] - o-cnn: octree based revolutionary neural networks for 3D shape analysis
浅谈企业信息化建设
[point cloud processing paper crazy reading classic version 10] - pointcnn: revolution on x-transformed points
Instant messaging IM is the countercurrent of the progress of the times? See what jnpf says