欢迎光临散文网 会员登陆 & 注册

cmake

2023-03-21 10:52 作者:米诺斯人  | 我要投稿

|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或者header_dir/headers(用作namespace)

  • +PRIVATE+ - the directory is added to this target's include directories:库的src.cc自己gcc -I headers_include_path

  • +INTERFACE+ - the directory is added to the include directories for any targets that link this library. :任何link这个库的编译单元(如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下一个目录。用目录的方式实现namespace


动态库区别不是很大,把static换成shared

add_library(hello::library ALIAS hello_library)

hello::libary是hello_library的引用别名。

——————————————————以上为lib和基础编译部分——————

————————————————



cmake的评论 (共 条)

分享到微博请遵守国家法律