[CMake] Mixing optional and required libraries with find_package

storri storri at torri.org
Mon Aug 9 08:55:52 EDT 2010


I don't think it is possible to find both required and optional
libraries with the same find_package command. Is that true?

I have a installation of Boost which has a proposed library added into
it called Boost.Log ('log' for short). I require the
boost_program_options library but optionally can use 'log' and
'boost_thread' (if Boost.Log is compiled with threads).

My idea was to do the following:

        find_package(Boost REQUIRED program_options)
        find_library(Boost.Log NAMES boost_log PATHS
        ${BOOST_LIBRARYDIR})

I am not sure if I can use the BOOST_LIBRARYDIR in the find_library
command. My initial test says that the answer is no. If I use the above
script in my CMakeLists.txt I get:

        //Path to a library.
        Boost_LOG_LIBRARY_DEBUG:FILEPATH=Boost_LOG_LIBRARY_DEBUG-NOTFOUND
        
        //Path to a library.
        Boost_LOG_LIBRARY_RELEASE:FILEPATH=Boost_LOG_LIBRARY_RELEASE-NOTFOUND

I would like to have it so I can declare a variable to be added to the
compiler flags to enable the preprocessor to use the library or compile
out the instructions wrapped with #ifdef BOOST_LOG.

Stephen



More information about the CMake mailing list