Skip to content

Commit

Permalink
Added unit tests to cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
lexus2k committed Sep 20, 2020
1 parent 40c39f0 commit 78e0e2e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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}
Expand Down
32 changes: 32 additions & 0 deletions unittest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 78e0e2e

Please sign in to comment.