Sunday, December 5, 2010

CMake - Build with Boost and Firebird

In the previous post I explained how to use wxWidgets with CMake.
Now we will look at the steps to successfully build a program that uses Firebird and the Boost library.

Boost is a well know and widely used library. Most of it does not require linking to a library file, just include some headers. That is what I do in my program, and here is the CMake code:

# try find BOOST (we need headers only)
find_package( Boost 1.37.0 )
if( Boost_FOUND)
  include_directories( ${Boost_INCLUDE_DIRS} )
endif( Boost_FOUND)

more information in C:\Program Files\CMake 2.8\share\cmake-2.8\Modules\FIndBoost.cmake. I am sure that you will figure out the correct path for your computer.

I use the IBPP library as a data access layer, and it requires a preprocessor definition to specify the operating system. Here is the CMake code:

# definitions for IBPP
if( WIN32 )
  add_definitions( -DIBPP_WINDOWS )
elseif( APPLE )
  add_definitions( -DIBPP_DARWIN )
else( WIN32 )
  add_definitions( -DIBPP_LINUX )
endif( WIN32 )

Under Windows the Firebird client library is loaded dynamically so there are no othe rrequirements.
Under Linux and OS X the program must link with the client library. Here is the CMake code:

if( UNIX )
  # link to the Firebird client library
  # the last path is used for OS X where I have a local copy (not installed)
  find_library( FB_LIB fbembed PATHS /usr/lib /usr/local/lib /opt/firebird/lib ${PROJECT_SOURCE_DIR}/firebird_runtime/firebird )
  if( NOT FB_LIB )
    message( FATAL_ERROR "Unable to find firebird interface" )
  else( NOT FB_LIB )
    message( STATUS "Firebird interface: " ${FB_LIB} )
  endif( NOT FB_LIB )

  target_link_libraries( MyTarget ${FB_LIB} )
endif( UNIX )

the find_libary command accepts some paths as parameters. They are used as suggestions to find the file. The example contains my paths, you will probably change them.

With this code in CMakeLists.txt it should be possible to successfully build the program. The next problem will be make it run using an embedded copy of Firebird.

No comments:

Post a Comment