##
## This file is part of haec_sim (https://tu-dresden.de/zih/haec_sim)
## haec_sim - A trace-based parallel discrete event simulation framework
##
## Copyright (c) 2013-2015 Technische Universitaet Dresden, Germany
##
## haec_sim is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## haec_sim is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with haec_sim.  If not, see <http://www.gnu.org/licenses/>.
##

include_directories(${OTF2_INCLUDE_DIRS})
link_directories(${OTF2_LINK_DIRS})

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenTraceFormat_CXX_FLAGS} -std=c++11")

FILE(GLOB MPI_TESTS mpi_*_test.c*)
FILE(GLOB TESTS *_test.c*)

foreach(TEST ${MPI_TESTS})

    # remove mpi tests from list of test files
    list(REMOVE_ITEM TESTS ${TEST})

    get_filename_component(TEST_NAME ${TEST} NAME_WE)

    add_executable(${TEST_NAME} ${TEST})
    target_link_libraries(${TEST_NAME} ${OTF2_LIBRARIES} )
    target_link_libraries(${TEST_NAME} ${Boost_LIBRARIES})
    target_link_mpi(${TEST_NAME})

    add_test(NAME ${TEST_NAME} COMMAND ${MPIEXEC} ${MPIEXEC_PREFLAGS} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_POSTFLAGS} ${CMAKE_CURRENT_BINARY_DIR}/${TEST_NAME})

    set_target_properties(${TEST_NAME} PROPERTIES FOLDER "tests")

endforeach()

# special case
list(REMOVE_ITEM TESTS ${CMAKE_CURRENT_SOURCE_DIR}/nitro_dl_test.cpp)

foreach(TEST ${TESTS})

    get_filename_component(TEST_NAME ${TEST} NAME_WE)

    add_executable(${TEST_NAME} ${TEST})
    target_link_libraries(${TEST_NAME} ${OTF2_LIBRARIES})
    target_link_libraries(${TEST_NAME} ${Boost_LIBRARIES})

    # add mpi stuff
    target_link_libraries(${TEST_NAME} ${MPI_LIBRARIES})
    if(MPI_COMPILE_FLAGS)
    set_target_properties(${TEST_NAME} PROPERTIES
        COMPILE_FLAGS "${MPI_COMPILE_FLAGS}")
    endif()
    if(MPI_LINK_FLAGS)
    set_target_properties(${TEST_NAME} PROPERTIES
        LINK_FLAGS "${MPI_LINK_FLAGS}")
    endif()


    add_test(${TEST_NAME} ${TEST_NAME})

    set_target_properties(${TEST_NAME} PROPERTIES FOLDER "tests")

endforeach()

# <--- special case for nitro_dl_test.cpp
# build test and link with -ldl
add_executable(nitro_dl_test nitro_dl_test.cpp)
target_link_libraries(nitro_dl_test dl)
# run test with custom LD_LIBRARY_PATH
add_test(nitro_dl_test nitro_dl_test)

set_target_properties(nitro_dl_test PROPERTIES FOLDER "tests")
# --->

#add_executable(test_runner test_runner.cpp)
#install(TARGETS haec_sim DESTINATION bin)

add_subdirectory(reference_traces)
