Skip to content

Commit

Permalink
add google test support
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsheirman committed Nov 7, 2024
1 parent 655c103 commit e83fc7c
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions stack/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ See the License for the specific language governing permissions and
limitations under the License.
]]

#Add the 'BUILD_UNIT_TESTS' option
#Add the 'BUILD_UNIT_TESTS' and 'INCLUDE_GTEST' options
OPTION(BUILD_UNIT_TESTS "Build unit tests applications" ON)
OPTION(INCLUDE_GTEST "Download and include google test" OFF)

SET(TESTS_EXTRA_TESTS_DIR "" CACHE STRING "Path to directory containing extra, out of tree tests (optional)")


LIST_SUBDIRS(TEST_DIRS ${CMAKE_CURRENT_SOURCE_DIR})
IF(NOT(TESTS_EXTRA_TESTS_DIR STREQUAL ""))
LIST_SUBDIRS(EXTRA_TESTS_DIRS ${TESTS_EXTRA_TESTS_DIR})
Expand All @@ -37,6 +37,24 @@ FOREACH(__dir ${TEST_DIRS})
UNSET(__upper_name)
ENDFOREACH()

# Make google test available if INCLUDE_GTEST is set
IF(INCLUDE_GTEST)
# GoogleTest requires at least C++14
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.12.1 # g++ 11
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
# set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
ENDIF()


#Finally Load the individual applications
FOREACH(__dir ${TEST_DIRS})
GET_FILENAME_COMPONENT(TEST_NAME ${__dir} NAME) # strip full path keeping only test name
Expand Down

0 comments on commit e83fc7c

Please sign in to comment.