Commit | Line | Data |
---|---|---|
89c34f5e MC |
1 | From 6693b9c8ff1ae1ec02c9002c0a8f5f416f0c88f0 Mon Sep 17 00:00:00 2001 |
2 | From: Maxim Cournoyer <maxim.cournoyer@gmail.com> | |
3 | Date: Sun, 12 Jan 2020 23:23:33 -0500 | |
4 | Subject: [PATCH 3/3] build: Prefer googletest from the system. | |
5 | ||
6 | Fixes issue #4. | |
7 | ||
8 | The build system now look for a system installed googletest or falls | |
9 | back to the bundled copy of googletest otherwise. | |
10 | ||
11 | * CMakeLists.txt: Add call to find_package(GTest). | |
12 | (include_directories): Remove "src/googletest/googletest/include" from | |
13 | arg. | |
14 | * src/CMakeLists.txt[NOT GTEST_FOUND]: Define the gtest and gtest_main | |
15 | libraries when GTEST_FOUND is false. Globally include the googletest | |
16 | headers here. Define aliases for the gtest and gtest_main libraries | |
17 | that match those defined by the FindGTest module. | |
18 | * src/tests/CMakeLists.txt: Replace references to gtest_main and gtest | |
19 | by GTest::Main and GTest::GTest, respectively. | |
20 | --- | |
21 | CMakeLists.txt | 3 ++- | |
22 | src/CMakeLists.txt | 15 +++++++++++---- | |
23 | src/tests/CMakeLists.txt | 6 +++--- | |
24 | 3 files changed, 16 insertions(+), 8 deletions(-) | |
25 | ||
26 | diff --git a/CMakeLists.txt b/CMakeLists.txt | |
27 | index bfeb8f03..96fbd58c 100644 | |
28 | --- a/CMakeLists.txt | |
29 | +++ b/CMakeLists.txt | |
30 | @@ -25,13 +25,14 @@ find_package(DoubleConversion REQUIRED) | |
31 | find_package(PkgConfig REQUIRED) | |
32 | find_package(Cython) | |
33 | find_package(Threads) | |
34 | +find_package(GTest) | |
35 | pkg_check_modules(GTK3 gtk+-3.0) | |
36 | pkg_check_modules(GLIB glib-2.0) | |
37 | pkg_check_modules(CAIRO cairo) | |
38 | pkg_check_modules(GSL gsl) | |
39 | ||
40 | # Add global include and link directories | |
41 | -include_directories(src src/googletest/googletest/include ${CMAKE_CURRENT_BINARY_DIR}) | |
42 | +include_directories(src ${CMAKE_CURRENT_BINARY_DIR}) | |
43 | link_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/2geom) | |
44 | ||
45 | check_cxx_source_compiles("#include <math.h>\nint main() { double a=0.5,b=0.5,c=0.5; sincos(a, &b, &c); return 0; }" HAVE_SINCOS) | |
46 | diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt | |
47 | index eefb3ac5..941dc4c7 100644 | |
48 | --- a/src/CMakeLists.txt | |
49 | +++ b/src/CMakeLists.txt | |
50 | @@ -1,7 +1,14 @@ | |
51 | -add_library(gtest SHARED googletest/googletest/src/gtest-all.cc) | |
52 | -target_include_directories(gtest PRIVATE googletest/googletest) | |
53 | -target_link_libraries(gtest Threads::Threads) | |
54 | -add_library(gtest_main STATIC googletest/googletest/src/gtest_main.cc) | |
55 | +if(NOT GTEST_FOUND) | |
56 | + message("No system googletest library: using bundled copy.") | |
57 | + add_library(gtest SHARED googletest/googletest/src/gtest-all.cc) | |
58 | + add_library(gtest_main STATIC googletest/googletest/src/gtest_main.cc) | |
59 | + target_include_directories(gtest PRIVATE googletest/googletest) | |
60 | + target_link_libraries(gtest Threads::Threads) | |
61 | + include_directories(SYSTEM googletest/googletest/include) | |
62 | + # Aliases to share the same nomenclature with FindGTest. | |
63 | + add_library(GTest::GTest ALIAS gtest) | |
64 | + add_library(GTest::Main ALIAS gtest_main) | |
65 | +endif() | |
66 | ||
67 | add_subdirectory(2geom) | |
68 | add_subdirectory(tests) | |
69 | diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt | |
70 | index 626cfd87..3538f8cf 100644 | |
71 | --- a/src/tests/CMakeLists.txt | |
72 | +++ b/src/tests/CMakeLists.txt | |
73 | @@ -34,15 +34,15 @@ foreach(source ${2GEOM_GTESTS_SRC}) | |
74 | add_executable(${source} ${source}.cpp) | |
75 | target_include_directories(${source} PRIVATE ${GSL_INCLUDE_DIRS} | |
76 | ${GTK3_INCLUDE_DIRS} ${GLIB_INCLUDE_DIRS}) | |
77 | - target_link_libraries(${source} 2geom gtest_main gtest ${GSL_LIBRARIES} | |
78 | - ${GTK3_LIBRARIES} ${GLIB_LIBRARIES}) | |
79 | + target_link_libraries(${source} 2geom GTest::Main GTest::GTest | |
80 | + ${GSL_LIBRARIES} ${GTK3_LIBRARIES} ${GLIB_LIBRARIES}) | |
81 | add_test(NAME ${source} COMMAND ${source}) | |
82 | endforeach() | |
83 | ||
84 | foreach(source ${2GEOM_TESTS_SRC}) | |
85 | add_executable(${source} ${source}.cpp) | |
86 | target_include_directories(${source} PRIVATE ${GSL_INCLUDE_DIRS} ${GTK3_INCLUDE_DIRS}) | |
87 | - target_link_libraries(${source} 2geom gtest ${GSL_LIBRARIES} ${GTK3_LIBRARIES}) | |
88 | + target_link_libraries(${source} 2geom GTest::GTest ${GSL_LIBRARIES} ${GTK3_LIBRARIES}) | |
89 | add_test(NAME ${source} COMMAND ${source}) | |
90 | endforeach(source) | |
91 | ||
92 | -- | |
93 | 2.24.1 | |
94 |