2010-05-13 18:19:26 +00:00
|
|
|
########################################################################
|
2019-05-19 23:29:18 -07:00
|
|
|
# Note: CMake support is community-based. The maintainers do not use CMake
|
2019-04-29 17:18:42 -04:00
|
|
|
# internally.
|
|
|
|
#
|
2010-10-05 19:24:04 +00:00
|
|
|
# CMake build script for Google Mock.
|
2010-05-13 18:19:26 +00:00
|
|
|
#
|
|
|
|
# To run the tests for Google Mock itself on Linux, use 'make test' or
|
2023-09-29 17:26:23 +03:00
|
|
|
# ctest. You can select which tests to run using 'ctest -R regex'.
|
2010-05-13 18:19:26 +00:00
|
|
|
# For more options, run 'ctest --help'.
|
|
|
|
|
|
|
|
option(gmock_build_tests "Build all of Google Mock's own tests." OFF)
|
|
|
|
|
|
|
|
# A directory to find Google Test sources.
|
2010-05-20 22:17:28 +00:00
|
|
|
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/gtest/CMakeLists.txt")
|
2010-05-13 18:19:26 +00:00
|
|
|
set(gtest_dir gtest)
|
|
|
|
else()
|
2015-08-26 21:50:38 -07:00
|
|
|
set(gtest_dir ../googletest)
|
2010-05-13 18:19:26 +00:00
|
|
|
endif()
|
|
|
|
|
2010-10-05 19:24:04 +00:00
|
|
|
# Defines pre_project_set_up_hermetic_build() and set_up_hermetic_build().
|
2010-05-13 18:19:26 +00:00
|
|
|
include("${gtest_dir}/cmake/hermetic_build.cmake" OPTIONAL)
|
|
|
|
|
|
|
|
if (COMMAND pre_project_set_up_hermetic_build)
|
|
|
|
# Google Test also calls hermetic setup functions from add_subdirectory,
|
|
|
|
# although its changes will not affect things at the current scope.
|
|
|
|
pre_project_set_up_hermetic_build()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
########################################################################
|
|
|
|
#
|
|
|
|
# Project-wide settings
|
|
|
|
|
|
|
|
# Name of the project.
|
|
|
|
#
|
|
|
|
# CMake files in this project can refer to the root source directory
|
|
|
|
# as ${gmock_SOURCE_DIR} and to the root binary directory as
|
|
|
|
# ${gmock_BINARY_DIR}.
|
|
|
|
# Language "C" is required for find_package(Threads).
|
2023-06-20 08:20:43 -07:00
|
|
|
cmake_minimum_required(VERSION 3.13)
|
2021-08-20 17:47:35 -04:00
|
|
|
project(gmock VERSION ${GOOGLETEST_VERSION} LANGUAGES CXX C)
|
2010-05-13 18:19:26 +00:00
|
|
|
|
|
|
|
if (COMMAND set_up_hermetic_build)
|
|
|
|
set_up_hermetic_build()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Instructs CMake to process Google Test's CMakeLists.txt and add its
|
2023-09-29 17:26:23 +03:00
|
|
|
# targets to the current scope. We are placing Google Test's binary
|
2010-10-05 19:24:04 +00:00
|
|
|
# directory in a subdirectory of our own as VC compilation may break
|
|
|
|
# if they are the same (the default).
|
2019-03-04 12:40:12 -08:00
|
|
|
add_subdirectory("${gtest_dir}" "${gmock_BINARY_DIR}/${gtest_dir}")
|
2010-05-13 18:19:26 +00:00
|
|
|
|
2018-04-05 13:38:33 +02:00
|
|
|
|
|
|
|
# These commands only run if this is the main project
|
|
|
|
if(CMAKE_PROJECT_NAME STREQUAL "gmock" OR CMAKE_PROJECT_NAME STREQUAL "googletest-distribution")
|
|
|
|
# BUILD_SHARED_LIBS is a standard CMake variable, but we declare it here to
|
|
|
|
# make it prominent in the GUI.
|
|
|
|
option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)." OFF)
|
|
|
|
else()
|
|
|
|
mark_as_advanced(gmock_build_tests)
|
|
|
|
endif()
|
|
|
|
|
2010-10-05 19:24:04 +00:00
|
|
|
# Although Google Test's CMakeLists.txt calls this function, the
|
2023-09-29 17:26:23 +03:00
|
|
|
# changes there don't affect the current scope. Therefore we have to
|
2010-10-05 19:24:04 +00:00
|
|
|
# call it again here.
|
2023-09-29 17:26:23 +03:00
|
|
|
config_compiler_and_linker() # from ${gtest_dir}/cmake/internal_utils.cmake
|
2010-10-05 19:24:04 +00:00
|
|
|
|
2010-05-13 18:19:26 +00:00
|
|
|
# Adds Google Mock's and Google Test's header directories to the search path.
|
2024-02-11 02:36:02 +01:00
|
|
|
# Get Google Test's include dirs from the target, gtest_SOURCE_DIR is broken
|
|
|
|
# when using fetch-content with the name "GTest".
|
|
|
|
get_target_property(gtest_include_dirs gtest INCLUDE_DIRECTORIES)
|
2017-12-01 12:48:46 +01:00
|
|
|
set(gmock_build_include_dirs
|
|
|
|
"${gmock_SOURCE_DIR}/include"
|
|
|
|
"${gmock_SOURCE_DIR}"
|
2024-02-11 02:36:02 +01:00
|
|
|
"${gtest_include_dirs}")
|
2017-12-01 12:48:46 +01:00
|
|
|
include_directories(${gmock_build_include_dirs})
|
2010-05-13 18:19:26 +00:00
|
|
|
|
|
|
|
########################################################################
|
|
|
|
#
|
2023-09-29 17:26:23 +03:00
|
|
|
# Defines the gmock & gmock_main libraries. User tests should link
|
2010-05-13 18:19:26 +00:00
|
|
|
# with one of them.
|
|
|
|
|
2023-09-29 17:26:23 +03:00
|
|
|
# Google Mock libraries. We build them using more strict warnings than what
|
2010-05-13 18:19:26 +00:00
|
|
|
# are used for other targets, to ensure that Google Mock can be compiled by
|
|
|
|
# a user aggressive about warnings.
|
2017-12-02 22:47:20 +01:00
|
|
|
if (MSVC)
|
|
|
|
cxx_library(gmock
|
|
|
|
"${cxx_strict}"
|
|
|
|
"${gtest_dir}/src/gtest-all.cc"
|
|
|
|
src/gmock-all.cc)
|
|
|
|
|
|
|
|
cxx_library(gmock_main
|
|
|
|
"${cxx_strict}"
|
|
|
|
"${gtest_dir}/src/gtest-all.cc"
|
|
|
|
src/gmock-all.cc
|
|
|
|
src/gmock_main.cc)
|
|
|
|
else()
|
|
|
|
cxx_library(gmock "${cxx_strict}" src/gmock-all.cc)
|
2017-12-01 12:48:46 +01:00
|
|
|
target_link_libraries(gmock PUBLIC gtest)
|
2020-03-21 05:35:12 -04:00
|
|
|
set_target_properties(gmock PROPERTIES VERSION ${GOOGLETEST_VERSION})
|
2017-12-02 22:47:20 +01:00
|
|
|
cxx_library(gmock_main "${cxx_strict}" src/gmock_main.cc)
|
2017-12-01 12:48:46 +01:00
|
|
|
target_link_libraries(gmock_main PUBLIC gmock)
|
2020-03-21 05:35:12 -04:00
|
|
|
set_target_properties(gmock_main PROPERTIES VERSION ${GOOGLETEST_VERSION})
|
2017-12-02 22:47:20 +01:00
|
|
|
endif()
|
2023-06-20 19:02:23 -06:00
|
|
|
|
|
|
|
string(REPLACE ";" "$<SEMICOLON>" dirs "${gmock_build_include_dirs}")
|
|
|
|
target_include_directories(gmock SYSTEM INTERFACE
|
|
|
|
"$<BUILD_INTERFACE:${dirs}>"
|
|
|
|
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
|
|
|
|
target_include_directories(gmock_main SYSTEM INTERFACE
|
|
|
|
"$<BUILD_INTERFACE:${dirs}>"
|
|
|
|
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
|
2015-12-06 16:25:33 +11:00
|
|
|
|
2015-12-03 09:33:21 +01:00
|
|
|
########################################################################
|
|
|
|
#
|
2023-09-29 17:26:23 +03:00
|
|
|
# Install rules.
|
2017-12-01 12:48:46 +01:00
|
|
|
install_project(gmock gmock_main)
|
2015-12-03 09:33:21 +01:00
|
|
|
|
2010-05-13 18:19:26 +00:00
|
|
|
########################################################################
|
|
|
|
#
|
|
|
|
# Google Mock's own tests.
|
|
|
|
#
|
|
|
|
# You can skip this section if you aren't interested in testing
|
|
|
|
# Google Mock itself.
|
|
|
|
#
|
2023-09-29 17:26:23 +03:00
|
|
|
# The tests are not built by default. To build them, set the
|
|
|
|
# gmock_build_tests option to ON. You can do it by running ccmake
|
2010-05-13 18:19:26 +00:00
|
|
|
# or specifying the -Dgmock_build_tests=ON flag when running cmake.
|
|
|
|
|
|
|
|
if (gmock_build_tests)
|
|
|
|
# This must be set in the root directory for the tests to be run by
|
|
|
|
# 'make test' or ctest.
|
|
|
|
enable_testing()
|
|
|
|
|
2019-08-11 21:10:06 +02:00
|
|
|
if (MINGW OR CYGWIN)
|
2023-06-20 19:02:23 -06:00
|
|
|
add_compile_options("-Wa,-mbig-obj")
|
2019-08-11 21:10:06 +02:00
|
|
|
endif()
|
|
|
|
|
2010-05-13 18:19:26 +00:00
|
|
|
############################################################
|
|
|
|
# C++ tests built with standard compiler flags.
|
|
|
|
|
|
|
|
cxx_test(gmock-actions_test gmock_main)
|
|
|
|
cxx_test(gmock-cardinalities_test gmock_main)
|
2013-03-01 21:28:40 +00:00
|
|
|
cxx_test(gmock_ex_test gmock_main)
|
2018-11-14 13:00:04 -05:00
|
|
|
cxx_test(gmock-function-mocker_test gmock_main)
|
2010-05-13 18:19:26 +00:00
|
|
|
cxx_test(gmock-internal-utils_test gmock_main)
|
2022-03-23 09:07:35 -07:00
|
|
|
cxx_test(gmock-matchers-arithmetic_test gmock_main)
|
|
|
|
cxx_test(gmock-matchers-comparisons_test gmock_main)
|
|
|
|
cxx_test(gmock-matchers-containers_test gmock_main)
|
|
|
|
cxx_test(gmock-matchers-misc_test gmock_main)
|
2010-05-13 18:19:26 +00:00
|
|
|
cxx_test(gmock-more-actions_test gmock_main)
|
|
|
|
cxx_test(gmock-nice-strict_test gmock_main)
|
|
|
|
cxx_test(gmock-port_test gmock_main)
|
|
|
|
cxx_test(gmock-spec-builders_test gmock_main)
|
|
|
|
cxx_test(gmock_link_test gmock_main test/gmock_link2_test.cc)
|
|
|
|
cxx_test(gmock_test gmock_main)
|
|
|
|
|
CMake: use threads if allowed and found, not just if found.
If the user's cmakelists.txt first look for threads using
find_package(Threads), then set(gtest_disable_pthreads ON),
and then include googletest. GoogleTest will not look for
threads. But since they have already been found before in
user's cmakelists, it will use them regardless.
This helped me fix build issue in darktable-org/rawspeed
on windows/MSYS2, even though there are threads, and they
are usable, googletest build was failing with issues
about AutoHandle. I was first looking for threads, and only
then including googletest, so no matter the value of
gtest_disable_pthreads, it failed.
The other obvious solution is for user to first include
googletest, and only then look for threads by himself.
2016-12-30 10:46:39 +03:00
|
|
|
if (DEFINED GTEST_HAS_PTHREAD)
|
2011-05-11 08:18:45 +00:00
|
|
|
cxx_test(gmock_stress_test gmock)
|
|
|
|
endif()
|
|
|
|
|
2010-05-13 18:19:26 +00:00
|
|
|
# gmock_all_test is commented to save time building and running tests.
|
|
|
|
# Uncomment if necessary.
|
|
|
|
# cxx_test(gmock_all_test gmock_main)
|
|
|
|
|
|
|
|
############################################################
|
|
|
|
# C++ tests built with non-standard compiler flags.
|
|
|
|
|
2017-12-02 22:47:20 +01:00
|
|
|
if (MSVC)
|
|
|
|
cxx_library(gmock_main_no_exception "${cxx_no_exception}"
|
|
|
|
"${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc)
|
2011-05-20 00:42:22 +00:00
|
|
|
|
2017-12-02 22:47:20 +01:00
|
|
|
cxx_library(gmock_main_no_rtti "${cxx_no_rtti}"
|
2014-01-13 22:28:01 +00:00
|
|
|
"${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc)
|
|
|
|
|
2017-12-02 22:47:20 +01:00
|
|
|
else()
|
|
|
|
cxx_library(gmock_main_no_exception "${cxx_no_exception}" src/gmock_main.cc)
|
2017-12-01 12:48:46 +01:00
|
|
|
target_link_libraries(gmock_main_no_exception PUBLIC gmock)
|
2017-12-02 22:47:20 +01:00
|
|
|
|
|
|
|
cxx_library(gmock_main_no_rtti "${cxx_no_rtti}" src/gmock_main.cc)
|
2017-12-01 12:48:46 +01:00
|
|
|
target_link_libraries(gmock_main_no_rtti PUBLIC gmock)
|
2014-01-13 22:28:01 +00:00
|
|
|
endif()
|
2010-05-13 18:19:26 +00:00
|
|
|
cxx_test_with_flags(gmock-more-actions_no_exception_test "${cxx_no_exception}"
|
|
|
|
gmock_main_no_exception test/gmock-more-actions_test.cc)
|
|
|
|
|
|
|
|
cxx_test_with_flags(gmock_no_rtti_test "${cxx_no_rtti}"
|
|
|
|
gmock_main_no_rtti test/gmock-spec-builders_test.cc)
|
|
|
|
|
2011-05-20 00:42:22 +00:00
|
|
|
cxx_shared_library(shared_gmock_main "${cxx_default}"
|
|
|
|
"${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc)
|
|
|
|
|
2023-09-29 17:26:23 +03:00
|
|
|
# Tests that a binary can be built with Google Mock as a shared library. On
|
2011-05-20 00:42:22 +00:00
|
|
|
# some system configurations, it may not possible to run the binary without
|
|
|
|
# knowing more details about the system configurations. We do not try to run
|
|
|
|
# this binary. To get a more robust shared library coverage, configure with
|
|
|
|
# -DBUILD_SHARED_LIBS=ON.
|
|
|
|
cxx_executable_with_flags(shared_gmock_test_ "${cxx_default}"
|
|
|
|
shared_gmock_main test/gmock-spec-builders_test.cc)
|
|
|
|
set_target_properties(shared_gmock_test_
|
|
|
|
PROPERTIES
|
|
|
|
COMPILE_DEFINITIONS "GTEST_LINKED_AS_SHARED_LIBRARY=1")
|
|
|
|
|
2010-05-13 18:19:26 +00:00
|
|
|
############################################################
|
|
|
|
# Python tests.
|
|
|
|
|
|
|
|
cxx_executable(gmock_leak_test_ test gmock_main)
|
|
|
|
py_test(gmock_leak_test)
|
|
|
|
|
|
|
|
cxx_executable(gmock_output_test_ test gmock)
|
|
|
|
py_test(gmock_output_test)
|
|
|
|
endif()
|