Reputation: 194
I have a C++ project that contains source files. For an external project, there are some folders I need to search for included libraries:
/home/data/lib/wisenet
/home/data/lib/wise_log
/home/data/lib/wise_rs_device
/home/data/lib/json
/home/data/lib/wise_versioning
What must I write to include these external libraries in CMake? These folders contain only interface resources (h files and .a libraries).
I tried to include these directories like this:
include_directories(
/home/data/lib/wisenet
/home/data/lib/wise_log
... etc
)
And I don't understand how to correctly add the lib files such as libwise_rs_device.a
.
Upvotes: 2
Views: 435
Reputation: 41750
Include directories only are for... well, include paths for your code. It won't link libraries.
The correct way to use external library is using imported libraries:
add_library(wise_rs_device STATIC IMPORTED GLOBAL)
set_target_properties(wise_rs_device PROPERTIES
IMPORTED_LOCATION "path/to/static/library"
INTERFACE_INCLUDE_DIRECTORIES "path/to/headers/of/wise_rs_device"
)
Then, you can simply link the imported target to yours:
# will link to the static library and add include directories.
target_link_libraries(your_executable PRIVATE wise_rs_device)
Upvotes: 4