project(LML)

cmake_minimum_required(VERSION 2.6)

# Version (in CamiTK)
set(VERSION_STRING "lml - ${CAMITK_VERSION_STRING} (c) UJF-Grenoble 1, CNRS, TIMC-IMAG UMR 5525")
configure_file(${LML_SOURCE_DIR}/LoadsVersion.h.in ${LML_BINARY_DIR}/LoadsVersion.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(LML_STANDALONE ON CACHE BOOL "ON only if LML compiled outside CAMITK")
  message(FATAL_ERROR "Compilation of LML outside CamiTK not implemented yet. Please contact authors")
endif()

# find xml2
find_package(Xml2 REQUIRED)


set(LML_INCLUDE_DIRECTORIES
     ${CMAKE_CURRENT_SOURCE_DIR}
     ${LIBXML2_INCLUDE_DIR}
)

set(LML_LIBRARIES
     lml
     ${LIBXML2_LIBRARIES}
)

set( HEADERS 
      Direction.h 
      Force.h 
      ForceUnit.h 
      Load.h 
      Loads.h 
      ${LML_BINARY_DIR}/LoadsVersion.h
      Pressure.h 
      PressureUnit.h 
      Rotation.h 
      RotationUnit.h 
      TargetList.h 
      Translation.h 
      TranslationUnit.h 
      Unit.h 
      ValueEvent.h 
      XMLLoads.h 
    )

set( SRCS
      Force.cpp 
      ForceUnit.cpp 
      Load.cpp 
      Loads.cpp 
      PressureUnit.cpp 
      RotationUnit.cpp 
      TargetList.cpp 
      Translation.cpp 
      TranslationUnit.cpp 
      ValueEvent.cpp 
      XMLLoads.cpp 
      ${HEADERS}
    )

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

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

target_link_libraries(lml ${LML_LIBRARIES})

#-----------
# 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()

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

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

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

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

option(APIDOC_GENERATE_FOR_LML "Build API documentation for LML" OFF)

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


