Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preventing CMake from finding installed libraries instead of "local" libraries

I'm working on multiple projects at the same time (some libraries, and some games that depend on them). They're all on GitHub, in separate repos.

For convenience, I pull every repo in a "workspace folder", like this:

/home/myWorkspace/Library1/
/home/myWorkspace/Library2/
/home/myWorkspace/Library3/
/home/myWorkspace/App1/
/home/myWorkspace/App2/

I have FindLibrary1, FindLibrary2 and FindLibrary3 .cmake files, which, in order, look for the library in ../ (which corresponds to the "myWorkspace" folder), then /usr/lib/.

While on Windows CMake finds the libraries in myWorkspace/, on Linux, no matter what, installed libraries are always found first.

Since I'd like to work in myWorkspace/ folder, then installing the libraries after I'm done, I'd prefer CMake to find and link everything within the myWorkspace/ folder.

I'd also like CMake to search for the libraries in /usr/lib/ and /usr/local/lib/ if there is no myWorkspace/ folder, but if myWorkspace/ exists, it should have the priority.

Examples of CMake files I'm using:


SSVUtils: library with no dependancies

SSVUtils CMakeLists: https://github.com/SuperV1234/SSVUtils/blob/master/CMakeLists.txt

FindSSVUtils.cmake: https://github.com/SuperV1234/SSVUtils/blob/master/cmake/modules/FindSSVUtils.cmake


SSVUtilsJson: library that depends on SSVUtils and SSVJsonCpp

SSVUtilsJson CMakeLists: https://github.com/SuperV1234/SSVUtilsJson/blob/master/CMakeLists.txt

FindSSVUtilsJson.cmake: https://github.com/SuperV1234/SSVUtilsJson/blob/master/cmake/modules/FindSSVUtilsJson.cmake


Any ideas how I can prioritize the myWorkspace/ folder while still having the possibility to find libs in file system paths?

like image 577
Vittorio Romeo Avatar asked Jun 01 '13 18:06

Vittorio Romeo


1 Answers

By default, find_path (or find_library, etc.) first checks for files in the system standard locations, before searching in the values provided in PATH. That's why "installed" libraries are always found first on Linux (but not on Windows, that doesn't have standard locations for installed libraries).

You can disable that behavior by using the NO_CMAKE_SYSTEM_PATH option: it will skip detection of files in standard locations.

Now... if you still want to use the installed libraries as a fallback when local versions are not found, you can do it in a two step process:

find_path(... NO_CMAKE_SYSTEM_PATH)

if (nothing_found)
    find_path(...)
endif()
like image 128
Guillaume Avatar answered Oct 12 '22 13:10

Guillaume