当前位置:网站首页>[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)
边栏推荐
- 22-05-26 Xi'an interview question (01) preparation
- Education informatization has stepped into 2.0. How can jnpf help teachers reduce their burden and improve efficiency?
- Binary tree sorting (C language, char type)
- LeetCode 532. K-diff number pairs in array
- Use the interface colmap interface of openmvs to generate the pose file required by openmvs mvs
- 20220630 learning clock in
- Debug debugging - Visual Studio 2022
- Basic knowledge of network security
- 常见渗透测试靶场
- The "booster" of traditional office mode, Building OA office system, was so simple!
猜你喜欢
Binary tree sorting (C language, int type)
too many open files解决方案
Tree DP acwing 285 A dance without a boss
LeetCode 508. The most frequent subtree elements and
记忆化搜索 AcWing 901. 滑雪
网络安全必会的基础知识
Recommend a low code open source project of yyds
Install third-party libraries such as Jieba under Anaconda pytorch
浅谈企业信息化建设
Low code momentum, this information management system development artifact, you deserve it!
随机推荐
Common DOS commands
Character pyramid
Tree DP acwing 285 A dance without a boss
Debug debugging - Visual Studio 2022
Education informatization has stepped into 2.0. How can jnpf help teachers reduce their burden and improve efficiency?
Use of sort command in shell
The method of replacing the newline character '\n' of a file with a space in the shell
Save the drama shortage, programmers' favorite high-score American drama TOP10
DOM render mount patch responsive system
Problems in the implementation of lenet
教育信息化步入2.0,看看JNPF如何帮助教师减负,提高效率?
too many open files解决方案
Excel is not as good as jnpf form for 3 minutes in an hour. Leaders must praise it when making reports like this!
Binary tree sorting (C language, char type)
[point cloud processing paper crazy reading classic version 10] - pointcnn: revolution on x-transformed points
【点云处理之论文狂读经典版8】—— O-CNN: Octree-based Convolutional Neural Networks for 3D Shape Analysis
樹形DP AcWing 285. 沒有上司的舞會
Noip 2002 popularity group selection number
Tag paste operator (#)
状态压缩DP AcWing 291. 蒙德里安的梦想