Debian Codegraph @

test/CMakeLists.txt

raw
1 # Unit tests only: Modern Boost integration (CMake 3.30+)
2 # Use CMake's built-in Boost support instead of deprecated FindBoost module
3 # For CMake < 3.30, keep old behavior to avoid errors
4 if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.30)
5 cmake_policy(SET CMP0167 NEW)
6 endif ()
7
8 # Make CMake respect variables like BOOST_ROOT even though we look for "Boost"
9 if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.27)
10 cmake_policy(SET CMP0144 NEW)
11 endif ()
12
13 # Find Boost unit test framework. We don't want to link that to libftdi1 itself.
14 find_package(Boost COMPONENTS unit_test_framework REQUIRED)
15
16 enable_testing()
17
18 # CMake 3.28 compatibility: include_directories only needed for CMake < 3.30
19 # (imported targets handle include paths automatically in CMake 3.30+)
20 if (CMAKE_VERSION VERSION_LESS 3.30)
21 INCLUDE_DIRECTORIES(BEFORE ${Boost_INCLUDE_DIRS})
22 endif ()
23
24 INCLUDE_DIRECTORIES(BEFORE ${PROJECT_SOURCE_DIR}/src)
25
26 set(cpp_tests basic.cpp baudrate.cpp)
27
28 add_executable(test_libftdi1 ${cpp_tests})
29
30 # Use modern imported targets for CMake 3.30+, fallback to old-style variables
31 if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.30)
32 target_link_libraries(test_libftdi1 ftdi1 Boost::unit_test_framework)
33 else ()
34 target_link_libraries(test_libftdi1 ftdi1 ${Boost_UNIT_TEST_FRAMEWORK_LIBRARIES})
35 endif ()
36
37 add_test(test_libftdi1 test_libftdi1)
38
39 # Add custom target so we run easily run "make check"
40 add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} DEPENDS test_libftdi1)