cmake语法学习

Before diving into the code, here is the folders structure.

├── CMakeLists.txt [ Top most ]
├── subbinary
│   ├── CMakeLists.txt [ subbinary ]
│   └── main.cpp
├── sublibrary1
│   ├── CMakeLists.txtsublibrary1 ]
│   ├── include
│   │   └── sublib1
│   │   └── sublib1.h
│   └── src
│   └── sublib1.cpp
└── sublibrary2
├── CMakeLists.txtsublibrary2 ]
└── include
└── sublib2
└── sublib2.h

*

CMakeLists.txt [ subbinary ]

To generate an execuatable. we have discussed before.

*

CMakeLists.txtsublibrary1 ]

To generate an library. we have discussed before.

*

CMakeLists.txtsublibrary2 ]

To generate an library. we have discussed before.

├── CMakeLists.txt [ Top most ]

cmake_minimum_required (VERSION 3.5)

project(subprojects)

# Add sub directories
add_subdirectory(sublibrary1)
add_subdirectory(sublibrary2)
add_subdirectory(subbinary)

*

add_subdirectory(sublibrary1)

- sublibrary1 is the folder name. Even though we have a folder named "sublibrary1" here, there are totally 2 different things.

- Question 1 :  Where to create the folder?

Answer 1 : Most of us will "mkdir build", "cd build" and "cmake ..", so the absolute folder path will be "......./build/sublibrary1" .

- Question 2 :What will the function do?

Answer 2 : As far as I know,

------------- 1 Create a sub-folder in building folder;

------------- 2 Link the CMakelist.txt in "sublibrary1"; So you can not pass a arbitrary folder name here.

That is all.

原文地址:https://www.cnblogs.com/alexYuin/p/12778536.html