1 # XXX: This should come from main project once everything
3 set(MAIN_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../src/main")
5 # Keep these alphabetically sorted by test name
7 set_property(SOURCE alignsensor_unittest.cc PROPERTY depends
8 "common/maths.c" "sensors/boardalignment.c")
10 set_property(SOURCE bitarray_unittest.cc PROPERTY depends "common/bitarray.c")
12 set_property(SOURCE flight_imu_unittest.cc PROPERTY depends "build/debug.c"
13 "common/maths.c" "common/calibration.c" "common/filter.c"
14 "drivers/accgyro/accgyro_fake.c" "flight/imu.c" "sensors/boardalignment.c"
17 set_property(SOURCE maths_unittest.cc PROPERTY depends "common/maths.c")
19 set_property(SOURCE olc_unittest.cc PROPERTY depends "common/olc.c")
21 set_property(SOURCE rcdevice_unittest.cc PROPERTY definitions USE_RCDEVICE)
22 set_property(SOURCE rcdevice_unittest.cc PROPERTY depends
23 "common/bitarray.c" "common/crc.c" "io/rcdevice.c" "io/rcdevice_cam.c"
24 "fc/rc_modes.c" "common/maths.c")
26 set_property(SOURCE sensor_gyro_unittest.cc PROPERTY depends
27 "build/debug.c" "common/maths.c" "common/calibration.c" "common/filter.c"
28 "drivers/accgyro/accgyro_fake.c" "sensors/gyro.c" "sensors/boardalignment.c")
30 set_property(SOURCE telemetry_hott_unittest.cc PROPERTY depends
31 "telemetry/hott.c" "common/gps_conversion.c" "common/string_light.c")
33 set_property(SOURCE time_unittest.cc PROPERTY depends "drivers/time.c")
35 set_property(SOURCE circular_queue_unittest.cc PROPERTY depends "common/circular_queue.c")
37 function(unit_test src)
38 get_filename_component(basename ${src} NAME)
39 string(REPLACE ".cc" "" name ${basename} )
40 get_property(deps SOURCE ${src} PROPERTY depends)
41 set(headers "${deps}")
42 list(TRANSFORM headers REPLACE "\.c$" ".h")
43 list(APPEND deps ${headers})
44 get_property(defs SOURCE ${src} PROPERTY definitions)
45 set(test_definitions "UNIT_TEST")
47 list(APPEND test_definitions ${defs})
49 list(TRANSFORM deps PREPEND "${MAIN_DIR}/")
50 add_executable(${name} ${src} ${deps})
51 set(gen_name ${name}_gen)
52 get_generated_files_dir(gen ${gen_name})
53 target_include_directories(${name} PRIVATE . ${MAIN_DIR} ${gen})
54 target_compile_definitions(${name} PRIVATE ${test_definitions})
55 target_compile_options(${name} PRIVATE -pthread -Wall -Wextra -Wno-extern-c-compat -ggdb3 -O0)
56 enable_settings(${name} ${gen_name} OUTPUTS setting_files SETTINGS_CXX g++)
57 target_sources(${name} PRIVATE ${setting_files})
58 target_link_libraries(${name} gtest_main)
59 gtest_discover_tests(${name})
60 add_custom_target("run-${name}" "${name}" DEPENDS ${name})
61 set(test_targets ${test_targets} "${name}" PARENT_SCOPE)
64 file(GLOB TEST_PROGRAMS *_unittest.cc)
65 foreach(source ${TEST_PROGRAMS})
69 add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} DEPENDS ${test_targets})