General
- 添加链接库
# add link library bar to foo
# method 1
include_directories(path/to/bar/headers/directory)
link_directories(path/to/bar.so/or/bar.a/directory)
add_executable(foo ${FOO_SRCS})
target_link_libraries(foo bar)
# method 2
add_executable(foo ${FOO_SRCS})
target_link_libraries(foo dl "path/to/bar.so/or/bar.a")
target_include_directories(test PUBLIC "path/to/bar/headers/directory")
# method 3
add_library(bar SHARED IMPORTED) # or STATIC instead of SHARED
set_target_properties(bar PROPERTIES
IMPORTED_LOCATION "path/to/bar.so/or/bar.a"
INTERFACE_INCLUDE_DIRECTORIES "path/to/bar/headers/directory"
)
add_executable(foo ${FOO_SRCS})
target_link_libraries(foo bar) # also adds the required include path
Windows
CMake的基本操作(以Windows平台为例)_yp18792574062的博客-CSDN博客