Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
816 views
in Technique[技术] by (71.8m points)

force cmake FIND_LIBRARY to look in custom directory

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...