Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lestarch: allowing GTest to be disabled in UTs #1004

Merged
merged 1 commit into from
Sep 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion cmake/API.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -438,9 +438,16 @@ function(register_fprime_ut)
message(STATUS "No extra 'MOD_DEPS' found in '${CMAKE_CURRENT_LIST_FILE}'.")
endif()
endif()

# Turn allow turning GTest on/off
set(INCLUDE_GTEST ON)
if (DEFINED UT_INCLUDE_GTEST)
set(INCLUDE_GTEST ${UT_INCLUDE_GTEST})
endif()

get_nearest_build_root(${CMAKE_CURRENT_LIST_DIR})
# Explicit call to module register
generate_ut("${UT_NAME}" "${SC_IFS}" "${MD_IFS}")
generate_ut("${UT_NAME}" "${SC_IFS}" "${MD_IFS}" "${INCLUDE_GTEST}")
setup_all_module_targets(FPRIME_UT_TARGET_LIST ${MODULE_NAME} "" "${SOURCE_FILES}" "${AC_OUTPUTS}" "${MD_IFS}")
endfunction(register_fprime_ut)

Expand Down
26 changes: 17 additions & 9 deletions cmake/support/Unit_Test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ add_custom_target(check_leak
# - **EXE_NAME:** name of exe (unit test exe)
# - **SOURCE_FILES:** source files to provide for autocoding
####
function(unit_test_component_autocoder EXE_NAME SOURCE_FILES)
function(unit_test_component_autocoder EXE_NAME SOURCE_FILES INCLUDE_GTEST)
# Search for component xml files
foreach(TEST_SOURCE ${SOURCE_FILES})
string(REGEX MATCH "([./a-zA-Z0-9\-_]+)ComponentAi.xml" COMPONENT_XML ${TEST_SOURCE})
Expand Down Expand Up @@ -93,9 +93,15 @@ function(unit_test_component_autocoder EXE_NAME SOURCE_FILES)
target_sources(
${EXE_NAME}
PRIVATE
${GTEST_SOURCE}
${BASE_SOURCE}
)
if (INCLUDE_GTEST)
target_sources(
${EXE_NAME}
PRIVATE
${GTEST_SOURCE}
)
endif()
endif()
endforeach()
endfunction(unit_test_component_autocoder)
Expand All @@ -110,7 +116,7 @@ endfunction(unit_test_component_autocoder)
# - **UT_SOURCES_INPUT:** sources to split into source and autocoder file
# - **MOD_DEPS_INPUT:** dependencies split into thread and module dependencies
####
function(generate_ut UT_EXE_NAME UT_SOURCES_INPUT MOD_DEPS_INPUT)
function(generate_ut UT_EXE_NAME UT_SOURCES_INPUT MOD_DEPS_INPUT INCLUDE_GTEST)
# Set the following variables from the existing SOURCE_FILES and LINK_DEPS by splitting them into
# their separate pieces.
#
Expand All @@ -125,13 +131,15 @@ function(generate_ut UT_EXE_NAME UT_SOURCES_INPUT MOD_DEPS_INPUT)
endif()
generate_executable(${UT_EXE_NAME} "${SOURCE_FILES}" "${MOD_DEPS_INPUT}")
# Generate the UTs w/ autocoding and add the other sources
unit_test_component_autocoder(${UT_EXE_NAME} "${AUTOCODER_INPUT_FILES}")
unit_test_component_autocoder(${UT_EXE_NAME} "${AUTOCODER_INPUT_FILES}" ${INCLUDE_GTEST})
# Link modules
target_link_libraries(
"${UT_EXE_NAME}"
"gtest_main"
"-lpthread" #TODO: fix this
)
if (INCLUDE_GTEST)
target_link_libraries(
"${UT_EXE_NAME}"
"gtest_main"
"-lpthread" #TODO: fix this
)
endif()
# Add test and dependencies to the "check" target
add_test(NAME ${UT_EXE_NAME} COMMAND ${UT_EXE_NAME})
add_dependencies(check ${UT_EXE_NAME})
Expand Down