I need to control the library order during linking, but CMake is doing weird things with OpenCV libs. See the following CMakeLists.txt:
cmake_minimum_required(VERSION 3.13)
project(cvtest)
set( CMAKE_VERBOSE_MAKEFILE on )
add_executable(cvtest "test.cpp")
find_package(OpenCV 3 REQUIRED core)
target_link_libraries(cvtest ${OpenCV_LIBS} FOO)
When building the resulting makefile, libraries are linked in the following order:
libopencv_core.3.4.2.dylib -lFOO
All good so far (FOO needs to go last). However, if I add another opencv lib:
cmake_minimum_required(VERSION 3.13)
project(cvtest)
set( CMAKE_VERBOSE_MAKEFILE on )
add_executable(cvtest "test.cpp")
find_package(OpenCV 3 REQUIRED core highgui)
target_link_libraries(cvtest ${OpenCV_LIBS} FOO)
Then the linker recieves libraries in the following order:
libopencv_highgui.3.4.2.dylib -lFOO libopencv_videoio.3.4.2.dylib libopencv_imgcodecs.3.4.2.dylib libopencv_imgproc.3.4.2.dylib libopencv_core.3.4.2.dylib
Importantly, FOO is not last anymore! I tried everything but I cannot make FOO appear at the end of the linking list. Does anyone know how this can be done?
Thanks,