Note that this approach requires CMake 2.8.2 or later due to
Note that this approach requires CMake 2.8.2 or later due to its use of the
its use of the `ExternalProject_Add()` command. The above
`ExternalProject_Add()` command. The above technique is discussed in more detail
technique is discussed in more detail in
in [this separate article](http://crascit.com/2015/07/25/cmake-gtest/) which
[this separate article](http://crascit.com/2015/07/25/cmake-gtest/)
also contains a link to a fully generalized implementation of the technique.
which also contains a link to a fully generalized implementation
of the technique.
##### Visual Studio Dynamic vs Static Runtimes #####
##### Visual Studio Dynamic vs Static Runtimes
By default, new Visual Studio projects link the C runtimes dynamically
By default, new Visual Studio projects link the C runtimes dynamically but
but Google Test links them statically.
Google Test links them statically. This will generate an error that looks
This will generate an error that looks something like the following:
something like the following: gtest.lib(gtest-all.obj) : error LNK2038: mismatch
gtest.lib(gtest-all.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value
'MDd_DynamicDebug' in main.obj
Google Test already has a CMake option for this: `gtest_force_shared_crt`
Google Test already has a CMake option for this: `gtest_force_shared_crt`
Enabling this option will make gtest link the runtimes dynamically too,
Enabling this option will make gtest link the runtimes dynamically too, and
and match the project in which it is included.
match the project in which it is included.
### Legacy Build Scripts ###
### Legacy Build Scripts
Before settling on CMake, we have been providing hand-maintained build
Before settling on CMake, we have been providing hand-maintained build
projects/scripts for Visual Studio, Xcode, and Autotools. While we
projects/scripts for Visual Studio, Xcode, and Autotools. While we continue to
continue to provide them for convenience, they are not actively
provide them for convenience, they are not actively maintained any more. We
maintained any more. We highly recommend that you follow the
highly recommend that you follow the instructions in the above sections to
instructions in the above sections to integrate Google Test
integrate Google Test with your existing build system.
with your existing build system.
If you still need to use the legacy build scripts, here's how:
If you still need to use the legacy build scripts, here's how:
The msvc\ folder contains two solutions with Visual C++ projects.
The msvc\ folder contains two solutions with Visual C++ projects. Open the
Open the `gtest.sln` or `gtest-md.sln` file using Visual Studio, and you
`gtest.sln` or `gtest-md.sln` file using Visual Studio, and you are ready to
are ready to build Google Test the same way you build any Visual
build Google Test the same way you build any Visual Studio project. Files that
Studio project. Files that have names ending with -md use DLL
have names ending with -md use DLL versions of Microsoft runtime libraries (the
versions of Microsoft runtime libraries (the /MD or the /MDd compiler
/MD or the /MDd compiler option). Files without that suffix use static versions
option). Files without that suffix use static versions of the runtime
of the runtime libraries (the /MT or the /MTd option). Please note that one must
libraries (the /MT or the /MTd option). Please note that one must use
use the same option to compile both gtest and the test code. If you use Visual
the same option to compile both gtest and the test code. If you use
Studio 2005 or above, we recommend the -md version as /MD is the default for new
Visual Studio 2005 or above, we recommend the -md version as /MD is
projects in these versions of Visual Studio.
the default for new projects in these versions of Visual Studio.
On Mac OS X, open the `gtest.xcodeproj` in the `xcode/` folder using Xcode.
On Mac OS X, open the `gtest.xcodeproj` in the `xcode/` folder using
Build the "gtest" target. The universal binary framework will end up in your
Xcode. Build the "gtest" target. The universal binary framework will
selected build directory (selected in the Xcode "Preferences..." -> "Building"
end up in your selected build directory (selected in the Xcode
pane and defaults to xcode/build). Alternatively, at the command line, enter:
"Preferences..." -> "Building" pane and defaults to xcode/build).
Alternatively, at the command line, enter:
xcodebuild
xcodebuild
This will build the "Release" configuration of gtest.framework in your
This will build the "Release" configuration of gtest.framework in your default
default build location. See the "xcodebuild" man page for more
build location. See the "xcodebuild" man page for more information about
information about building different configurations and building in
building different configurations and building in different locations.
different locations.
If you wish to use the Google Test Xcode project with Xcode 4.x and
If you wish to use the Google Test Xcode project with Xcode 4.x and above, you
above, you need to either:
need to either:
* update the SDK configuration options in xcode/Config/General.xconfig.
* update the SDK configuration options in xcode/Config/General.xconfig.
Comment options `SDKROOT`, `MACOS_DEPLOYMENT_TARGET`, and `GCC_VERSION`. If
Comment options `SDKROOT`, `MACOS_DEPLOYMENT_TARGET`, and `GCC_VERSION`. If
you choose this route you lose the ability to target earlier versions
you choose this route you lose the ability to target earlier versions of
of MacOS X.
MacOS X.
* Install an SDK for an earlier version. This doesn't appear to be
* Install an SDK for an earlier version. This doesn't appear to be supported
supported by Apple, but has been reported to work
by Apple, but has been reported to work
(http://stackoverflow.com/questions/5378518).
(http://stackoverflow.com/questions/5378518).
### Tweaking Google Test ###
### Tweaking Google Test
Google Test can be used in diverse environments. The default
Google Test can be used in diverse environments. The default configuration may
configuration may not work (or may not work well) out of the box in
not work (or may not work well) out of the box in some environments. However,
some environments. However, you can easily tweak Google Test by
you can easily tweak Google Test by defining control macros on the compiler
defining control macros on the compiler command line. Generally,
command line. Generally, these macros are named like `GTEST_XYZ` and you define
these macros are named like `GTEST_XYZ` and you define them to either 1
them to either 1 or 0 to enable or disable a certain feature.
or 0 to enable or disable a certain feature.
We list the most frequently used macros below. For a complete list,
We list the most frequently used macros below. For a complete list, see file
see file [include/gtest/internal/gtest-port.h](include/gtest/internal/gtest-port.h).