CMake has an interesting feature is that it keeps a cache of the values you would otherwise specify on the ./configure command line for non-standard library locations.
My way of doing things is the following:
- if the library comes with an installer, for instance, the windows version of OpenSSL, I will install it in the recommended folder, ie. C:\Program Files\OpenSSL.
- if the library comes in a zip, I usually decompress them under a C:\dev directory, in order to facilitate further migrations and to make the folders shorter to type and easier to find.
Then, when compiling my CMake-powered project, I run the graphical tool to generate the CMakeCache.txt file, not caring about errors triggered by FindXXX modules that have failed to find my external libraries.
Instead, I will then use the CMake GUI to browse for the directories where the header files and the library files are located, and manually set up the correct folders. As long as the cache is not removed, these paths will remain in CMakeCache.txt even if the CMakeLists.txt files are modified.
In some cases, the installed libraries set up environment variables that the CMake modules can use to locate them, like Boost (the BOOST_ROOT variable). This makes it very easy to use an installed Boost in windows with CMake, as you can see here :
##### Boost libraries #####
include(FindBoost)
if(MSVC)
find_package(Boost 1.40.0 REQUIRED) # msvc autolink support means we don't specify libs
else(MSVC)
find_package(Boost 1.40.0 REQUIRED COMPONENTS system)
endif(MSVC)
include_directories(${Boost_INCLUDE_DIRS})
set(Boost_USE_STATIC_LIBS ON)
link_directories(${Boost_LIBRARY_DIRS})
Then you can link your executables with Boost doing the following thing:
add_executable(program_example program_example.cpp)
target_link_libraries(program_example ${Boost_LIBRARIES})