@@ -147,3 +147,53 @@ macro(add_llvm_external_project name)
147
147
endif ()
148
148
endif ()
149
149
endmacro (add_llvm_external_project )
150
+
151
+ # Generic support for adding a unittest.
152
+ function (add_unittest test_suite test_dirname )
153
+ string (REGEX MATCH "([^/]+)$" test_name ${test_dirname} )
154
+ if (CMAKE_BUILD_TYPE )
155
+ set (CMAKE_RUNTIME_OUTPUT_DIRECTORY
156
+ ${CMAKE_CURRENT_BINARY_DIR} /${test_dirname}/${CMAKE_BUILD_TYPE} )
157
+ else ()
158
+ set (CMAKE_RUNTIME_OUTPUT_DIRECTORY
159
+ ${CMAKE_CURRENT_BINARY_DIR} /${test_dirname} )
160
+ endif ()
161
+ if ( NOT LLVM_BUILD_TESTS )
162
+ set (EXCLUDE_FROM_ALL ON )
163
+ endif ()
164
+
165
+ add_llvm_executable (${test_name} ${ARGN} )
166
+ target_link_libraries (${test_name}
167
+ gtest
168
+ gtest_main
169
+ LLVMSupport # gtest needs it for raw_ostream.
170
+ )
171
+
172
+ add_dependencies (${test_suite} ${test_name} )
173
+ get_target_property (test_suite_folder ${test_suite} FOLDER )
174
+ if (NOT ${test_suite_folder} STREQUAL "NOTFOUND" )
175
+ set_property (TARGET ${test_name} PROPERTY FOLDER "${test_suite_folder} " )
176
+ endif ()
177
+
178
+ # Visual Studio 2012 only supports up to 8 template parameters in
179
+ # std::tr1::tuple by default, but gtest requires 10
180
+ if (MSVC AND MSVC_VERSION EQUAL 1700 )
181
+ set_property (TARGET ${test_name} APPEND PROPERTY COMPILE_DEFINITIONS _VARIADIC_MAX=10 )
182
+ endif ()
183
+
184
+ include_directories (${LLVM_MAIN_SRC_DIR} /utils/unittest/googletest/include )
185
+ set_property (TARGET ${test_name} APPEND PROPERTY COMPILE_DEFINITIONS GTEST_HAS_RTTI=0 )
186
+ if (LLVM_COMPILER_IS_GCC_COMPATIBLE )
187
+ set_property (TARGET ${test_name} APPEND_STRING PROPERTY COMPILE_FLAGS " -fno-rtti" )
188
+ elseif (MSVC )
189
+ set_property (TARGET ${test_name} APPEND_STRING PROPERTY COMPILE_FLAGS " /GR-" )
190
+ endif ()
191
+
192
+ if (NOT LLVM_ENABLE_THREADS )
193
+ set_property (TARGET ${test_name} APPEND PROPERTY COMPILE_DEFINITIONS GTEST_HAS_PTHREAD=0 )
194
+ endif ()
195
+
196
+ if (SUPPORTS_NO_VARIADIC_MACROS_FLAG )
197
+ set_property (TARGET ${test_name} APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-variadic-macros" )
198
+ endif ()
199
+ endfunction ()
0 commit comments