Boost-Unit-Test-Programm mit CMake kompilieren

English Deutsch

Dies zur CMakeLists.txt hinzufügen:

CMakeLists.txt
#
# Compile test suite
#
find_package(Boost COMPONENTS system filesystem unit_test_framework REQUIRED)

add_executable(test_myprogram
    tests/MyTest.cpp
)
target_include_directories(test_myprogram PUBLIC "${CMAKE_CURRENT_LIST_DIR}/include")
target_compile_features(test_myprogram PRIVATE cxx_std_17)

target_link_libraries(test_myprogram
                      ${Boost_FILESYSTEM_LIBRARY}
                      ${Boost_SYSTEM_LIBRARY}
                      ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}
                      )
add_test(test_myprogram test_myprogram)
# make "make test" run the test program
add_custom_target(test
     DEPENDS myprogram
     COMMAND ./test_myprogram
)

Um das Programm und den Test zu bauen, ausführen

build_make.sh
make

Um die Tests auszuführen, verwenden

run_tests.sh
make test

Check out similar posts by category: Boost, C/C++, CMake