views:

61

answers:

3

I've started using CMake as a build tool for a cross-platform command line program that requires FFTW3 and Boost.Format. I'm familiar with the Unix-like standard directory structures for headers and binaries of installed libraries but I'm wondering what the quasi standard is on Windows platforms as to how and where libraries are installed, organized, etc. Are there any quasi standard environment variables I could use in my CMakeLists.txt / FindXXX.cmake scripts for finding libraries? Where should I put the FFTW3 headers and binaries on a Windows platform? Does it make sense to install something like pkg-config on a Windows box? Obviously, I don't want to hard-code the libraries' paths so it just works on my Windows box with exactly the same directory structure.

TIA, sellibitze

A: 

Have you considered requiring a cygwin installation for windows targets ? That would at least solve the question of what standards to adhere to.

gilligan
A: 

The default install path for Windows usually looks like C:\Program Files\<company name>\<app name>\ or C:\Program Files\<app name>\. However, FFTW comes in the form of a zip file and it's up to the user to decide where to put it. I would probably have the CMake find module check the two afore mentioned spots and if nothing is found, spit out an informative message.

Maybe someone else will have a better suggestion.

dgnorton
+1  A: 

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})
SirDarius