# Create variable so that other source codes can find the include files
set(libtpcnlopt_HEADER_FILES "${CMAKE_CURRENT_SOURCE_DIR}" PARENT_SCOPE)

# This needs to be edited each time a new .c is added
add_library (tpcnlopt STATIC 
  nlopt.c constraints.c nlopt1d.c simplex.c praxis.c rndpoint.c mpso.c
  tgo.c
)
# Dependencies on other libraries
include_directories(
#  ${tpcnlopt_SOURCE_DIR}
  ${libtpcextensions_HEADER_FILES}
  ${libtpcrand_HEADER_FILES}
  ${libtpcstatist_HEADER_FILES}
)
target_link_libraries (
  tpcnlopt 
  tpcrand tpcstatist tpcextensions
  m
)

# Install the library and headers
install (
  TARGETS tpcnlopt
  ARCHIVE 
  DESTINATION ${LIBPATH}
  COMPONENT libraries
)
install (
  FILES tpcnlopt.h 
  DESTINATION ${LIBPATH}/include
  COMPONENT headers
)

# Compile executable for testing
add_executable (libtpcnlopt libtpcnlopt.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 (
  libtpcnlopt tpcnlopt 
  tpcrand tpcstatist tpcextensions 
  m
)

# Install the executable
#install (
#  PROGRAMS 
#  ${CMAKE_CURRENT_BINARY_DIR}/libtpcnlopt${CMAKE_EXECUTABLE_SUFFIX}
#  DESTINATION bin
#  COMPONENT librarytests
#)

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

# Run tests
add_test (
  NAME libtpcnloptTests
  WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/test
  COMMAND libtpcnlopt "--verbose" "--test"
)
