Adds a gtest_disable_pthreads CMake option; also fixes an include order problem in the cmake script.
This commit is contained in:
		@@ -1,8 +1,5 @@
 | 
			
		||||
########################################################################
 | 
			
		||||
# Experimental CMake build script for Google Test.
 | 
			
		||||
#
 | 
			
		||||
# Consider this a prototype.  It will change drastically.  For now,
 | 
			
		||||
# this is only for people on the cutting edge.
 | 
			
		||||
# CMake build script for Google Test.
 | 
			
		||||
#
 | 
			
		||||
# To run the tests for Google Test itself on Linux, use 'make test' or
 | 
			
		||||
# ctest.  You can select which tests to run using 'ctest -R regex'.
 | 
			
		||||
@@ -23,6 +20,9 @@ option(gtest_build_tests "Build all of gtest's own tests." OFF)
 | 
			
		||||
 | 
			
		||||
option(gtest_build_samples "Build gtest's sample programs." OFF)
 | 
			
		||||
 | 
			
		||||
option(gtest_disable_pthreads "Disable uses of pthreads in gtest." OFF)
 | 
			
		||||
 | 
			
		||||
# Defines pre_project_set_up_hermetic_build() and set_up_hermetic_build().
 | 
			
		||||
include(cmake/hermetic_build.cmake OPTIONAL)
 | 
			
		||||
 | 
			
		||||
if (COMMAND pre_project_set_up_hermetic_build)
 | 
			
		||||
@@ -46,10 +46,10 @@ if (COMMAND set_up_hermetic_build)
 | 
			
		||||
  set_up_hermetic_build()
 | 
			
		||||
endif()
 | 
			
		||||
 | 
			
		||||
# Defines functions and variables used by Google Test.
 | 
			
		||||
# Define helper functions and macros used by Google Test.
 | 
			
		||||
include(cmake/internal_utils.cmake)
 | 
			
		||||
 | 
			
		||||
fix_default_settings()  # Defined in internal_utils.cmake.
 | 
			
		||||
config_compiler_and_linker()  # Defined in internal_utils.cmake.
 | 
			
		||||
 | 
			
		||||
# Where Google Test's .h files can be found.
 | 
			
		||||
