# Set the name of library
set(libname "tpcnlopt")

# This needs to be edited each time a new .c is added
add_library (${libname} STATIC 
  nlopt.c constraints.c nlopt1d.c simplex.c praxis.c rndpoint.c mpso.c
  tgo.c
)
# Dependencies on other libraries
include_directories(
  ${CMAKE_SOURCE_DIR}/v2/libtpcextensions
  ${CMAKE_SOURCE_DIR}/v2/libtpcrand
  ${CMAKE_SOURCE_DIR}/v2/libtpcstatist
)
target_link_libraries (
  ${libname} 
  tpcrand tpcstatist tpcextensions
  m
)

# Install the library and headers
install (
  TARGETS ${libname}
  ARCHIVE 
  DESTINATION ${LIBPATH}
  COMPONENT libraries
)

install (
  FILES ${libname}.h 
  DESTINATION ${LIBPATH}/include
  COMPONENT headers
)

# Compile executable for testing
add_executable (lib${libname} lib${libname}.c 
  test_nlopt.c test_constraints.c 
  test_nlopt1d.c test_simplex.c test_praxis.c test_rndpoint.c test_mpso.c
  test_tgo.c
) 
# Link the executable to the libraries. 
target_link_libraries (
  lib${libname} ${libname} 
  tpcrand tpcstatist tpcextensions 
  m
)

# Copy test data folder
file(COPY test DESTINATION ${CMAKE_CURRENT_BINARY_DIR} )

# Run tests
add_test (
  NAME lib${libname}Tests
  WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/test
  COMMAND lib${libname} "--verbose" "--test"
)
