Merge pull request #10285 from flywoo/master
[inav.git] / src / test / unit / CMakeLists.txt
blob300721b8f532e59ad99d98079be72d9d794f2305
1 # XXX: This should come from main project once everything
2 # uses cmake
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"
15     "sensors/gyro.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 set_property(SOURCE osd_unittest.cc PROPERTY depends "io/osd_utils.c" "io/displayport_msp_osd.c" "common/typeconversion.c")
38 set_property(SOURCE osd_unittest.cc PROPERTY definitions OSD_UNIT_TEST USE_MSP_DISPLAYPORT DISABLE_MSP_BF_COMPAT)
40 set_property(SOURCE gps_ublox_unittest.cc PROPERTY depends "io/gps_ublox_utils.c")
41 set_property(SOURCE gps_ublox_unittest.cc PROPERTY definitions GPS_UBLOX_UNIT_TEST)
43 set_property(SOURCE gimbal_serial_unittest.cc PROPERTY depends "io/gimbal_serial.c" "drivers/gimbal_common.c" "common/maths.c")
44 set_property(SOURCE gimbal_serial_unittest.cc PROPERTY definitions USE_SERIAL_GIMBAL GIMBAL_UNIT_TEST)
46 function(unit_test src)
47     get_filename_component(basename ${src} NAME)
48     string(REPLACE ".cc" "" name ${basename} )
49     get_property(deps SOURCE ${src} PROPERTY depends)
50     set(headers "${deps}")
51     list(TRANSFORM headers REPLACE "\.c$" ".h")
52     list(APPEND deps ${headers})
53     get_property(defs SOURCE ${src} PROPERTY definitions)
54     set(test_definitions "UNIT_TEST")
55     if (defs)
56         list(APPEND test_definitions ${defs})
57     endif()
58     list(TRANSFORM deps PREPEND "${MAIN_DIR}/")
59     add_executable(${name} ${src} ${deps})
60     set(gen_name ${name}_gen)
61     get_generated_files_dir(gen ${gen_name})
62     target_include_directories(${name} PRIVATE . ${MAIN_DIR} ${gen})
63     target_compile_definitions(${name} PRIVATE ${test_definitions})
64     target_compile_options(${name} PRIVATE -pthread -Wall -Wextra -Wno-extern-c-compat -ggdb3 -O0)
65     enable_settings(${name} ${gen_name} OUTPUTS setting_files SETTINGS_CXX g++)
66     target_sources(${name} PRIVATE ${setting_files})
67     target_link_libraries(${name} gtest_main)
68     gtest_discover_tests(${name})
69     add_custom_target("run-${name}" "${name}" DEPENDS ${name})
70     set(test_targets ${test_targets} "${name}" PARENT_SCOPE)
71 endfunction()
73 file(GLOB TEST_PROGRAMS *_unittest.cc)
74 foreach(source ${TEST_PROGRAMS})
75     unit_test(${source})
76 endforeach()
78 add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} DEPENDS ${test_targets})