cmake
|CMAKE_SOURCE_DIR |The root source directory
|CMAKE_CURRENT_SOURCE_DIR |The current source directory if using
sub-projects and directories.
|PROJECT_SOURCE_DIR |The source directory of the current cmake project.
|CMAKE_BINARY_DIR |The root binary / build directory. This is the
directory where you ran the cmake command.
|CMAKE_CURRENT_BINARY_DIR |The build directory you are currently in.
|PROJECT_BINARY_DIR |The build directory for the current project.
—————————————————————————————————————————
file(GLOB SOURCES ${PROJECT_SOURCE_DIR}/src/*.cpp)????//file代替set添加變量
target_include_directories(hello_library
PUBLIC
${PROJECT_SOURCE_DIR}/include
)
include目錄下有headers或者h(yuǎn)eader_dir/headers(用作namespace)
+PRIVATE+ - the directory is added to this target's include directories:庫(kù)的src.cc自己gcc -I headers_include_path
+INTERFACE+ - the directory is added to the include directories for any targets that link this library. :任何link這個(gè)庫(kù)的編譯單元(如main.cc) gcc -I headers_include_path
+PUBLIC+ - As above, it is included in this library and also any targets that link this library. :上面兩條取并集
For public headers it is often a good idea to have your include folder be "namespaced"
with sub-directories.
The directory passed to +target_include_directories+ will be the root of your
include directory tree and your C++ files should include the path from there to your header.
For this example you can see that we do it as follows:
[source,cpp]
include "static/Hello.h"
static是include下一個(gè)目錄。用目錄的方式實(shí)現(xiàn)namespace
動(dòng)態(tài)庫(kù)區(qū)別不是很大,把static換成shared
add_library(hello::library ALIAS hello_library)
hello::libary是hello_library的引用別名。
——————————————————以上為lib和基礎(chǔ)編譯部分——————
————————————————