# Static library
#


# Utils
add_library (
    nomadStatic 
    STATIC
    ${MATH_SOURCES} ${OUTPUT_SOURCES}
    ${PARAM_SOURCES} ${TYPE_SOURCES}
    ${UTIL_SOURCES} ${ATTRIBUTE_HEADERS}
    ${CACHE_SOURCES} ${EVAL_SOURCES}
    ${ALGOS_SOURCES} ${CS_SOURCES} 
    ${DMULTIMADS_SOURCES} ${DISCOMADS_SOURCES} 
    ${MADS_SOURCES} ${MADSLOGBARRIER_SOURCES} ${SIMPLE_MADS_SOURCES} ${LH_SOURCES}
    ${NM_SOURCES} ${PHASEONE_SOURCES} 
    ${PSDMADS_SOURCES} ${COOPMADS_SOURCES} 
    ${QPSOLVER_SOURCES} ${SSDMADS_SOURCES} 
    ${TEMPLATE_ALGO_SOURCES} ${SIMPLELINESEARCH_ALGO_SOURCES} 
    ${VNSMADS_SOURCES}


)

target_include_directories(
    nomadStatic 
    PUBLIC
    $<BUILD_INTERFACE: 
      ${CMAKE_SOURCE_DIR}/src/Attribute
      ${CMAKE_SOURCE_DIR}/src/Math
      ${CMAKE_SOURCE_DIR}/src/Output
      ${CMAKE_SOURCE_DIR}/src/Param
      ${CMAKE_SOURCE_DIR}/src/Type
      ${CMAKE_SOURCE_DIR}/src/Util

      ${CMAKE_CURRENT_SOURCE_DIR}/Cache
      ${CMAKE_CURRENT_SOURCE_DIR}/Eval

      ${CMAKE_CURRENT_SOURCE_DIR}/Algos
      ${CMAKE_CURRENT_SOURCE_DIR}/Algos/COOPMads
      ${CMAKE_CURRENT_SOURCE_DIR}/Algos/CoordinateSearch
      ${CMAKE_CURRENT_SOURCE_DIR}/Algos/DMultiMads
      ${CMAKE_CURRENT_SOURCE_DIR}/Algos/DiscoMads
      ${CMAKE_CURRENT_SOURCE_DIR}/Algos/LatinHypercubeSampling
      ${CMAKE_CURRENT_SOURCE_DIR}/Algos/Mads
      ${CMAKE_CURRENT_SOURCE_DIR}/Algos/SimpleMads
      ${CMAKE_CURRENT_SOURCE_DIR}/Algos/NelderMead
      ${CMAKE_CURRENT_SOURCE_DIR}/Algos/PhaseOne
      ${CMAKE_CURRENT_SOURCE_DIR}/Algos/PSDMads
      ${CMAKE_CURRENT_SOURCE_DIR}/Algos/QPSolverAlgo
      ${CMAKE_CURRENT_SOURCE_DIR}/Algos/SSDMads
      ${CMAKE_CURRENT_SOURCE_DIR}/Algos/TemplateAlgo
      ${CMAKE_CURRENT_SOURCE_DIR}/Algos/SimpleLineSearch
      ${CMAKE_CURRENT_SOURCE_DIR}/Algos/VNSMads
    >
    $<INSTALL_INTERFACE: 
     ${CMAKE_INSTALL_INCLUDEDIR}
    >
)

if(USE_SGTELIB MATCHES ON)
  target_sources(
    nomadStatic
    PRIVATE
      ${QUADMODEL_SOURCES}
      ${QUADMODELSLD_SOURCES} 
      ${SGTELIBMODEL_SOURCES} 
  )

  target_include_directories(
    nomadStatic
    PUBLIC
      $<BUILD_INTERFACE: 
        ${CMAKE_CURRENT_SOURCE_DIR}/Algos/QuadModel
        ${CMAKE_CURRENT_SOURCE_DIR}/Algos/QuadModelSLD
        ${CMAKE_CURRENT_SOURCE_DIR}/Algos/SgtelibModel
      >
  )

  target_link_libraries(
    nomadStatic
    PUBLIC 
      sgtelibStatic
  )
else()
  target_include_directories(
    nomadStatic
    PUBLIC
      $<BUILD_INTERFACE: 
        $ENV{IBEX_ROOT}/src
      >
  )
endif()

if(OpenMP_CXX_FOUND)
    target_link_libraries(
      nomadStatic 
      PUBLIC
        OpenMP::OpenMP_CXX
    )
endif()

if(USE_IBEX MATCHES ON)
  target_link_libraries(
    nomadStatic
    PUBLIC ibex
  )

   add_library(
     ibex 
     SHARED IMPORTED
   )

   set_target_properties(
     ibex
     PROPERTIES
       IMPORTED_LOCATION
         $ENV{IBEX_ROOT}/lib/libibex.so
   )

   target_include_directories(
     ibex
     INTERFACE
       "$ENV{IBEX_ROOT}/__build__"
	 "$ENV{IBEX_ROOT}/include/ibex"
       "$ENV{IBEX_ROOT}/include/ibex/3rd"
   )

   message(CHECK_START " Ready to use IBEX")
endif()



set_target_properties(
    nomadStatic 
    PROPERTIES
       VERSION "${NOMAD_VERSION}"
       SOVERSION "${NOMAD_VERSION_MAJOR}.${NOMAD_VERSION_MINOR}"
       OUTPUT_NAME nomadStatic
)

if (WIN32)
    target_compile_definitions(
      nomadStatic
      PRIVATE 
        -DNOMAD_STATIC_BUILD
    )
endif()




#
# Install the library
#

# installing executables and libraries
install(
  TARGETS
    nomadStatic
  LIBRARY 
    DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

