SET(LIBRARIES ChronoEngine ChronoEngine_fea)

SET(TESTS
    test_ANCFBeam
)

MESSAGE(STATUS "Unit test programs for FEA module...")

FOREACH(PROGRAM ${TESTS})
    MESSAGE(STATUS "...add ${PROGRAM}")

    ADD_EXECUTABLE(${PROGRAM}  "${PROGRAM}.cpp")
    SOURCE_GROUP(""  FILES "${PROGRAM}.cpp")

    SET_TARGET_PROPERTIES(${PROGRAM} PROPERTIES
        FOLDER demos
        COMPILE_FLAGS "${CH_CXX_FLAGS}"
        LINK_FLAGS "${CH_LINKERFLAG_EXE}"
    )

    TARGET_LINK_LIBRARIES(${PROGRAM} ${LIBRARIES})
    ADD_DEPENDENCIES(${PROGRAM} ${LIBRARIES})

    INSTALL(TARGETS ${PROGRAM} DESTINATION bin)
    ADD_TEST(${PROGRAM} ${PROJECT_BINARY_DIR}/bin/${PROGRAM})
ENDFOREACH(PROGRAM)
SET(LIBRARIES ChronoEngine ChronoEngine_fea)

SET(TESTS
    test_ANCFBeam
)

MESSAGE(STATUS "Unit test programs for FEA module...")

# A hack to set the working directory in which to execute the CTest
# runs.  This is needed for tests that need to access the Chrono data
# directory (since we use a relative path to it)
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
  set(MY_WORKING_DIR "${EXECUTABLE_OUTPUT_PATH}/$<CONFIGURATION>")
else()
  set(MY_WORKING_DIR ${EXECUTABLE_OUTPUT_PATH})
endif()

FOREACH(PROGRAM ${TESTS})
    MESSAGE(STATUS "...add ${PROGRAM}")

    ADD_EXECUTABLE(${PROGRAM}  "${PROGRAM}.cpp")
    SOURCE_GROUP(""  FILES "${PROGRAM}.cpp")

    SET_TARGET_PROPERTIES(${PROGRAM} PROPERTIES
        FOLDER demos
        COMPILE_FLAGS "${CH_CXX_FLAGS}"
        LINK_FLAGS "${CH_LINKERFLAG_EXE}"
    )

    TARGET_LINK_LIBRARIES(${PROGRAM} ${LIBRARIES})
    ADD_DEPENDENCIES(${PROGRAM} ${LIBRARIES})

    INSTALL(TARGETS ${PROGRAM} DESTINATION bin)

    ADD_TEST(NAME ${PROGRAM}
             COMMAND ${PROGRAM}
             WORKING_DIRECTORY ${MY_WORKING_DIR})
ENDFOREACH()

Fix for running unit tests that use the Chrono data directory.
Fix for running unit tests that use the Chrono data directory.

Because we use a relative path to the Chrono data directory, we must ensure that CTest executes the tests in the appropriate directory.  This requires specifying the WORKING_DIRECTORY test property.  However, matters are further complicated by the fact that VS places the executables in a subdirectory of ${EXECUTABLE_OUTPUT_PATH} (depending on the build configuration).