include_directories(
 | 
			
		||||
 
 | 
			
		||||
@@ -1,13 +1,22 @@
 | 
			
		||||
# NOTE: This file can be included both into Google Test's and Google Mock's
 | 
			
		||||
# build scripts, so actions and functions defined here need to be
 | 
			
		||||
# idempotent.
 | 
			
		||||
# Defines functions and macros useful for building Google Test and
 | 
			
		||||
# Google Mock.
 | 
			
		||||
#
 | 
			
		||||
# Note:
 | 
			
		||||
#
 | 
			
		||||
# - This file will be run twice when building Google Mock (once via
 | 
			
		||||
#   Google Test's CMakeLists.txt, and once via Google Mock's).
 | 
			
		||||
#   Therefore it shouldn't have any side effects other than defining
 | 
			
		||||
#   the functions and macros.
 | 
			
		||||
#
 | 
			
		||||
# - The functions/macros defined in this file may depend on Google
 | 
			
		||||
#   Test and Google Mock's option() definitions, and thus must be
 | 
			
		||||
#   called *after* the options have been defined.
 | 
			
		||||
 | 
			
		||||
# Defines CMAKE_USE_PTHREADS_INIT and CMAKE_THREAD_LIBS_INIT.
 | 
			
		||||
find_package(Threads)
 | 
			
		||||
 | 
			
		||||
# macro is required here, as inside a function string() will update
 | 
			
		||||
# variables only at the function scope.
 | 
			
		||||
macro(fix_default_settings)
 | 
			
		||||
# Tweaks CMake's default compiler/linker settings to suit Google Test's needs.
 | 
			
		||||
#
 | 
			
		||||
# This must be a macro(), as inside a function string() can only
 | 
			
		||||
# update variables in the function scope.
 | 
			
		||||
macro(fix_default_compiler_settings_)
 | 
			
		||||
  if (MSVC)
 | 
			
		||||
    # For MSVC, CMake sets certain flags to defaults we want to override.
 | 
			
		||||
    # This replacement code is taken from sample in the CMake Wiki at
 | 
			
		||||
@@ -33,62 +42,69 @@ macro(fix_default_settings)
 | 
			
		||||
  endif()
 | 
			
		||||
endmacro()
 | 
			
		||||
 | 
			
		||||
# Defines the compiler/linker flags used to build gtest.  You can
 | 
			
		||||
# tweak these definitions to suit your need.  A variable's value is
 | 
			
		||||
# empty before it's explicitly assigned to.
 | 
			
		||||
# Defines the compiler/linker flags used to build Google Test and
 | 
			
		||||
# Google Mock.  You can tweak these definitions to suit your need.  A
 | 
			
		||||
# variable's value is empty before it's explicitly assigned to.
 | 
			
		||||
macro(config_compiler_and_linker)
 | 
			
		||||
  if (NOT gtest_disable_pthreads)
 | 
			
		||||
    # Defines CMAKE_USE_PTHREADS_INIT and CMAKE_THREAD_LIBS_INIT.
 | 
			
		||||
    find_package(Threads)
 | 
			
		||||
  endif()
 | 
			
		||||
 | 
			
		||||
if (MSVC)
 | 
			
		||||
  # Newlines inside flags variables break CMake's NMake generator.
 | 
			
		||||
  # TODO(vladl@google.com): Add -RTCs and -RTCu to debug builds.
 | 
			
		||||
  set(cxx_base_flags "-GS -W4 -WX -wd4127 -wd4251 -wd4275 -nologo -J -Zi")
 | 
			
		||||
  set(cxx_base_flags "${cxx_base_flags} -D_UNICODE -DUNICODE -DWIN32 -D_WIN32")
 | 
			
		||||
  set(cxx_base_flags "${cxx_base_flags} -DSTRICT -DWIN32_LEAN_AND_MEAN")
 | 
			
		||||
  set(cxx_exception_flags "-EHsc -D_HAS_EXCEPTIONS=1")
 | 
			
		||||
  set(cxx_no_exception_flags "-D_HAS_EXCEPTIONS=0")
 | 
			
		||||
  set(cxx_no_rtti_flags "-GR-")
 | 
			
		||||
elseif (CMAKE_COMPILER_IS_GNUCXX)
 | 
			
		||||
  set(cxx_base_flags "-Wall -Wshadow")
 | 
			
		||||
  set(cxx_exception_flags "-fexceptions")
 | 
			
		||||
  set(cxx_no_exception_flags "-fno-exceptions")
 | 
			
		||||
  # Until version 4.3.2, GCC doesn't define a macro to indicate
 | 
			
		||||
  # whether RTTI is enabled.  Therefore we define GTEST_HAS_RTTI
 | 
			
		||||
  # explicitly.
 | 
			
		||||
  set(cxx_no_rtti_flags "-fno-rtti -DGTEST_HAS_RTTI=0")
 | 
			
		||||
  set(cxx_strict_flags "-Wextra")
 | 
			
		||||
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "SunPro")
 | 
			
		||||
  set(cxx_exception_flags "-features=except")
 | 
			
		||||
  # Sun Pro doesn't provide macros to indicate whether exceptions and
 | 
			
		||||
  # RTTI are enabled, so we define GTEST_HAS_* explicitly.
 | 
			
		||||
  set(cxx_no_exception_flags "-features=no%except -DGTEST_HAS_EXCEPTIONS=0")
 | 
			
		||||
  set(cxx_no_rtti_flags "-features=no%rtti -DGTEST_HAS_RTTI=0")
 | 
			
		||||
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "VisualAge" OR
 | 
			
		||||
        CMAKE_CXX_COMPILER_ID STREQUAL "XL")
 | 
			
		||||
  # CMake 2.8 changes Visual Age's compiler ID to "XL".
 | 
			
		||||
  set(cxx_exception_flags "-qeh")
 | 
			
		||||
  set(cxx_no_exception_flags "-qnoeh")
 | 
			
		||||
  # Until version 9.0, Visual Age doesn't define a macro to indicate
 | 
			
		||||
  # whether RTTI is enabled.  Therefore we define GTEST_HAS_RTTI
 | 
			
		||||
  # explicitly.
 | 
			
		||||
  set(cxx_no_rtti_flags "-qnortti -DGTEST_HAS_RTTI=0")
 | 
			
		||||
endif()
 | 
			
		||||
  fix_default_compiler_settings_()
 | 
			
		||||
  if (MSVC)
 | 
			
		||||
    # Newlines inside flags variables break CMake's NMake generator.
 | 
			
		||||
    # TODO(vladl@google.com): Add -RTCs and -RTCu to debug builds.
 | 
			
		||||
    set(cxx_base_flags "-GS -W4 -WX -wd4127 -wd4251 -wd4275 -nologo -J -Zi")
 | 
			
		||||
    set(cxx_base_flags "${cxx_base_flags} -D_UNICODE -DUNICODE -DWIN32 -D_WIN32")
 | 
			
		||||
    set(cxx_base_flags "${cxx_base_flags} -DSTRICT -DWIN32_LEAN_AND_MEAN")
 | 
			
		||||
    set(cxx_exception_flags "-EHsc -D_HAS_EXCEPTIONS=1")
 | 
			
		||||
    set(cxx_no_exception_flags "-D_HAS_EXCEPTIONS=0")
 | 
			
		||||
    set(cxx_no_rtti_flags "-GR-")
 | 
			
		||||
  elseif (CMAKE_COMPILER_IS_GNUCXX)
 | 
			
		||||
    set(cxx_base_flags "-Wall -Wshadow")
 | 
			
		||||
    set(cxx_exception_flags "-fexceptions")
 | 
			
		||||
    set(cxx_no_exception_flags "-fno-exceptions")
 | 
			
		||||
    # Until version 4.3.2, GCC doesn't define a macro to indicate
 | 
			
		||||
    # whether RTTI is enabled.  Therefore we define GTEST_HAS_RTTI
 | 
			
		||||
    # explicitly.
 | 
			
		||||
    set(cxx_no_rtti_flags "-fno-rtti -DGTEST_HAS_RTTI=0")
 | 
			
		||||
    set(cxx_strict_flags "-Wextra")
 | 
			
		||||
  elseif (CMAKE_CXX_COMPILER_ID STREQUAL "SunPro")
 | 
			
		||||
    set(cxx_exception_flags "-features=except")
 | 
			
		||||
    # Sun Pro doesn't provide macros to indicate whether exceptions and
 | 
			
		||||
    # RTTI are enabled, so we define GTEST_HAS_* explicitly.
 | 
			
		||||
    set(cxx_no_exception_flags "-features=no%except -DGTEST_HAS_EXCEPTIONS=0")
 | 
			
		||||
    set(cxx_no_rtti_flags "-features=no%rtti -DGTEST_HAS_RTTI=0")
 | 
			
		||||
  elseif (CMAKE_CXX_COMPILER_ID STREQUAL "VisualAge" OR
 | 
			
		||||
      CMAKE_CXX_COMPILER_ID STREQUAL "XL")
 | 
			
		||||
    # CMake 2.8 changes Visual Age's compiler ID to "XL".
 | 
			
		||||
    set(cxx_exception_flags "-qeh")
 | 
			
		||||
    set(cxx_no_exception_flags "-qnoeh")
 | 
			
		||||
    # Until version 9.0, Visual Age doesn't define a macro to indicate
 | 
			
		||||
    # whether RTTI is enabled.  Therefore we define GTEST_HAS_RTTI
 | 
			
		||||
    # explicitly.
 | 
			
		||||
    set(cxx_no_rtti_flags "-qnortti -DGTEST_HAS_RTTI=0")
 | 
			
		||||
  endif()
 | 
			
		||||
 | 
			
		||||
