message(".==============================================================================.")
message("|           QUANTIS Random Number Generator software by id Quantique           |")
message("|                                                                              |")
message("|         Copyright (C) 2004-2010 id Quantique SA. All Rights Reserved.        |")
message("|                                                                              |")
message("|                                                                              |")
message("|  Redistribution and use in source and binary forms, with or without          |")
message("|  modification, are permitted provided that the following conditions          |")
message("|  are met:                                                                    |")
message("|  1. Redistributions of source code must retain the above copyright           |")
message("|     notice, this list of conditions, and the following disclaimer,           |")
message("|     without modification.                                                    |")
message("|  2. Redistributions in binary form must reproduce the above copyright        |")
message("|     notice, this list of conditions and the following disclaimer in the      |")
message("|     documentation and/or other materials provided with the distribution.     |")
message("|  3. The name of the author may not be used to endorse or promote products    |")
message("|     derived from this software without specific prior written permission.    |")
message("|                                                                              |")
message("|  THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ''AS IS'' AND      |")
message("|  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE       |")
message("|  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE  |")
message("|  ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR  |")
message("|  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL      |")
message("|  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS     |")
message("|  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)       |")
message("|  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT  |")
message("|  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY.  |")
message("|                                                                              |")
message("+  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -   +")
message("|                                                                              |")
message("|  Alternatively, this software may be distributed under the terms of the      |")
message("|  GNU General Public License version 2 as published by the Free Software      |")
message("|  Foundation.                                                                 |") 
message("|                                                                              |")
message("|  This program is distributed in the hope that it will be useful, but         |")
message("|  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY  |")
message("|  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License     |")
message("|  for more details.                                                           |")
message("|                                                                              |")
message("|  You should have received a copy of the GNU General Public License           |")
message("|  along with this program; if not, write to the Free Software                 |")
message("|  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA    |")
message("|                                                                              |")
message("+------------------------------------------------------------------------------+")
message("|                                                                              |")
message("| Usage: cmake . [OPTIONS]                                                     |")
message("|                                                                              |")
message("|  OPTIONS:                                                                    |")
message("|                                                                              |")
message("|     -DDISABLE_QUANTIS_PCI=1            Disable Quantis PCI support.          |")
message("|                                                                              |")
message("|     -DDISABLE_QUANTIS_USB=1            Disable Quantis USB support.          |")
message("|                                                                              |")
message("|     -DDISABLE_QUANTIS_JAVA=1           Disable Java support.                 |")
message("|                                                                              |")
message("|     -DENABLE_QUANTIS_COMPAT=1          Build API v1 compatibility libraries. |")
message("|                                                                              |")
message("|     -DDISABLE_EASYQUANTIS=1            Don't build EasyQuantis application.  |")
message("|                                                                              |")
message("|     -DDISABLE_EASYQUANTIS_GUI=1        Only build command-line version of    |")
message("|                                        the EasyQuantis application.          |")
message("|                                                                              |")
message("|     -DFORCE32BIT=1 | -DFORCE64BIT=1    Force 32-bit or 64-bit ABI.           |")
message("|                                                                              |")
message("|     -DCMAKE_BUILD_TYPE=None | Debug | Release | RelWithDebInfo | MinSizeRel  |")
message("|                                                                              |")
message("|     -DCMAKE_INSTALL_PREFIX:PATH=/path  Set install directory prefix to /path.|")
message("|                                        Default value is                      |")
message("|                                           /opt/IDQQuantis on Solaris         |")
message("|                                           / on all other systems             |")
message("|                                                                              |")
message("|     -DCMAKE_VERBOSE_MAKEFILE=1         Enable Makefile verbose mode.         |")
message("|                                        Verbose can be useful for debugging   |")
message("|                                        and is disabled by default.           |")
message("|                                                                              |")
message("+  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -   +")
message("|                                                                              |")
message("| NOTE:                                                                        |")
message("|   Libraries and binaries are compiled using the GNU Compiler Collection.     |")
message("|   It is possible to use use an alternative compiler by overloading the       |")
message("|   CC and CXX variables:                                                      |")
message("|      CC=gcc CXX=g++ cmake .            Use GNU Compiler Collection (default).|")
message("|      CC=icc CXX=icpc cmake .           Use Intel C/C++ Compiler.             |")
message("|      CC=cc  CXX=CC cmake .             Use Sun Studio  Compiler.             |")
message("°==============================================================================°")
message("")


