cmake_minimum_required (VERSION 2.6 FATAL_ERROR)
# Name of the project
project (verifix CXX C)
#options
option(verifix_build_tests "Build tests for Verifix." OFF)
option(verifix_debug "Build debug version of Verifix." OFF)
# Define helper functions and macros.
include(cmake/internal_utils.cmake)
include(CheckIncludeFile)
config_compiler_and_linker()  # Defined in internal_utils.cmake.

set (verifix_VERSION_MAJOR 1)
set (verifix_VERSION_MINOR 1)
set (verifix_VERSION_PATCH 1)

IF(NOT CMAKE_BUILD_TYPE)
    IF(verifix_debug)
       SET(CMAKE_BUILD_TYPE Debug CACHE STRING
           "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
         FORCE)
     ELSE()
       SET(CMAKE_BUILD_TYPE Release CACHE STRING
           "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
         FORCE)
     ENDIF(verifix_debug)
ENDIF(NOT CMAKE_BUILD_TYPE)
set(EXECUTABLE_OUTPUT_PATH ${verifix_SOURCE_DIR}/bin)
file(MAKE_DIRECTORY ${verifix_SOURCE_DIR}/bin/tests)
file(MAKE_DIRECTORY ${verifix_BINARY_DIR}/src)
file(MAKE_DIRECTORY ${verifix_BINARY_DIR}/src/common)
file(MAKE_DIRECTORY ${verifix_BINARY_DIR}/src/system)
file(MAKE_DIRECTORY ${verifix_BINARY_DIR}/src/search)
# configure a header file to pass some of the CMake settings
# to the source code

configure_file (
  "${verifix_SOURCE_DIR}/src/config.h.in"
  "${verifix_BINARY_DIR}/src/config.h"
  )
find_program(LZZ_COMMAND lzz)
find_program(UDBM_COMMAND udbm-config)
find_package(Boost COMPONENTS program_options)
find_package(LibXml2 REQUIRED)

if (BUILD_SHARED_LIBS)
  message("Using dynamically linked boost libraries")
else()
  message("Using statically linked boost libraries")
  set(Boost_USE_STATIC_LIBS   ON)
endif()
find_package(Boost COMPONENTS program_options filesystem system REQUIRED)
execute_process(COMMAND ${UDBM_COMMAND} --dir
                OUTPUT_VARIABLE udbm_DIR)
string(REGEX REPLACE "[ \t\n]+" "" udbm_DIR "${udbm_DIR}")
include_directories(
        ${verifix_SOURCE_DIR}/src/tests/include
        ${verifix_SOURCE_DIR}/src/
        ${verifix_BINARY_DIR}/src/
	      ${Boost_INCLUDE_DIRS}
	      ${udbm_DIR}/include
	)
message("${udbm_DIR}/include ${UDBM_COMMAND}" )
link_directories(
          ${verifix_SOURCE_DIR}/bin/tests
          ${Boost_LIBRARY_DIRS}
          "/usr/local/lib"
	        ${udbm_DIR}/lib
	  )
if (verifix_build_tests)
   # This must be set in the root directory for the tests to be run by
   # 'make test' or ctest.
  enable_testing()
endif()

CHECK_INCLUDE_FILE("inttypes.h" HAVE_INTTYPES_H)
CHECK_INCLUDE_FILE("stdint.h" HAVE_STDINT_H)
CHECK_INCLUDE_FILE("strings.h" HAVE_STRINGS_H)
CHECK_INCLUDE_FILE("string.h" HAVE_STRING_H)
CHECK_INCLUDE_FILE("sys/stat.h"   HAVE_SYS_STAT_H)
CHECK_INCLUDE_FILE("sys/types.h"  HAVE_SYS_TYPES_H)
CHECK_INCLUDE_FILE("unistd.h"     HAVE_UNISTD_H)

add_subdirectory(src)
#No tests for the moment
#add_subdirectory(tests)
#enable_testing()