if (CMAKE_USE_PTHREADS_INIT)  # The pthreads library is available.
 | 
			
		||||
  set(cxx_base_flags "${cxx_base_flags} -DGTEST_HAS_PTHREAD=1")
 | 
			
		||||
endif()
 | 
			
		||||
  if (CMAKE_USE_PTHREADS_INIT)  # The pthreads library is available and allowed.
 | 
			
		||||
    set(cxx_base_flags "${cxx_base_flags} -DGTEST_HAS_PTHREAD=1")
 | 
			
		||||
  else()
 | 
			
		||||
    set(cxx_base_flags "${cxx_base_flags} -DGTEST_HAS_PTHREAD=0")
 | 
			
		||||
  endif()
 | 
			
		||||
 | 
			
		||||
# For building gtest's own tests and samples.
 | 
			
		||||
set(cxx_exception "${CMAKE_CXX_FLAGS} ${cxx_base_flags} ${cxx_exception_flags}")
 | 
			
		||||
set(cxx_no_exception
 | 
			
		||||
  # For building gtest's own tests and samples.
 | 
			
		||||
  set(cxx_exception "${CMAKE_CXX_FLAGS} ${cxx_base_flags} ${cxx_exception_flags}")
 | 
			
		||||
  set(cxx_no_exception
 | 
			
		||||
    "${CMAKE_CXX_FLAGS} ${cxx_base_flags} ${cxx_no_exception_flags}")
 | 
			
		||||
set(cxx_default "${cxx_exception}")
 | 
			
		||||
set(cxx_no_rtti "${cxx_default} ${cxx_no_rtti_flags}")
 | 
			
		||||
set(cxx_use_own_tuple "${cxx_default} -DGTEST_USE_OWN_TR1_TUPLE=1")
 | 
			
		||||
  set(cxx_default "${cxx_exception}")
 | 
			
		||||
  set(cxx_no_rtti "${cxx_default} ${cxx_no_rtti_flags}")
 | 
			
		||||
  set(cxx_use_own_tuple "${cxx_default} -DGTEST_USE_OWN_TR1_TUPLE=1")
 | 
			
		||||
 | 
			
		||||
# For building the gtest libraries.
 | 
			
		||||
set(cxx_strict "${cxx_default} ${cxx_strict_flags}")
 | 
			
		||||
  # For building the gtest libraries.
 | 
			
		||||
  set(cxx_strict "${cxx_default} ${cxx_strict_flags}")
 | 
			
		||||
endmacro()
 | 
			
		||||
 | 
			
		||||
########################################################################
 | 
			
		||||
#
 | 
			
		||||
# Defines the gtest & gtest_main libraries.  User tests should link
 | 
			
		||||
# with one of them.
 | 
			
		||||
function(cxx_library_with_type name type cxx_flags)
 | 
			
		||||
@@ -108,6 +124,10 @@ function(cxx_library_with_type name type cxx_flags)
 | 
			
		||||
  endif()
 | 
			
		||||
endfunction()
 | 
			
		||||
 | 
			
		||||
########################################################################
 | 
			
		||||
#
 | 
			
		||||
# Helper functions for creating build targets.
 | 
			
		||||
 | 
			
		||||
function(cxx_shared_library name cxx_flags)
 | 
			
		||||
  cxx_library_with_type(${name} SHARED "${cxx_flags}" ${ARGN})
 | 
			
		||||
endfunction()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user