diff options
author | iphydf <iphydf@users.noreply.github.com> | 2018-02-11 00:09:07 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2018-02-11 12:20:36 +0000 |
commit | 2e74db5447f89745f4bdc375230e20a7247670a0 (patch) | |
tree | eea5fc2ab7f8741626b2ace7468ebadbfe01d2a3 /cmake | |
parent | 95029f412c173878a066a5d42c16e3f0161fd445 (diff) |
Improve gtest finding, support local checkout.
Also fix library dependency order for monolith test.
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/CompileGTest.cmake | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/cmake/CompileGTest.cmake b/cmake/CompileGTest.cmake new file mode 100644 index 00000000..520ca06a --- /dev/null +++ b/cmake/CompileGTest.cmake | |||
@@ -0,0 +1,49 @@ | |||
1 | # Find and compile the GTest library. | ||
2 | |||
3 | message(STATUS "Checking for gtest") | ||
4 | |||
5 | # Look for the sources. | ||
6 | find_file(GTEST_ALL_CC gtest-all.cc PATHS | ||
7 | ${CMAKE_SOURCE_DIR}/third_party/googletest/googletest/src | ||
8 | /usr/src/gtest/src | ||
9 | NO_DEFAULT_PATH | ||
10 | ) | ||
11 | |||
12 | if(GTEST_ALL_CC) | ||
13 | # ../.. from the source file is the source root. | ||
14 | get_filename_component(GTEST_SRC_DIR ${GTEST_ALL_CC} DIRECTORY) | ||
15 | get_filename_component(GTEST_SRC_ROOT ${GTEST_SRC_DIR} DIRECTORY) | ||
16 | |||
17 | # Look for the header file. | ||
18 | include(CheckIncludeFileCXX) | ||
19 | include_directories(SYSTEM ${GTEST_SRC_ROOT}/include) | ||
20 | check_include_file_cxx("gtest/gtest.h" HAVE_GTEST_GTEST_H) | ||
21 | |||
22 | if(HAVE_GTEST_GTEST_H) | ||
23 | message(STATUS "Found gtest: ${GTEST_SRC_ROOT}") | ||
24 | |||
25 | add_library(gtest | ||
26 | ${GTEST_SRC_DIR}/gtest-all.cc | ||
27 | ${GTEST_SRC_DIR}/gtest_main.cc) | ||
28 | target_include_directories(gtest PRIVATE ${GTEST_SRC_ROOT}) | ||
29 | |||
30 | # Ignore all warnings for gtest. We don't care about their implementation. | ||
31 | check_cxx_compiler_flag("-w" HAVE_CXX_W QUIET) | ||
32 | if(HAVE_CXX_W) | ||
33 | set_target_properties(gtest PROPERTIES COMPILE_FLAGS "-w") | ||
34 | endif() | ||
35 | |||
36 | set(HAVE_GTEST TRUE) | ||
37 | set(TEST_CXX_FLAGS "") | ||
38 | |||
39 | check_cxx_compiler_flag("-Wno-global-constructors" HAVE_CXX_W_NO_GLOBAL_CONSTRUCTORS QUIET) | ||
40 | if(HAVE_CXX_W_NO_GLOBAL_CONSTRUCTORS) | ||
41 | set(TEST_CXX_FLAGS "${TEST_CXX_FLAGS} -Wno-global-constructors") | ||
42 | endif() | ||
43 | |||
44 | check_cxx_compiler_flag("-Wno-zero-as-null-pointer-constant" HAVE_CXX_W_NO_ZERO_AS_NULL_POINTER_CONSTANT QUIET) | ||
45 | if(HAVE_CXX_W_NO_ZERO_AS_NULL_POINTER_CONSTANT) | ||
46 | set(TEST_CXX_FLAGS "${TEST_CXX_FLAGS} -Wno-zero-as-null-pointer-constant") | ||
47 | endif() | ||
48 | endif() | ||
49 | endif() | ||