# ########## Project setup ##########
project(QuantisRNG)

cmake_minimum_required(VERSION 2.6.0)

# Uses 2.6.3 policies
# cmake_policy(VERSION 2.6.3)

# Include project's CMake files
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMake")

# Consistency check
if(FORCE32BIT AND FORCE64BIT)
  message(FATAL_ERROR "-- Can't use both FORCE32BIT and FORCE64BIT!")
endif()

if(FORCE64BIT OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64" AND NOT FORCE32BIT)
  set(SOFTWARE_ARCHITECTURE "amd64")
  message("-- Software architecture: amd64 (x86-64)")
else()
  set(SOFTWARE_ARCHITECTURE "i386")
  message("-- Software architecture: i386")
endif()

# Build
if(NOT CMAKE_BUILD_TYPE)
  message("-- CMAKE_BUILD_TYPE not set")
  message("---- Setting build type to 'Release'")
  set (CMAKE_BUILD_TYPE Release)
endif()


# Installation's directory prefix
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
  if(CMAKE_SYSTEM_NAME MATCHES "SunOS")
    set(CMAKE_INSTALL_PREFIX "/opt/IDQQuantis")
  else()
    set(CMAKE_INSTALL_PREFIX "/")
  endif()
endif()

# Set default installation directories
include(InstallDirs)

# Set custom compilers flags
include (CompilersFlags)


# ########## Definitions' header file ##########
# include(CheckIncludeFile)
# include(CheckIncludeFileCXX)
# 
# # Configuration checks
# CHECK_INCLUDE_FILE("malloc.h" HAVE_MALLOC_H)
# 
# # Generate a header file with the specific definitions
# configure_file(
#   "${PROJECT_SOURCE_DIR}/Quantis/QuantisLibConfig.h.in"
#   "${PROJECT_BINARY_DIR}/QuantisLibConfig.h"
# )
# 
# # Generate a header file with the specific definitions
# configure_file(
#   "${PROJECT_SOURCE_DIR}/EasyQuantis/EasyQuantisConfig.h.in"
#   "${PROJECT_BINARY_DIR}/EasyQuantisConfig.h"
# )
# 
# # Include directory containing generated files
# include_directories(${PROJECT_BINARY_DIR})


# ########## Configure external libraries ##########

# ---------- Boost libs ----------
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)

# ########## Various ##########

# Adds current directory (base source directory) to the include path.
# This way includes like
#    #include "../../MyLibrary/MyHeader.h"
# can be simplified to
#    #include "MyLibrary/MyHeader.h"
include_directories("${CMAKE_CURRENT_SOURCE_DIR}")

# Also includes base Quantis Software Package directory
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/..")


# ########## Generates installing packages ##########
include(QuantisPackages)

# ########## Includes sub-directories ##########

# Quantis library
add_subdirectory(Quantis)

# EasyQuantis application
if(NOT DISABLE_EASYQUANTIS)
  if (CMAKE_SYSTEM_NAME MATCHES "SunOS" AND SOFTWARE_ARCHITECTURE MATCHES "amd64")
    message(STATUS "warning: Building 64-bit version of EasyQuantis!")
    message(STATUS "warning: This will almost probably fail if you did not build 64-bit QT libaries manually!")
  endif() 
  add_subdirectory(EasyQuantis)
else()
  message("-- NOT building EasyQuantis")
endif()
  

