#
# Current informations:
# Version 1.0B released on May, 2005.
# Download site : http://6s.ltdri.org/
#

set(OTB3P_INSTALL_EXPORT_NAME "${OTB6S-targets}")
set(OTB3P_INSTALL_INCLUDE_DIR "${OTB6S_INSTALL_INCLUDE_DIR}")
set(OTB3P_INSTALL_RUNTIME_DIR "${OTB6S_INSTALL_RUNTIME_DIR}")
set(OTB3P_INSTALL_LIBRARY_DIR "${OTB6S_INSTALL_LIBRARY_DIR}")
set(OTB3P_INSTALL_ARCHIVE_DIR "${OTB6S_INSTALL_ARCHIVE_DIR}")

# Inform header files they are being included from a source inside the
# otb_6S library.
add_definitions(-DOTB_6S_SRC)
add_definitions(-DNON_POSIX_STDIO)

# On Microsoft Visual
if(WIN32)
  if(NOT BORLAND)
    if(NOT CYGWIN)
      if(NOT MINGW)
#        if(NOT ITK_ENABLE_VISUAL_STUDIO_DEPRECATED_C_WARNINGS)
          add_definitions(
            -DUSE_CLOCK
            -DMSDOS
            -DNO_ONEXIT
            )
#        endif()
      else()
          add_definitions(
            -DUSE_CLOCK
            -DMSDOS
            -DNO_TRUNCATE  #For generate endfile.c
            )
      endif()
    endif()
  endif()
endif()


file(GLOB OTB6S_SRCS "6SV1.0B/*.c" )
file(GLOB LIBF2C_SRCS "libf2c/*.c" )
list(REMOVE_ITEM LIBF2C_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/libf2c/arithchk.c" )
list(REMOVE_ITEM LIBF2C_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/libf2c/main.c" )
list(REMOVE_ITEM LIBF2C_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/libf2c/getarg_.c" )
list(REMOVE_ITEM LIBF2C_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/libf2c/iargc_.c" )

# Main code source
set(OTB6S_MAIN_SRCS
  otb_main6S_function.c                # otb 6S main function
  main.c                               # ORIGINAL 6S main
  otb_main6S_program_call_function.c   # OTB 6S main (which call otb_main6S_function function)
  aeroprof_com.c                       # others *.c fils generated by f2c
  multorder_com.c
  sixs_del__com.c
  sixs_ier__com.c
  num_quad__com.c
  sixs_aer__com.c
  sixs_disc__com.c
  sixs_planesim__com.c
  mie_in__com.c
  sixs_atm__com.c
  sixs_ffu__com.c
  sixs_test__com.c
  )

add_library(otb6S ${LIBF2C_SRCS} ${OTB6S_SRCS} ${OTB6S_MAIN_SRCS})
if(UNIX)
    target_link_libraries(otb6S m)
endif()
if(OTB_LIBRARY_PROPERTIES)
  set_target_properties(otb6S PROPERTIES ${OTB_LIBRARY_PROPERTIES})
endif()

install(TARGETS otb6S
  EXPORT ${OTB3P_INSTALL_EXPORT_NAME}
  RUNTIME DESTINATION ${OTB3P_INSTALL_RUNTIME_DIR} COMPONENT RuntimeLibraries
  LIBRARY DESTINATION ${OTB3P_INSTALL_LIBRARY_DIR} COMPONENT RuntimeLibraries
  ARCHIVE DESTINATION ${OTB3P_INSTALL_ARCHIVE_DIR} COMPONENT Development
  )

otb_module_target( otb6S NO_INSTALL )
