########################################################################
#
# Project-wide settings

# Name of the project.
#
# CMake files in this project can refer to the root source directory
# as ${ccarve_SOURCE_DIR} and to the root binary directory as
# ${ccarve_BINARY_DIR}.
# Language "C" is required for find_package(Threads).
project(ccarve CXX C)
cmake_minimum_required(VERSION 2.6.2 FATAL_ERROR)

option(ccarve_build_tests "Build tests for cCarve." ON)
# BUILD_SHARED_LIBS is a standard CMake variable, but we declare it here to
# make it prominent in the GUI.
option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)." OFF)
option(ccarve_disable_pthreads "Disable uses of pthreads." OFF)
option(ccarve_debug "Build project using debugging code" OFF)
# to turn off: cmake -Dccarve_debug:BOOL=ON

set (ccarve_VERSION_MAJOR 1)
set (ccarve_VERSION_MINOR 1)
set (ccarve_VERSION_PATCH 1)

IF(NOT CMAKE_BUILD_TYPE)
    IF(ccarve_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(ccarve_debug)
ENDIF(NOT CMAKE_BUILD_TYPE)
# Define helper functions and macros.
include(cmake/internal_utils.cmake)
config_compiler_and_linker()  # Defined in internal_utils.cmake.

set(EXECUTABLE_OUTPUT_PATH ${ccarve_SOURCE_DIR}/bin)
file(MAKE_DIRECTORY ${ccarve_SOURCE_DIR}/bin/tests)
file(MAKE_DIRECTORY ${ccarve_SOURCE_DIR}/src/generated)
set(LIBRARY_OUTPUT_PATH ${ccarve_SOURCE_DIR}/lib)

# configure a header file to pass some of the CMake settings
# to the source code

configure_file (
  "${ccarve_SOURCE_DIR}/src/include/config.h.in"
  "${ccarve_SOURCE_DIR}/src/include/config.h"
  )

find_program(LZZ_COMMAND lzz)
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)

# Where .h files can be found.
include_directories(
        ${ccarve_SOURCE_DIR}/src/tests/include
        ${ccarve_SOURCE_DIR}/src/generated
        ${ccarve_SOURCE_DIR}/src/include
	${Boost_INCLUDE_DIRS}
	)

# Where generated libraries can be found.
link_directories(
          ${ccarve_SOURCE_DIR}/bin/tests
          ${Boost_LIBRARY_DIRS}
	  )


if (ccarve_build_tests)
   # This must be set in the root directory for the tests to be run by
   # 'make test' or ctest.
  enable_testing()
endif()

add_subdirectory(src)


set(DOC_FILES COPYRIGHT README CHANGELOG)
set(DOC_PATH "share/doc/ccarve-${ccarve_VERSION_MAJOR}.${ccarve_VERSION_MINOR}")
#install(FILES ${DOC_FILES}
#        DESTINATION ${DOC_PATH})

SET(CPACK_GENERATOR ZIP)
SET(CPACK_SOURCE_GENERATOR ZIP)
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "cCarve command line tool for carving dump sets")
SET(CPACK_PACKAGE_VENDOR "Piotr Kordy, Sjouke Mauw")
SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README")
SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYRIGHT")
SET(CPACK_PACKAGE_VERSION_MAJOR "${ccarve_VERSION_MAJOR}")
SET(CPACK_PACKAGE_VERSION_MINOR "${ccarve_VERSION_MINOR}")
SET(CPACK_PACKAGE_VERSION_PATCH "${ccarve_VERSION_PATCH}")
SET(CPACK_PACKAGE_INSTALL_DIRECTORY "ccarve-${ccarve_VERSION_MAJOR}.${ccarve_VERSION_MINOR}")
IF(WIN32 AND NOT UNIX)
  # There is a bug in NSI that does not handle full unix paths properly. Make
  # sure there is at least one set of four (4) backlasshes.
  SET(CPACK_NSIS_INSTALLED_ICON_NAME "bin\\\\ccarve.exe")
  SET(CPACK_NSIS_DISPLAY_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY} cCarve")
  SET(CPACK_NSIS_HELP_LINK "http:\\\\\\\\www.satoss.uni.lu/ccarve")
  SET(CPACK_NSIS_MODIFY_PATH ON)
ELSE(WIN32 AND NOT UNIX)
  SET(CPACK_STRIP_FILES "bin/ccarve")
  SET(CPACK_SOURCE_STRIP_FILES "")
ENDIF(WIN32 AND NOT UNIX)
SET(CPACK_PACKAGE_EXECUTABLES "ccarve" "cCarve")

set(CPACK_SOURCE_IGNORE_FILES
"/\\\\.svn/"
"/Tons/"
"/bin/"
"/build/.+$"
"/moveToSatoss$"
"/MyNotes$"
"/notes$"
"/clang_compile$"
"/generated/"
"/Session\\\\.vim$"
"/zip$"
"\\\\.zip$"
"/doc/"
"/tags$"
"/\\\\..*$"
"~$"
)
install(FILES ${DOC_FILES} DESTINATION .)
message("CPACK_SOURCE_IGNORE_FILES = ${CPACK_SOURCE_IGNORE_FILES}")
INCLUDE(CPack)

# 'other' documentation files
# *****************************
# Conditional compiling
# #ifdef DEBUG 
#    some code
# #endif
# 
# In order to tell CMake to add -DDEBUG to compile lines, you can use the SET_SOURCE_FILE_PROPERTIES with the COMPILE_FLAGS property.
#
# Better
# 
