Search code examples
c++testingcmakectest

Link more than one file to executable


How can I link more than one file(test) to an executable?

I have this code:

set(TEST_EXE_NAME Test)
add_executable(${TEST_EXE_NAME} t1.cc)
add_executable(${TEST_EXE_NAME} t2.cc)
add_test(Test ${TEST_EXE_NAME})

This of course doesn't compile and I understand why. But is there a way to put both tests into one executable?


Solution

  • Just repeat it.

    set(TEST_EXE_NAME Test)
    add_executable(${TEST_EXE_NAME} t1.cc)
    add_test(Test ${TEST_EXE_NAME})
    set(TEST_EXE_NAME Test1)
    add_executable(${TEST_EXE_NAME} t2.cc)
    add_test(Test1 ${TEST_EXE_NAME})
    

    Since you're testing this way the names can be more descriptive for each executable anyway.