0

I've built and make installed opencv on my mac with SHARED_LIBS. I want to be able to choose for each project if I built with or without shared libs.

When I compile an additional OpenCV build with -DBUILD_SHARED_LIBS=OFF how can I reference it in my project's CMakeLists and chose the build type I want?

I have the source with shared libs in my ~/opencv and I've already compiled it in ~/opencv/build followed by make install.

When I create another dir like ~/opencv/static_build how would I have to adapt my CMakeLists in order to make a static build app? So far I've used:

    find_package( OpenCV REQUIRED )

    include_directories(${OpenCV_INCLUDE_DIRS})
    target_link_libraries(test ${OpenCV_LIBS})

But if I'm not mistaken, these lines all depend variables which have been added to cmake during my inital make install.

Picard
  • 983
  • 9
  • 23
  • Your first question already has an answer [here](https://stackoverflow.com/a/7585256/3987854). Did you try it? Consider checking out [this](https://stackoverflow.com/help/how-to-ask) page before posting, as you should limit your question post to **one specific** issue. – Kevin Nov 07 '19 at 12:28
  • You probably haven‘t read my question. It is exactly one specific issue. And your link doesnt answer my question. But I‘ll try to make my question more clear. – Picard Nov 07 '19 at 13:47

1 Answers1

1

It works by configuring a different install location with the cmake flag -D CMAKE_INSTALL_PREFIX for each build and make install will then install them to their respective locations.

In order to distinguish between the specific builds and to allow cmake to find the library if it not in its path, one has to add the following line to the project's CMakeLists.txt:

set(OpenCV_DIR /path/to/build/lib/cmake)

before:

find_package( OpenCV REQUIRED )

Picard
  • 983
  • 9
  • 23