project(PML)

cmake_minimum_required(VERSION 2.6)

set(VERSION_STRING "pml - ${CAMITK_VERSION_STRING} (c) UJF-Grenoble 1, CNRS, TIMC-IMAG UMR 5525")
configure_file(${PML_SOURCE_DIR}/PhysicalModelVersion.h.in ${PML_BINARY_DIR}/PhysicalModelVersion.h)

#set (CMAKE_VERBOSE_MAKEFILE ON CACHE BOOL "Verbose makefile" FORCE)

# compile in debug mode
if(NOT CMAKE_BUILD_TYPE)
  set(CMAKE_BUILD_TYPE Debug CACHE STRING
      "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." FORCE)
endif()

# Is this tool is compiled inside or outside CAMITK (as a standalone)?
if (NOT CAMITK_SOURCE_DIR)
  # if this tool is compiled independantly from CamiTK
  set(PML_STANDALONE ON CACHE BOOL "ON only if PML compiled outside CAMITK")
  message(SEND_ERROR "Compilation of PML outside CamiTK not implemented yet. Please contact authors")
endif()

# find xml2
find_package(Xml2 REQUIRED)

# Sets the variables for required include subdirectories :
set (PhysicalModelProperties_DIR ${PML_SOURCE_DIR}/PhysicalProperties)

link_directories(${CAMITK_LIB_DIRECTORIES})

set (PML_INCLUDE_DIRECTORIES
     ${CMAKE_CURRENT_SOURCE_DIR}
     ${PhysicalModelProperties_DIR}
     ${LIBXML2_INCLUDE_DIR}
)


set (PML_LIBRARIES
     pml
     ${LIBXML2_LIBRARIES}
)

set ( HEADERS
      Atom.h
      BasicAtomProperties.h
      Cell.h
      BasicCellProperties.h
      Component.h
      MultiComponent.h
      PhysicalModel.h
      ${PML_BINARY_DIR}/PhysicalModelVersion.h
      PhysicalModelIO.h
      Properties.h
      StructuralComponent.h
      BasicSCProperties.h
      Structure.h
      StructureProperties.h
      AbortException.h
      PMLTransform.h
      RenderingMode.h
      ${PhysicalModelProperties_DIR}/AtomProperties.h
      ${PhysicalModelProperties_DIR}/CellProperties.h
      ${PhysicalModelProperties_DIR}/StructuralComponentProperties.h
     )


set (SRCS Atom.cpp
    BasicAtomProperties.cpp
	  Cell.cpp
	  Component.cpp
	  BasicCellProperties.cpp
	  MultiComponent.cpp
	  PhysicalModel.cpp
	  StructuralComponent.cpp
	  Structure.cpp
	  StructureProperties.cpp
	  PMLTransform.cpp
	  ${PhysicalModelProperties_DIR}/AtomProperties.cpp
	  ${PhysicalModelProperties_DIR}/CellProperties.cpp
	  ${PhysicalModelProperties_DIR}/StructuralComponentProperties.cpp
	  Properties.cpp
	  ${HEADERS}
	 )

include_directories ( ${CMAKE_CURRENT_SOURCE_DIR}
		      ${CMAKE_CURRENT_BINARY_DIR}
		      ${PML_INCLUDE_DIRECTORIES}
)

add_library(pml STATIC ${SRCS}) # better use static libs for distributing executables

#-----------
# 64bits
#-----------
# this is needed on 64bits processor to avoid relocation R_X86_64_32 error
if( CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" )
  add_definitions(-fPIC)
endif( CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" )

#-----------
# testing
#-----------
add_subdirectory(test)

#-----------
# tools
#-----------
add_subdirectory(tools)

#--------------
# installation
#--------------
export_headers(${HEADERS} COMPONENT pml)

# lib installation
install(TARGETS pml
        ARCHIVE DESTINATION lib/${CAMITK_SHORT_VERSION_STRING}
        COMPONENT pml
)

#-------------------
# api documentation
#-------------------

option(APIDOC_GENERATE_FOR_PML "Build API documentation for PML" OFF)

if(APIDOC_GENERATE_FOR_PML)
  find_package(Doxygen REQUIRED)
  if (DOXYGEN)
      add_subdirectory(api-doc)
  else ()
      message(STATUS "WARNING: Doxygen not found - PML API documentation and reference manual will not be created")
  endif ()
endif()
