-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
168 lines (131 loc) · 5.68 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and
# other BLT Project Developers. See the top-level COPYRIGHT file for details
#
# SPDX-License-Identifier: (BSD-3-Clause)
set(_blt_tpl_targets) # tracks names of enabled tpl targets
if(ENABLE_TESTS)
include(CTest)
# Note: Users can pass extra compiler flags to gtest
# with the 'gtest_extra_flags' variable and extra
# compile definitions with the 'gtest_defines' variable.
# The following flag should be added to gtest's dependents,
# but not to gtest in shared Windows builds
if(WIN32 AND BUILD_SHARED_LIBS)
list(APPEND gtest_export_defines "-DGTEST_LINKED_AS_SHARED_LIBRARY=1")
endif()
# Explicitly enable/disable death tests
if(ENABLE_GTEST_DEATH_TESTS)
list(APPEND gtest_defines "-DGTEST_HAS_DEATH_TEST=1")
else()
list(APPEND gtest_defines "-DGTEST_HAS_DEATH_TEST=0")
endif()
if(gtest_disable_pthreads)
list(APPEND gtest_defines "-DGTEST_HAS_PTHREAD=0")
endif()
#
# Use BLT's ENABLE_GMOCK option to set the build options for
# gtest's cmake project
#
if(ENABLE_GMOCK)
# In BLT ENABLE_GMOCK implies ENABLE_GTEST,
# IF ENABLE_GTEST is OFF, force to ON
if(NOT ENABLE_GTEST)
set(ENABLE_GTEST ON CACHE BOOL "")
endif()
set(BUILD_GMOCK ON CACHE BOOL "")
set(BUILD_GTEST OFF CACHE BOOL "")
else()
set(BUILD_GMOCK OFF CACHE BOOL "")
set(BUILD_GTEST ON CACHE BOOL "")
endif()
message(STATUS "Google Test Support is ${ENABLE_GTEST}")
message(STATUS "Google Mock Support is ${ENABLE_GMOCK}")
#
# Guard of googletest w/ ENABLE_GTEST
# In BLT, ENABLE_GTEST is also required when using ENABLE_GMOCK
#
if(ENABLE_GTEST)
#
# gtest 1.8 emits many warnings related to dll-interface
# issues on windows, so we add flags to work around these
# warnings, so they don't mask warnings we care about
#
# For more info see: https://github.com/LLNL/blt/issues/79
#
blt_append_custom_compiler_flag( FLAGS_VAR gtest_extra_flags
DEFAULT " "
MSVC "/wd4251" "/wd4275" )
set (INSTALL_GMOCK OFF CACHE BOOL "")
set (INSTALL_GTEST OFF CACHE BOOL "")
# Enable builtin google test
add_subdirectory(googletest-master-2018-02-01
${BLT_BUILD_DIR}/thirdparty_builtin/googletest-master-2018-02-01)
if(UNIX AND NOT APPLE)
find_package( Threads )
set(gtest_extra_libs ${CMAKE_THREAD_LIBS_INIT})
endif()
blt_register_library(NAME gtest
INCLUDES ${gtest_SOURCE_DIR}/include
LIBRARIES gtest_main gtest ${gtest_extra_libs}
COMPILE_FLAGS ${gtest_extra_flags}
DEFINES ${gtest_defines} ${gtest_export_defines}
TREAT_INCLUDES_AS_SYSTEM ON
)
blt_add_target_definitions(TO gtest TARGET_DEFINITIONS ${gtest_defines})
list(APPEND _blt_tpl_targets gtest gtest_main)
if(ENABLE_GMOCK)
blt_register_library(NAME gmock
INCLUDES ${gmock_SOURCE_DIR}/include
LIBRARIES gmock_main gmock
COMPILE_FLAGS ${gtest_extra_flags}
DEFINES ${gtest_defines}
TREAT_INCLUDES_AS_SYSTEM ON
)
list(APPEND _blt_tpl_targets gmock gmock_main)
endif()
endif()
# Enable Fruit (FortRan UnIT testing) support
if (ENABLE_FORTRAN)
message(STATUS "Fruit Support is ${ENABLE_FRUIT}")
if(ENABLE_FRUIT)
add_subdirectory(fruit-3.4.1
${BLT_BUILD_DIR}/thirdparty_builtin/fruit-3.4.1)
list(APPEND _blt_tpl_targets fruit)
endif()
endif()
endif()
if(ENABLE_BENCHMARKS)
if(NOT ENABLE_TESTS)
message(FATAL_ERROR "ENABLE_BENCHMARKS requires ENABLE_TESTS to be ON")
endif()
message(STATUS "Google Benchmark Support is ${ENABLE_GBENCHMARK}")
if(ENABLE_GBENCHMARK)
if(WIN32 AND BUILD_SHARED_LIBS)
message(FATAL_ERROR "Google Benchmark cannot be built when BUILD_SHARED_LIBS=ON or on Windows")
endif()
if(CMAKE_CXX_STANDARD LESS 11)
message(WARNING "C++11 is required to compile gbenchmark.")
endif()
set(BENCHMARK_ENABLE_TESTING OFF CACHE "" BOOL)
add_subdirectory(benchmark-1.5.0
${BLT_BUILD_DIR}/thirdparty_builtin/benchmark-1.5.0)
if (UNIX AND NOT APPLE)
find_library(RT_LIBRARIES rt)
endif()
blt_register_library(NAME gbenchmark
INCLUDES ${benchmark_SOURCE_DIR}/include ${benchmark_SOURCE_DIR}
LIBRARIES benchmark ${RT_LIBRARIES}
TREAT_INCLUDES_AS_SYSTEM ON)
list(APPEND _blt_tpl_targets gbenchmark)
endif()
# This sets up a target to run the benchmarks
add_custom_target(${BLT_RUN_BENCHMARKS_TARGET_NAME}
COMMAND ctest -C Benchmark -VV
WORKING_DIRECTORY ${PROJECT_BINARY_DIR})
endif()
# Set the folder property of the blt thirdparty libraries
if(ENABLE_FOLDERS)
foreach(tpl ${_blt_tpl_targets})
blt_set_target_folder(TARGET ${tpl} FOLDER blt/thirdparty)
endforeach()
endif()