Libraries for Both a Target and its Dependents
Target_link_libraries to the Rescue
When packaging software libraries, it's common to deploy both a static and a shared library. Target_link_libraries is a CMake command that can help you achieve this goal.
Using target_link_libraries
To use target_link_libraries, you'll need to open the CMakeLists.txt file for your project and locate the target_link_libraries statement. This statement is used to specify the libraries that your target depends on.
For example, the following code snippet shows how to link a target named "mytarget" to the "libfoo" library:
target_link_libraries(mytarget PUBLIC libfoo)
The PUBLIC keyword specifies that the "libfoo" library should be linked to the "mytarget" library in a public manner. This means that the symbols from "libfoo" will be visible to other targets that link to "mytarget".
You can also use the PRIVATE keyword to specify that the "libfoo" library should be linked to the "mytarget" library in a private manner. This means that the symbols from "libfoo" will not be visible to other targets that link to "mytarget".
Additional Options
In addition to the PUBLIC and PRIVATE keywords, target_link_libraries also supports a number of other options. These options can be used to control the way that libraries are linked to your target.
For more information on target_link_libraries, please refer to the CMake documentation.
Komentar