@@ -17,12 +17,12 @@ See the License for the specific language governing permissions and
1717limitations under the License.
1818]]
1919
20- #Add the 'BUILD_UNIT_TESTS' option
20+ #Add the 'BUILD_UNIT_TESTS' and 'INCLUDE_GTEST' options
2121OPTION (BUILD_UNIT_TESTS "Build unit tests applications" ON )
22+ OPTION (INCLUDE_GTEST "Download and include google test" OFF )
2223
2324SET (TESTS_EXTRA_TESTS_DIR "" CACHE STRING "Path to directory containing extra, out of tree tests (optional)" )
2425
25-
2626LIST_SUBDIRS(TEST_DIRS ${CMAKE_CURRENT_SOURCE_DIR} )
2727IF (NOT (TESTS_EXTRA_TESTS_DIR STREQUAL "" ))
2828 LIST_SUBDIRS(EXTRA_TESTS_DIRS ${TESTS_EXTRA_TESTS_DIR} )
@@ -37,6 +37,24 @@ FOREACH(__dir ${TEST_DIRS})
3737 UNSET (__upper_name)
3838ENDFOREACH ()
3939
40+ # Make google test available if INCLUDE_GTEST is set
41+ IF (INCLUDE_GTEST)
42+ # GoogleTest requires at least C++14
43+ set (CMAKE_CXX_STANDARD 14)
44+ set (CMAKE_CXX_STANDARD_REQUIRED ON )
45+
46+ include (FetchContent)
47+ FetchContent_Declare(
48+ googletest
49+ GIT_REPOSITORY https://github.com/google/googletest.git
50+ GIT_TAG release-1.12.1 # g++ 11
51+ )
52+ # For Windows: Prevent overriding the parent project's compiler/linker settings
53+ # set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
54+ FetchContent_MakeAvailable(googletest)
55+ ENDIF ()
56+
57+
4058#Finally Load the individual applications
4159FOREACH (__dir ${TEST_DIRS} )
4260 GET_FILENAME_COMPONENT (TEST_NAME ${__dir} NAME ) # strip full path keeping only test name
0 commit comments