[CMake] choosing specific version of a library with find_package (i.e. choosing macports in /opt/local over system default in /usr)

Michael Jackson mike.jackson at bluequartz.net
Thu Jun 7 18:00:46 EDT 2012


<opinion>I think the complexity is brought about by using MacPorts or Fink. If you simply compile the libraries yourself instead of letting MacPorts do it and install the libraries in /usr/local my guess your experience may be better.</opinion>

Not sure which libraries you are using from MacPorts but do those libraries have any specific environment variables that you can set that would help tell CMake where to look? Like Boost has BOOST_ROOT and Qt has QTDir. I had to write a couple of modules that over-ride the standard modules included with CMake in order to look for environment variables FIRST and set the search paths accordingly.
___________________________________________________________
Mike Jackson                    Principal Software Engineer
BlueQuartz Software                            Dayton, Ohio
mike.jackson at bluequartz.net              www.bluequartz.net

On Jun 7, 2012, at 5:27 PM, Natalie Tasman wrote:

> Thank you for your detailed reply, Rolf.  The code you've included
> looks to me like the similar complexity of the code I've seen in the
> "FindModulexxx.cmake" files-- it looks like a solution for this one
> specific library, but perhaps one I'd have to replicate for every
> library used in the project.  At this point the complexity of my
> CMakeLists files would seem to approach the existing makefile solution
> we've put together.
> 
> I am getting the impression that mac os x with additional library
> installations via macports or fink is not a first-class supported
> platform for CMake.  I'm evaluating CMake as a potential replacement
> for a large open-source C++ project, which is currently carefully
> maintained with a large makefile system for linux, mingw, and mac os x
> and also simultaneously, separate Visual Studio build files (for
> different versions of MSVC as well), so I'm definitely interested in
> the answers here.  I'd need to present an convincing argument that
> switching to CMake and maintaining a CMake build system will be less
> complex than what we already have with more uniform platform coverage;
> perhaps if mac os x is involved, the answer is no?
> 
> Many thanks,
> 
> Natalie
> 
> 
> 
> On Wed, Jun 6, 2012 at 11:42 PM, Rolf Eike Beer <eike at sf-mail.de> wrote:
>> Am Mittwoch, 6. Juni 2012, 16:15:52 schrieb Natalie Tasman:
>>> Andreas, thank you for your help.  Not surprisingly (for someone new
>>> to cmake) I was getting tripped up with the cmake cache, in part.
>>> Here's what I've found using cmake 2.8.8:
>>> 
>>> 0) One can get tripped up working with the both GUI and the command
>>> line.  I was manually clearing cache files from the commandline and
>>> re-generating the cmake project with the GUI.  I didn't realize that
>>> you had to use the GUI's "delete cache" as well (or just skip the
>>> GUI.)
>>> 
>>> 1) to force an alternate location (such as /opt/local for me), use
>>>   set(CMAKE_PREFIX_PATH /opt/local ${CMAKE_PREFIX_PATH})
>>> 
>>> In this case, cmake ONLY searches the alternate
>>> 
>>> 2) to add a "backup" or "fallback" location, use
>>>   INCLUDE_DIRECTORIES(/opt/local/include)
>>>   LINK_DIRECTORIES(/opt/local/lib)
>> 
>> This is sortof wrong. You need to specify include_directories() anyway to tell
>> the compiler where to search for the libraries. And you for sure should not be
>> using link_directories at all as it bypasses the normal link directory
>> ordering of CMake.
>> 
>> I assume you want to be able to tell CMake about a location from outside (i.e.
>> without touching the CMakeLists.txt anymore) and be sure that CMake finds the
>> library in the same place as the header. Try something like the following
>> (untested):
>> 
>> find_library(MYLIB foobar HINTS ENV FOOBAR_PREFIX)
>>  #get's the path
>> get_filename_component(MYLIB_PREFIX "${MYLIB}" PATH)
>> #goes one leven upwards, e.g. cuts the "/lib"
>> get_filename_component(MYLIB_PREFIX "${MYLIB}" PATH)
>> find_path(MYHDR foo.h HINTS ${MYLIB_PREFIX
>>          PATH_SUFFIXES include
>>          NO_DEFAULT_PATH NO_CMAKE_ENVIRONMENT_PATH
>>          NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH)
>> 
>> To find out what all those options do have a look at "cmake --help-command
>> find_library" and "cmake --help-command find_path".
>> 
>> Eike
>> 



More information about the CMake mailing list