Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm currently trying to get CMake running for my project (on windows). I want to use a custom location where all libraries are installed. To inform CMake about that path I tried to do that:

set(CMAKE_PREFIX_PATH D:/develop/cmake/libs)

But when I try to find the library with

find_library(CURL_LIBRARY NAMES curl curllib libcurl_imp curllib_static)

CMake can't find it. When I set my prefix path to

set(CMAKE_PREFIX_PATH D:/develop/cmake/libs/curl)

... the library is located.

So my question is: How can I configure CMake properly to work with a directory structore at a custom location which looks like that:

D:/develop/cmake/libs/
-> libA
   -> include
   -> lib
-> libB
   -> include
   -> lib
-> ...
   -> include
   -> lib

In "include" lie the public headers and in "lib" are the compiled libraries.

Hope someone can help me - Thanks in advance

edit: The current workaround for me is, to do this before i search for libraries:

set(CUSTOM_LIBRARY_PATH D:/develop/cmake/libs)
file(GLOB sub-dir ${CUSTOM_LIBRARY_PATH}/*)
foreach(dir ${sub-dir})
    if(IS_DIRECTORY ${dir})
        set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH};${dir})
    endif()
endforeach()

But that way the default module for boost wont find it until it because the directory structore of boost is a bit different.

boost -> include -> boost-1_50 -> *.hpp

When I move the content if "boost-1_50" to "include" the library can be found but that way it's not possible to handle multiple versions right?

See Question&Answers more detail:os

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

1 Answer

The simplest solution may be to add HINTS to each find_* request.

For example:

find_library(CURL_LIBRARY
    NAMES curl curllib libcurl_imp curllib_static
    HINTS "${CMAKE_PREFIX_PATH}/curl/lib"
)

For Boost I would strongly recommend using the FindBoost standard module and setting the BOOST_DIR variable to point to your Boost libraries.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...