?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download

  1. ########################################################################
  2. # CMake build script for Google Mock.
  3. #
  4. # To run the tests for Google Mock itself on Linux, use 'make test' or
  5. # ctest.  You can select which tests to run using 'ctest -R regex'.
  6. # For more options, run 'ctest --help'.
  7.  
  8. option(gmock_build_tests "Build all of Google Mock's own tests." OFF)
  9.  
  10. # A directory to find Google Test sources.
  11. if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/gtest/CMakeLists.txt")
  12.   set(gtest_dir gtest)
  13. else()
  14.   set(gtest_dir ../googletest)
  15. endif()
  16.  
  17. # Defines pre_project_set_up_hermetic_build() and set_up_hermetic_build().
  18. include("${gtest_dir}/cmake/hermetic_build.cmake" OPTIONAL)
  19.  
  20. if (COMMAND pre_project_set_up_hermetic_build)
  21.   # Google Test also calls hermetic setup functions from add_subdirectory,
  22.   # although its changes will not affect things at the current scope.
  23.   pre_project_set_up_hermetic_build()
  24. endif()
  25.  
  26. ########################################################################
  27. #
  28. # Project-wide settings
  29.  
  30. # Name of the project.
  31. #
  32. # CMake files in this project can refer to the root source directory
  33. # as ${gmock_SOURCE_DIR} and to the root binary directory as
  34. # ${gmock_BINARY_DIR}.
  35. # Language "C" is required for find_package(Threads).
  36. if (CMAKE_VERSION VERSION_LESS 3.0)
  37.   project(gmock CXX C)
  38. else()
  39.   cmake_policy(SET CMP0048 NEW)
  40.   project(gmock VERSION ${GOOGLETEST_VERSION} LANGUAGES CXX C)
  41. endif()
  42. cmake_minimum_required(VERSION 2.6.4)
  43.  
  44. if (COMMAND set_up_hermetic_build)
  45.   set_up_hermetic_build()
  46. endif()
  47.  
  48. # Instructs CMake to process Google Test's CMakeLists.txt and add its
  49. # targets to the current scope.  We are placing Google Test's binary
  50. # directory in a subdirectory of our own as VC compilation may break
  51. # if they are the same (the default).
  52. add_subdirectory("${gtest_dir}" "${gmock_BINARY_DIR}/gtest")
  53.  
  54.  
  55. # These commands only run if this is the main project
  56. if(CMAKE_PROJECT_NAME STREQUAL "gmock" OR CMAKE_PROJECT_NAME STREQUAL "googletest-distribution")
  57.   # BUILD_SHARED_LIBS is a standard CMake variable, but we declare it here to
  58.   # make it prominent in the GUI.
  59.   option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)." OFF)
  60. else()
  61.   mark_as_advanced(gmock_build_tests)
  62. endif()
  63.  
  64. # Although Google Test's CMakeLists.txt calls this function, the
  65. # changes there don't affect the current scope.  Therefore we have to
  66. # call it again here.
  67. config_compiler_and_linker()  # from ${gtest_dir}/cmake/internal_utils.cmake
  68.  
  69. # Adds Google Mock's and Google Test's header directories to the search path.
  70. set(gmock_build_include_dirs
  71.   "${gmock_SOURCE_DIR}/include"
  72.   "${gmock_SOURCE_DIR}"
  73.   "${gtest_SOURCE_DIR}/include"
  74.   # This directory is needed to build directly from Google Test sources.
  75.   "${gtest_SOURCE_DIR}")
  76. include_directories(${gmock_build_include_dirs})
  77.  
  78. # Summary of tuple support for Microsoft Visual Studio:
  79. # Compiler    version(MS)  version(cmake)  Support
  80. # ----------  -----------  --------------  -----------------------------
  81. # <= VS 2010  <= 10        <= 1600         Use Google Tests's own tuple.
  82. # VS 2012     11           1700            std::tr1::tuple + _VARIADIC_MAX=10
  83. # VS 2013     12           1800            std::tr1::tuple
  84. # VS 2015     14           1900            std::tuple
  85. # VS 2017     15           >= 1910         std::tuple
  86. if (MSVC AND MSVC_VERSION EQUAL 1700)
  87.   add_definitions(/D _VARIADIC_MAX=10)
  88. endif()
  89.  
  90. ########################################################################
  91. #
  92. # Defines the gmock & gmock_main libraries.  User tests should link
  93. # with one of them.
  94.  
  95. # Google Mock libraries.  We build them using more strict warnings than what
  96. # are used for other targets, to ensure that Google Mock can be compiled by
  97. # a user aggressive about warnings.
  98. if (MSVC)
  99.   cxx_library(gmock
  100.               "${cxx_strict}"
  101.               "${gtest_dir}/src/gtest-all.cc"
  102.               src/gmock-all.cc)
  103.  
  104.   cxx_library(gmock_main
  105.               "${cxx_strict}"
  106.               "${gtest_dir}/src/gtest-all.cc"
  107.               src/gmock-all.cc
  108.               src/gmock_main.cc)
  109. else()
  110.   cxx_library(gmock "${cxx_strict}" src/gmock-all.cc)
  111.   target_link_libraries(gmock PUBLIC gtest)
  112.   cxx_library(gmock_main "${cxx_strict}" src/gmock_main.cc)
  113.   target_link_libraries(gmock_main PUBLIC gmock)
  114. endif()
  115. # If the CMake version supports it, attach header directory information
  116. # to the targets for when we are part of a parent build (ie being pulled
  117. # in via add_subdirectory() rather than being a standalone build).
  118. if (DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11")
  119.   target_include_directories(gmock SYSTEM INTERFACE
  120.     "$<BUILD_INTERFACE:${gmock_build_include_dirs}>"
  121.     "$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
  122.   target_include_directories(gmock_main SYSTEM INTERFACE
  123.     "$<BUILD_INTERFACE:${gmock_build_include_dirs}>"
  124.     "$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
  125. endif()
  126.  
  127. ########################################################################
  128. #
  129. # Install rules
  130. install_project(gmock gmock_main)
  131.  
  132. ########################################################################
  133. #
  134. # Google Mock's own tests.
  135. #
  136. # You can skip this section if you aren't interested in testing
  137. # Google Mock itself.
  138. #
  139. # The tests are not built by default.  To build them, set the
  140. # gmock_build_tests option to ON.  You can do it by running ccmake
  141. # or specifying the -Dgmock_build_tests=ON flag when running cmake.
  142.  
  143. if (gmock_build_tests)
  144.   # This must be set in the root directory for the tests to be run by
  145.   # 'make test' or ctest.
  146.   enable_testing()
  147.  
  148.   ############################################################
  149.   # C++ tests built with standard compiler flags.
  150.  
  151.   cxx_test(gmock-actions_test gmock_main)
  152.   cxx_test(gmock-cardinalities_test gmock_main)
  153.   cxx_test(gmock_ex_test gmock_main)
  154.   cxx_test(gmock-generated-actions_test gmock_main)
  155.   cxx_test(gmock-generated-function-mockers_test gmock_main)
  156.   cxx_test(gmock-generated-internal-utils_test gmock_main)
  157.   cxx_test(gmock-generated-matchers_test gmock_main)
  158.   cxx_test(gmock-internal-utils_test gmock_main)
  159.   cxx_test(gmock-matchers_test gmock_main)
  160.   cxx_test(gmock-more-actions_test gmock_main)
  161.   cxx_test(gmock-nice-strict_test gmock_main)
  162.   cxx_test(gmock-port_test gmock_main)
  163.   cxx_test(gmock-spec-builders_test gmock_main)
  164.   cxx_test(gmock_link_test gmock_main test/gmock_link2_test.cc)
  165.   cxx_test(gmock_test gmock_main)
  166.  
  167.   if (DEFINED GTEST_HAS_PTHREAD)
  168.     cxx_test(gmock_stress_test gmock)
  169.   endif()
  170.  
  171.   # gmock_all_test is commented to save time building and running tests.
  172.   # Uncomment if necessary.
  173.   # cxx_test(gmock_all_test gmock_main)
  174.  
  175.   ############################################################
  176.   # C++ tests built with non-standard compiler flags.
  177.  
  178.   if (MSVC)
  179.     cxx_library(gmock_main_no_exception "${cxx_no_exception}"
  180.       "${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc)
  181.  
  182.     cxx_library(gmock_main_no_rtti "${cxx_no_rtti}"
  183.       "${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc)
  184.  
  185.     if (MSVC_VERSION LESS 1600)  # 1600 is Visual Studio 2010.
  186.       # Visual Studio 2010, 2012, and 2013 define symbols in std::tr1 that
  187.       # conflict with our own definitions. Therefore using our own tuple does not
  188.       # work on those compilers.
  189.       cxx_library(gmock_main_use_own_tuple "${cxx_use_own_tuple}"
  190.         "${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc)
  191.  
  192.       cxx_test_with_flags(gmock_use_own_tuple_test "${cxx_use_own_tuple}"
  193.         gmock_main_use_own_tuple test/gmock-spec-builders_test.cc)
  194.     endif()
  195.   else()
  196.     cxx_library(gmock_main_no_exception "${cxx_no_exception}" src/gmock_main.cc)
  197.     target_link_libraries(gmock_main_no_exception PUBLIC gmock)
  198.  
  199.     cxx_library(gmock_main_no_rtti "${cxx_no_rtti}" src/gmock_main.cc)
  200.     target_link_libraries(gmock_main_no_rtti PUBLIC gmock)
  201.  
  202.     cxx_library(gmock_main_use_own_tuple "${cxx_use_own_tuple}" src/gmock_main.cc)
  203.     target_link_libraries(gmock_main_use_own_tuple PUBLIC gmock)
  204.   endif()
  205.   cxx_test_with_flags(gmock-more-actions_no_exception_test "${cxx_no_exception}"
  206.     gmock_main_no_exception test/gmock-more-actions_test.cc)
  207.  
  208.   cxx_test_with_flags(gmock_no_rtti_test "${cxx_no_rtti}"
  209.     gmock_main_no_rtti test/gmock-spec-builders_test.cc)
  210.  
  211.   cxx_shared_library(shared_gmock_main "${cxx_default}"
  212.     "${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc)
  213.  
  214.   # Tests that a binary can be built with Google Mock as a shared library.  On
  215.   # some system configurations, it may not possible to run the binary without
  216.   # knowing more details about the system configurations. We do not try to run
  217.   # this binary. To get a more robust shared library coverage, configure with
  218.   # -DBUILD_SHARED_LIBS=ON.
  219.   cxx_executable_with_flags(shared_gmock_test_ "${cxx_default}"
  220.     shared_gmock_main test/gmock-spec-builders_test.cc)
  221.   set_target_properties(shared_gmock_test_
  222.     PROPERTIES
  223.     COMPILE_DEFINITIONS "GTEST_LINKED_AS_SHARED_LIBRARY=1")
  224.  
  225.   ############################################################
  226.   # Python tests.
  227.  
  228.   cxx_executable(gmock_leak_test_ test gmock_main)
  229.   py_test(gmock_leak_test)
  230.  
  231.   cxx_executable(gmock_output_test_ test gmock)
  232.   py_test(gmock_output_test)
  233. endif()
  234.