Various fixes around Companion trainer mode (#7116)
[opentx.git] / radio / src / tests / CMakeLists.txt
blob20a3cfb60dcb92782834162066e1f517dd33e8eb
3 if(GTEST_INCDIR AND GTEST_SRCDIR AND Qt5Widgets_FOUND)
4   add_library(gtests-radio-lib STATIC EXCLUDE_FROM_ALL ${GTEST_SRCDIR}/src/gtest-all.cc )
5   target_include_directories(gtests-radio-lib PUBLIC ${GTEST_INCDIR} ${GTEST_INCDIR}/gtest ${GTEST_SRCDIR})
6   add_definitions(-DSIMU -DGTESTS)
7   remove_definitions(-DCLI)
8   set(TESTS_PATH ${RADIO_SRC_DIRECTORY}/tests)
9   set(TESTS_BUILD_PATH ${CMAKE_CURRENT_BINARY_DIR})
10   configure_file(${RADIO_SRC_DIRECTORY}/tests/location.h.in ${CMAKE_CURRENT_BINARY_DIR}/location.h @ONLY)
11   include_directories(${CMAKE_CURRENT_BINARY_DIR})
12   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS_DEBUG} -O0")
13   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_DEBUG} -O0 ${WARNING_FLAGS}")
14   use_cxx11()  # ensure gnu++11 in CXX_FLAGS with CMake < 3.1
16   if(PCB STREQUAL X12S OR PCB STREQUAL X10)
18     set(EXTRACT_MODEL_FILES model_22_x12s model_22_x10)
20     foreach(model_file ${EXTRACT_MODEL_FILES})
21       add_custom_command(
22         DEPENDS ${TESTS_PATH}/${model_file}.otx
23         OUTPUT ${TESTS_BUILD_PATH}/${model_file}/RADIO/radio.bin
24         COMMAND mkdir -p ${model_file} && cd ${model_file} && unzip -o -q -DD ${TESTS_PATH}/${model_file}.otx >/dev/null
25         WORKING_DIRECTORY ${TESTS_BUILD_PATH}
26       )
27       add_custom_target(${model_file}_files
28         DEPENDS ${TESTS_BUILD_PATH}/${model_file}/RADIO/radio.bin
29       )
30       set(HORUS_MODEL_FILES ${HORUS_MODEL_FILES} ${model_file}_files)
31     endforeach()
32   endif()
33   
34   if(WIN32)
35     target_include_directories(gtests-radio-lib PUBLIC ${WIN_INCLUDE_DIRS})
36     target_link_libraries(gtests-radio-lib PRIVATE ${WIN_LINK_LIBRARIES})
37   endif(WIN32)
39   if(SDL_FOUND AND SIMU_AUDIO)
40     target_include_directories(gtests-radio-lib PUBLIC ${SDL_INCLUDE_DIR})
41     target_link_libraries(gtests-radio-lib PRIVATE ${SDL_LIBRARY})
42   endif()
44   foreach(FILE ${SRC})
45     set(RADIO_SRC ${RADIO_SRC} ../${FILE})
46   endforeach()
48   file(GLOB TEST_SRC_FILES ${RADIO_SRC_DIRECTORY}/tests/*.cpp)
50   if(MINGW)
51     # struct packing breaks on MinGW w/out -mno-ms-bitfields: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52991 & http://stackoverflow.com/questions/24015852/struct-packing-and-alignment-with-mingw
52     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mno-ms-bitfields")
53   endif()
55   add_executable(gtests-radio EXCLUDE_FROM_ALL ${GTEST_SRC} ${TEST_SRC_FILES} ${CMAKE_CURRENT_SOURCE_DIR}/location.h ${RADIO_SRC} ../targets/simu/simpgmspace.cpp ../targets/simu/simueeprom.cpp ../targets/simu/simufatfs.cpp)
56   add_dependencies(gtests-radio ${RADIO_DEPENDENCIES} ${FIRMWARE_DEPENDENCIES} gtests-radio-lib)
57   if(PCB STREQUAL X12S OR PCB STREQUAL X10)
58     add_dependencies(gtests-radio ${HORUS_MODEL_FILES})
59   endif()
60   target_link_libraries(gtests-radio gtests-radio-lib pthread Qt5::Core Qt5::Widgets)
61   message(STATUS "Added optional gtests target")
62 else()
63   message(WARNING "WARNING: gtests target will not be available (check that GTEST_INCDIR, GTEST_SRCDIR, and Qt5Widgets are configured).")
64 endif()