From 10f49c99ef7cd4f40adf1ef056cec2c952550433 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Thu, 9 Dec 2021 12:55:55 +0100 Subject: [PATCH] px4_add_gtest.cmake: add optional COMPILE_FLAGS, INCLUDES, EXTRA_SRCS and LINKLIBS --- cmake/gtest/px4_add_gtest.cmake | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/cmake/gtest/px4_add_gtest.cmake b/cmake/gtest/px4_add_gtest.cmake index 5560fca062..1a54456194 100644 --- a/cmake/gtest/px4_add_gtest.cmake +++ b/cmake/gtest/px4_add_gtest.cmake @@ -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,