######################################################################################################
#
#  created:    2015/09/18
#  filename:   CMakeLists.txt
#
#  author:     Gerald Dherbomez
#              Copyright Heudiasyc (c) UMR UTC/CNRS 7253
# 
#  license:    CECILL-C
# 
#  version:    $Id: $
#
#  brief:      Pacpus project template 
#
######################################################################################################

project(ProjectTemplate)
cmake_minimum_required(VERSION 2.8)

# ========================================
# ProjectTemplate version
# ========================================
set(ProjectTemplate_MAJOR_VERSION 0)
set(ProjectTemplate_MINOR_VERSION 0)
set(ProjectTemplate_PATCH_VERSION 1)
set(ProjectTemplate_VERSION
    "${ProjectTemplate_MAJOR_VERSION}.${ProjectTemplate_MINOR_VERSION}.${ProjectTemplate_PATCH_VERSION}")

# ========================================
# Configure CMake 
# ========================================
if(NOT ${PACPUS_ROOT} STREQUAL "")
	set(CMAKE_MODULE_PATH ${PACPUS_ROOT}/cmake)
	string (REPLACE "\\" "/" CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH})
	message (STATUS "setting CMAKE_MODULE_PATH to: "  ${CMAKE_MODULE_PATH})
elseif( NOT $ENV{PACPUS_ROOT} STREQUAL "")
    set(PACPUS_ROOT $ENV{PACPUS_ROOT})
	set(CMAKE_MODULE_PATH $ENV{PACPUS_ROOT}/cmake)
	string (REPLACE "\\" "/" CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH})
	message (STATUS "setting CMAKE_MODULE_PATH to: " ${CMAKE_MODULE_PATH})
    message (STATUS "PACPUS_ROOT is: " ${PACPUS_ROOT})
else()
	message (FATAL_ERROR "Environment variable PACPUS_ROOT not set, please define it in your operating system or pass it as argument to the cmake command")
endif()

include(${CMAKE_MODULE_PATH}/PacpusUtilities.cmake)
include(${CMAKE_MODULE_PATH}/PacpusConfiguration.cmake)
include(${CMAKE_MODULE_PATH}/PacpusDependencies.cmake)
include(${CMAKE_MODULE_PATH}/PacpusPlatforms.cmake)

# ========================================
# Pre-configuration of the compiler
# ========================================
find_package(Pacpus REQUIRED)
# Includes directories
if(PACPUS_FOUND)
include_directories(
  ${PACPUS_DEPENDENCIES_INC}
  ${PACPUS_INCLUDE_DIR}
)
# Compiler flags coming from PacpusDependencies and PacpusPlatforms
add_definitions(${PACPUS_DEFINITIONS})
endif(PACPUS_FOUND)


# ========================================
# Build the ProjectTemplate' modules
# ========================================
#
# In the following list add the plugin you want to build. 
# Paths are relative to the root of the project. 
#
add_subdirectory(plugin_exercise_1)
add_subdirectory(plugin_exercise_2)


# ========================================
# Summary
# ========================================
pacpus_info("")
pacpus_info("=====================================================================")
pacpus_info("Configuration for ProjectTemplate ${ProjectTemplate_VERSION}")
pacpus_info("=====================================================================")
pacpus_info("")
pacpus_info("  Platform:")
pacpus_info("    Host:" ${CMAKE_HOST_SYSTEM_NAME} ${CMAKE_HOST_SYSTEM_VERSION} ${CMAKE_HOST_SYSTEM_PROCESSOR})
if(CMAKE_CROSS_COMPILING)
    pacpus_info("    Target:" ${CMAKE_SYSTEM_NAME} ${CMAKE_SYSTEM_VERSION} ${CMAKE_SYSTEM_PROCESSOR})
endif()
pacpus_info("    CMake:" ${CMAKE_VERSION})
pacpus_info("    CMake generator:" ${CMAKE_GENERATOR})
pacpus_info("    CMake build tool:" ${CMAKE_BUILD_TOOL})
if(MSVC)
    pacpus_info("    MSVC:" ${MSVC_VERSION})
else()
    pacpus_info("    Configuration:" ${CMAKE_BUILD_TYPE})
endif()
pacpus_info("")
pacpus_info("  Compiler:")
pacpus_info("    C++ Compiler:" ${CMAKE_CXX_COMPILER})
pacpus_info("    C++ flags (release):" ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE})
pacpus_info("    C++ flags (debug):" ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG})
pacpus_info("")
pacpus_info("  Pacpus:")
pacpus_info("    PacpusFramework path:" ${PACPUS_ROOT})
pacpus_info("    Log4cxx logging enabled:" ${PACPUS_USE_LOG})
pacpus_info("")
if("${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}")
    message(WARNING "The source directory is the same as build directory. \"make clean\" may damage the source tree")
endif()

