From 78e0e2e68d7692523e6d5ba82240dc47c7400bd0 Mon Sep 17 00:00:00 2001 From: Aleksei Dynda Date: Sun, 20 Sep 2020 18:58:47 +1000 Subject: [PATCH] Added unit tests to cmake --- CMakeLists.txt | 5 +++++ unittest/CMakeLists.txt | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 unittest/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index d4578492..afbfa490 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,7 @@ cmake_minimum_required (VERSION 3.5) option(EXAMPLES "Build examples and tiny_loopback" OFF) +option(UNITTEST "Build unit tests" OFF) file(GLOB_RECURSE SOURCE_FILES src/*.cpp src/*.c) file(GLOB_RECURSE HEADER_FILES src/*.h) @@ -19,6 +20,10 @@ if (NOT DEFINED COMPONENT_DIR) add_subdirectory(examples/linux/hdlc_demo_multithread) endif() + if (UNITTEST) + add_subdirectory(unittest) + endif() + else() idf_component_register(SRCS ${SOURCE_FILES} diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt new file mode 100644 index 00000000..963a41bf --- /dev/null +++ b/unittest/CMakeLists.txt @@ -0,0 +1,32 @@ +cmake_minimum_required (VERSION 3.5) + +file(GLOB_RECURSE SOURCE_FILES *.cpp *.c) + +if (NOT DEFINED COMPONENT_DIR) + + project (unit_test) + + add_executable(unit_test ${SOURCE_FILES}) + + target_link_libraries(unit_test tinyproto) + + find_package(Threads REQUIRED) + target_link_libraries(${PROJECT_NAME} Threads::Threads) + find_package(CppUTest QUIET) + if (NOT CppUTest_FOUND) + find_package(PkgConfig REQUIRED) + pkg_search_module(CPPUTEST cpputest REQUIRED) + target_link_libraries(${PROJECT_NAME} ${CPPUTEST_LIBRARIES}) + else() + target_link_libraries(${PROJECT_NAME} CppUTest::CppUTest) + endif() + + + add_custom_target(check unit_test) + +else() + + idf_component_register(SRCS ${SOURCE_FILES} + INCLUDE_DIRS ".") + +endif()