px4_add_gtest.cmake: add optional COMPILE_FLAGS, INCLUDES, EXTRA_SRCS and LINKLIBS

This commit is contained in:
Beat Küng 2021-12-09 12:55:55 +01:00 committed by Daniel Agar
parent 87ec8839c4
commit 10f49c99ef
1 changed files with 20 additions and 4 deletions

View File

@ -44,7 +44,7 @@ function(px4_add_unit_gtest)
px4_parse_function_args(
NAME px4_add_unit_gtest
ONE_VALUE SRC
MULTI_VALUE LINKLIBS
MULTI_VALUE EXTRA_SRCS COMPILE_FLAGS INCLUDES LINKLIBS
REQUIRED SRC
ARGN ${ARGN})
@ -54,11 +54,19 @@ function(px4_add_unit_gtest)
set(TESTNAME unit-${TESTNAME})
# build a binary for the unit test
add_executable(${TESTNAME} EXCLUDE_FROM_ALL ${SRC})
add_executable(${TESTNAME} EXCLUDE_FROM_ALL ${SRC} ${EXTRA_SRCS})
# link the libary to test and gtest
target_link_libraries(${TESTNAME} ${LINKLIBS} gtest_main)
if(COMPILE_FLAGS)
target_compile_options(${TESTNAME} PRIVATE ${COMPILE_FLAGS})
endif()
if(INCLUDES)
target_include_directories(${TESTNAME} PRIVATE ${INCLUDES})
endif()
# add the test to the ctest plan
add_test(NAME ${TESTNAME}
COMMAND ${TESTNAME}
@ -76,7 +84,7 @@ function(px4_add_functional_gtest)
px4_parse_function_args(
NAME px4_add_functional_gtest
ONE_VALUE SRC
MULTI_VALUE LINKLIBS
MULTI_VALUE EXTRA_SRCS COMPILE_FLAGS INCLUDES LINKLIBS
REQUIRED SRC
ARGN ${ARGN})
@ -86,7 +94,7 @@ function(px4_add_functional_gtest)
set(TESTNAME functional-${TESTNAME})
# build a binary for the unit test
add_executable(${TESTNAME} EXCLUDE_FROM_ALL ${SRC})
add_executable(${TESTNAME} EXCLUDE_FROM_ALL ${SRC} ${EXTRA_SRCS})
# link the libary to test and gtest
target_link_libraries(${TESTNAME} ${LINKLIBS} gtest_functional_main
@ -104,6 +112,14 @@ function(px4_add_functional_gtest)
uorb_msgs
test_stubs) #put test_stubs last
if(COMPILE_FLAGS)
target_compile_options(${TESTNAME} PRIVATE ${COMPILE_FLAGS})
endif()
if(INCLUDES)
target_include_directories(${TESTNAME} PRIVATE ${INCLUDES})
endif()
# add the test to the ctest plan
add_test(NAME ${TESTNAME}
# functional tests need to run in a new process for each test,