1. Different Libraries Have Different Linking Methods
OpenCV uses ${OpenCV_LIBS}
target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS})
protobuf uses ${PROTOBUF_LIBRARIES}
target_link_libraries(${PROJECT_NAME} ${PROTOBUF_LIBRARIES})
jpeg-turbo uses the target name libjpeg-turbo::turbojpeg-static
target_link_libraries(${PROJECT_NAME} libjpeg-turbo::turbojpeg-static)
2. How to Determine Which Method to Use
Generally, the following methods can be used:
- Check the CMake file for usage instructions. (Well-written CMake files usually include usage instructions)
- Look for how others are using it online
- Search the CMake files for relevant variables, such as checking if OpenCV’s CMake files contain the “OpenCV_LIBS” variable
- Check the relevant target names in the CMake files
2.1 Check the CMake File for Usage Instructions
For example, OpenCV has usage instructions at the top of the OpenCVConfig.cmake file as follows:

2.2 Search CMake Files for Relevant Variables
For example, protobuf can find the PROTOBUF_LIBRARIES variable in protobuf-module.cmake
2.3 Check the Relevant Target Names in the CMake Files
For example, jpeg-turbo can find the relevant target in the libjpeg-turboTargets.cmake file: libjpeg-turbo::turbojpeg-static
How does everyone determine this?