Skip to content
This repository was archived by the owner on Jan 7, 2025. It is now read-only.

Commit e83fc7c

Browse files
committed
add google test support
1 parent 655c103 commit e83fc7c

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

stack/tests/CMakeLists.txt

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ See the License for the specific language governing permissions and
1717
limitations under the License.
1818
]]
1919

20-
#Add the 'BUILD_UNIT_TESTS' option
20+
#Add the 'BUILD_UNIT_TESTS' and 'INCLUDE_GTEST' options
2121
OPTION(BUILD_UNIT_TESTS "Build unit tests applications" ON)
22+
OPTION(INCLUDE_GTEST "Download and include google test" OFF)
2223

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

25-
2626
LIST_SUBDIRS(TEST_DIRS ${CMAKE_CURRENT_SOURCE_DIR})
2727
IF(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)
3838
ENDFOREACH()
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
4159
FOREACH(__dir ${TEST_DIRS})
4260
GET_FILENAME_COMPONENT(TEST_NAME ${__dir} NAME) # strip full path keeping only test name

0 commit comments

Comments
 (0)