Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

force cmake FIND_LIBRARY to look in custom directory

Tags:

cmake

cmake version 2.8.4

I have the following apache portable runtime libraries that I have compiled myself and want my application to link against.

My project directory where my apr libraries are:

gw_proj/tools/apr/libs

In my CMakeLists.txt I have the following:

FIND_LIBRARY(APRUTIL NAMES "aprutil-1"
  PATHS ${PROJECT_SOURCE_DIR}/tools/apr/libs)

My problem is on a machine that already has the apache portable runtime already installed it will look for it in this folder:

/usr/lib

So will always ignore my custom path.

How can I force the FIND_LIBRARY to always look in my custom directory:

gw_proj/tools/apr/libs

Many thanks for any suggestions

like image 773
ant2009 Avatar asked Apr 02 '13 11:04

ant2009


People also ask

What does Find_library do in CMake?

find_library (<VAR> name1 [path1 path2 ...]) This command is used to find a library. A cache entry named by <VAR> is created to store the result of this command. If the library is found the result is stored in the variable and the search will not be repeated unless the variable is cleared.

How find_ package works CMake?

FIND_PACKAGE(<name>) asks CMake to find and load settings from the external package <name>. This works as follows: CMake searches the directories listed in CMAKE_MODULE_PATH for a file called Find<name>. cmake.

Where does CMake look for libraries on Windows?

CMake looks into the paths stored in the ${CMAKE_MODULE_PATH} variable for the files with the find-instructions. The find-files have to be named according to a certain convention which essentially boils down to <libraryname>. cmake .


1 Answers

You can specify the search order using one or more of NO_DEFAULT_PATH, NO_CMAKE_ENVIRONMENT_PATH , NO_CMAKE_PATH, NO_SYSTEM_ENVIRONMENT_PATH, NO_CMAKE_SYSTEM_PATH, CMAKE_FIND_ROOT_PATH_BOTH, ONLY_CMAKE_FIND_ROOT_PATH, orNO_CMAKE_FIND_ROOT_PATH.

From the docs for find_library:

The default search order is designed to be most-specific to least-specific for common use cases. Projects may override the order by simply calling the command multiple times and using the NO_* options:

find_library(<VAR> NAMES name PATHS paths... NO_DEFAULT_PATH)
find_library(<VAR> NAMES name)

Once one of the calls succeeds the result variable will be set and stored in the cache so that no call will search again.

So in your case, you can do

FIND_LIBRARY(APRUTIL NAMES "aprutil-1"
  PATHS ${PROJECT_SOURCE_DIR}/tools/apr/libs NO_DEFAULT_PATH)
like image 150
Fraser Avatar answered Sep 24 '22 18:09

Fraser