cmake_minimum_required (VERSION 2.6)
cmake_policy (SET CMP0014 OLD)

project ("Rabbit Tree")
include_directories ("${PROJECT_SOURCE_DIR}/include")
set (
  RUNTIME_OUTPUT_DIRECTORY
  "${PROJECT_BINARY_DIR}/bin"
)

################################### Options ####################################
configure_file (
  "${PROJECT_SOURCE_DIR}/cmake_config.h.in"
  "${PROJECT_BINARY_DIR}/cmake_config.h"
)
include_directories ("${PROJECT_BINARY_DIR}")

option (
  RBT_DEBUG
  "Enable debugging messages."
  OFF
)

option (
  RBT_USE_COLOR
  "Use colors in some output functions if non-zero."
  OFF
)

option (
  RBT_DEBUG_USE_COLOR
  "Use colors in debugging and error messages if non-zero. If not defined,
  inherit from RBT_USE_COLOR."
  OFF
)


option (
  BUILD_EXAMPLES
  "Build the included examples."
  OFF
)



##################################### HTML #####################################
if (NOT HTML_SUFFIX)
  set (
    HTML_SUFFIX
    ".html"
  )
endif (NOT HTML_SUFFIX)



################################### Examples ###################################
if (BUILD_EXAMPLES)
  include_directories ("${PROJECT_SOURCE_DIR}/examples")
  add_subdirectory (examples)
  set(CMAKE_C_FLAGS "-Wall -g")

  add_executable (string_set examples/string_set.c)
  add_executable (string_to_const_string examples/string_to_const_string.c)
  add_executable (string_to_const_string.expanded examples/string_to_const_string.expanded.c)
  add_executable (int_to_const_string examples/int_to_const_string.c)

  add_test(
    NAME TestExamples
    WORKING_DIRECTORY "${PROJECT_BINARY_DIR}"
    COMMAND "${PROJECT_SOURCE_DIR}/tests/test_examples.sh" test
  )
  set_tests_properties(
    TestExamples
    PROPERTIES
    PASS_REGULAR_EXPRESSION "^all tests passed\n$"
  )
endif (BUILD_EXAMPLES)



################################### Doxygen ####################################
find_package(Doxygen)
if (DOXYGEN_FOUND)
configure_file(
  "${PROJECT_SOURCE_DIR}/Doxyfile.in"
  "${PROJECT_BINARY_DIR}/Doxyfile"
  @ONLY
)
add_custom_target(
  doc ALL
  ${DOXYGEN_EXECUTABLE} "${PROJECT_BINARY_DIR}/Doxyfile"
  WORKING_DIRECTORY "${PROJECT_BINARY_DIR}"
  COMMENT "Generating API documentation with Doxygen"
  VERBATIM
)
install (
  DIRECTORY "${PROJECT_BINARY_DIR}/doc"
  DESTINATION share/rbt
  COMPONENT doc
)
endif (DOXYGEN_FOUND)



################################# Installation #################################
install (
  DIRECTORY include/
  DESTINATION include/rbt
)



#################################### Tests #####################################
ENABLE_TESTING()