# - Build arpon
#
# The following variables can be modified:
#
# CMAKE_C_FLAGS        - Set flags for the C compiler
# CMAKE_BUILD_TYPE     - Set build type: release or debug
# CMAKE_LIBRARY_PATH   - Set the library path
# CMAKE_INCLUDE_PATH   - Set the include path
# CMAKE_INSTALL_PREFIX - Set the install prefix for arpon.
#                        By default arpon will be installed to /usr/loca/ path.
#
# Copyright 2014 <Giuseppe Marco Randazzo> gmrandazzo@gmail.com
#
# Redistribution AND use is allowed according to the terms of the BSD 3 clause

cmake_minimum_required(VERSION 2.6)
project(ArpON)
set(AUTHOR "Andrea Di Pasquale" INTERNAL "Author")
set(VERSION "2.7.2")

if(NOT CMAKE_BUILD_TYPE)
  set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: Debug Release" FORCE)
endif(NOT CMAKE_BUILD_TYPE)

if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
  set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "ArpON install prefix" FORCE)
endif(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)

set(CMAKE_LIBRARY_PATH /lib;
                       /usr/lib;
                       /usrc/lib64;
                       /usr/local/lib;
                       /usr/local/lib64;
                       /usr/local/lib/libnet11;
                       /usr/local/lib/libnet-1.1;
                       /usr/pkg/lib;
                       /usr/pkg/lib/libnet11;
                       /opt/csw/lib;
                       ${CMAKE_LIBRARY_PATH})

set(CMAKE_INCLUDE_PATH /usr/include/;
                       /usr/local/include/;
                       /usr/local/include/libnet11;
                       /usr/local/include/libnet-1.1;
                       /usr/pkg/include;
                       /usr/pkg/include/libnet11;
                       /opt/csw/include;
                       ${CMAKE_INCLUDE_PATH})

string(TOLOWER "${CMAKE_BUILD_TYPE}" cmake_build_type_tolower)
if(cmake_build_type_tolower STREQUAL "debug")
  message(STATUS "Build Type: Debug")
  set(CMAKE_BUILD_TYPE "Debug")
  set(CMAKE_C_FLAGS "-Wall -Werror -pedantic -O0 -g")
else()
  message(STATUS "Build Type: Release")
  set(CMAKE_BUILD_TYPE "Release")
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror")
endif()

include_directories(
  ${PROJECT_BINARY_DIR}
  ${PROJECT_SOURCE_DIR}/src
  ${CMAKE_CURRENT_BINARY_DIR} 
  ${CMAKE_CURRENT_SOURCE_DIR}
  ${CMAKE_INCLUDE_PATH}
)

set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules/")
find_package(System)
find_package(Pthread)
find_package(DNET)
find_package(NET)
find_package(PCAP)

add_subdirectory(src)
add_subdirectory(man8)
add_subdirectory(etc)

configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in" 
        "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY)
add_custom_target(uninstall "${CMAKE_COMMAND}" -P 
        "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")

