[CMake] Properly test if compiler supports compiler flags
[WebKit-https.git] / Tools / TestWebKitAPI / CMakeLists.txt
1 set(TESTWEBKITAPI_DIR "${TOOLS_DIR}/TestWebKitAPI")
2 set(test_wtf_LIBRARIES
3     WTF${DEBUG_SUFFIX}
4     gtest
5 )
6
7 set(test_webcore_LIBRARIES
8     WTF${DEBUG_SUFFIX}
9     WebCore${DEBUG_SUFFIX}
10     gtest
11 )
12
13 set(TestWebKitAPI_LIBRARIES
14     WTF${DEBUG_SUFFIX}
15 )
16
17 if (ENABLE_WEBKIT)
18     set(test_webkit2_api_LIBRARIES
19         JavaScriptCore
20         TestWebKitAPIBase
21         WTF
22         WebKit2
23         gtest
24     )
25     list(APPEND TestWebKitAPI_LIBRARIES
26         WebKit2
27     )
28 else ()
29     list(APPEND TestWebKitAPI_LIBRARIES
30         WebKit${DEBUG_SUFFIX}
31     )
32 endif ()
33
34
35 set(TestJavaScriptCore_LIBRARIES
36     JavaScriptCore
37     gtest
38 )
39
40 set(TestWTF_SOURCES
41     ${TESTWEBKITAPI_DIR}/Counters.cpp
42     ${TESTWEBKITAPI_DIR}/TestsController.cpp
43     ${TESTWEBKITAPI_DIR}/Tests/WTF/AtomicString.cpp
44     ${TESTWEBKITAPI_DIR}/Tests/WTF/BloomFilter.cpp
45     ${TESTWEBKITAPI_DIR}/Tests/WTF/CrossThreadTask.cpp
46     ${TESTWEBKITAPI_DIR}/Tests/WTF/CString.cpp
47     ${TESTWEBKITAPI_DIR}/Tests/WTF/CheckedArithmeticOperations.cpp
48     ${TESTWEBKITAPI_DIR}/Tests/WTF/Condition.cpp
49     ${TESTWEBKITAPI_DIR}/Tests/WTF/DateMath.cpp
50     ${TESTWEBKITAPI_DIR}/Tests/WTF/Deque.cpp
51     ${TESTWEBKITAPI_DIR}/Tests/WTF/EnumTraits.cpp
52     ${TESTWEBKITAPI_DIR}/Tests/WTF/Expected.cpp
53     ${TESTWEBKITAPI_DIR}/Tests/WTF/Function.cpp
54     ${TESTWEBKITAPI_DIR}/Tests/WTF/HashCountedSet.cpp
55     ${TESTWEBKITAPI_DIR}/Tests/WTF/HashMap.cpp
56     ${TESTWEBKITAPI_DIR}/Tests/WTF/HashSet.cpp
57     ${TESTWEBKITAPI_DIR}/Tests/WTF/IntegerToStringConversion.cpp
58     ${TESTWEBKITAPI_DIR}/Tests/WTF/LifecycleLogger.cpp
59     ${TESTWEBKITAPI_DIR}/Tests/WTF/ListHashSet.cpp
60     ${TESTWEBKITAPI_DIR}/Tests/WTF/Lock.cpp
61     ${TESTWEBKITAPI_DIR}/Tests/WTF/Logger.cpp
62     ${TESTWEBKITAPI_DIR}/Tests/WTF/MD5.cpp
63     ${TESTWEBKITAPI_DIR}/Tests/WTF/MathExtras.cpp
64     ${TESTWEBKITAPI_DIR}/Tests/WTF/MediaTime.cpp
65     ${TESTWEBKITAPI_DIR}/Tests/WTF/MetaAllocator.cpp
66     ${TESTWEBKITAPI_DIR}/Tests/WTF/NakedPtr.cpp
67     ${TESTWEBKITAPI_DIR}/Tests/WTF/NeverDestroyed.cpp
68     ${TESTWEBKITAPI_DIR}/Tests/WTF/Optional.cpp
69     ${TESTWEBKITAPI_DIR}/Tests/WTF/OptionSet.cpp
70     ${TESTWEBKITAPI_DIR}/Tests/WTF/ParkingLot.cpp
71     ${TESTWEBKITAPI_DIR}/Tests/WTF/RedBlackTree.cpp
72     ${TESTWEBKITAPI_DIR}/Tests/WTF/Ref.cpp
73     ${TESTWEBKITAPI_DIR}/Tests/WTF/RefCounter.cpp
74     ${TESTWEBKITAPI_DIR}/Tests/WTF/RefLogger.cpp
75     ${TESTWEBKITAPI_DIR}/Tests/WTF/RefPtr.cpp
76     ${TESTWEBKITAPI_DIR}/Tests/WTF/SHA1.cpp
77     ${TESTWEBKITAPI_DIR}/Tests/WTF/SaturatedArithmeticOperations.cpp
78     ${TESTWEBKITAPI_DIR}/Tests/WTF/Scope.cpp
79     ${TESTWEBKITAPI_DIR}/Tests/WTF/ScopedLambda.cpp
80     ${TESTWEBKITAPI_DIR}/Tests/WTF/SetForScope.cpp
81     ${TESTWEBKITAPI_DIR}/Tests/WTF/StringBuilder.cpp
82     ${TESTWEBKITAPI_DIR}/Tests/WTF/StringHasher.cpp
83     ${TESTWEBKITAPI_DIR}/Tests/WTF/StringImpl.cpp
84     ${TESTWEBKITAPI_DIR}/Tests/WTF/StringOperators.cpp
85     ${TESTWEBKITAPI_DIR}/Tests/WTF/StringView.cpp
86     ${TESTWEBKITAPI_DIR}/Tests/WTF/TextBreakIterator.cpp
87     ${TESTWEBKITAPI_DIR}/Tests/WTF/ThreadGroup.cpp
88     ${TESTWEBKITAPI_DIR}/Tests/WTF/Time.cpp
89     ${TESTWEBKITAPI_DIR}/Tests/WTF/UniqueRef.cpp
90     ${TESTWEBKITAPI_DIR}/Tests/WTF/Variant.cpp
91     ${TESTWEBKITAPI_DIR}/Tests/WTF/Vector.cpp
92     ${TESTWEBKITAPI_DIR}/Tests/WTF/WTFString.cpp
93     ${TESTWEBKITAPI_DIR}/Tests/WTF/WeakPtr.cpp
94     ${TESTWEBKITAPI_DIR}/Tests/WTF/WorkQueue.cpp
95 )
96
97 # FIXME: Tests/WTF/RunLoop.cpp is missing because it doesn't work for Windows.
98 # FIXME: Platform-specific sources in Tests/WTF are not included in TestWTF_SOURCES.
99
100 WEBKIT_INCLUDE_CONFIG_FILES_IF_EXISTS()
101
102 include_directories(
103     ${TESTWEBKITAPI_DIR}
104     ${CMAKE_BINARY_DIR}
105     ${CMAKE_SOURCE_DIR}/Source
106     ${JAVASCRIPTCORE_DIR}
107     ${PAL_DIR}
108     ${THIRDPARTY_DIR}/gtest/include
109     ${WEBKIT2_DIR}/Platform/IPC
110     ${WEBKIT2_DIR}/Shared
111     ${WEBKIT2_DIR}/Shared/API
112     ${WEBKIT2_DIR}/Shared/API/c
113     ${WEBKIT2_DIR}/Shared/Plugins
114     ${WEBKIT2_DIR}/UIProcess
115     ${WEBKIT2_DIR}/UIProcess/API
116     ${WEBKIT2_DIR}/WebProcess/InjectedBundle
117     ${WEBKIT2_DIR}/WebProcess/InjectedBundle/API/c
118 )
119
120 if (ENABLE_WEBKIT)
121     add_library(TestWebKitAPIInjectedBundle SHARED
122         ${bundle_harness_SOURCES}
123         ${TESTWEBKITAPI_DIR}/InjectedBundleController.cpp
124         ${TESTWEBKITAPI_DIR}/InjectedBundleMain.cpp
125         ${TESTWEBKITAPI_DIR}/PlatformUtilities.cpp
126         ${TESTWEBKITAPI_DIR}/Tests/WebKit2/CanHandleRequest_Bundle.cpp
127         ${TESTWEBKITAPI_DIR}/Tests/WebKit2/DidAssociateFormControls_Bundle.cpp
128         ${TESTWEBKITAPI_DIR}/Tests/WebKit2/DOMWindowExtensionBasic_Bundle.cpp
129         ${TESTWEBKITAPI_DIR}/Tests/WebKit2/DOMWindowExtensionNoCache_Bundle.cpp
130         ${TESTWEBKITAPI_DIR}/Tests/WebKit2/DocumentStartUserScriptAlertCrash_Bundle.cpp
131         ${TESTWEBKITAPI_DIR}/Tests/WebKit2/GetInjectedBundleInitializationUserDataCallback_Bundle.cpp
132         ${TESTWEBKITAPI_DIR}/Tests/WebKit2/HitTestResultNodeHandle_Bundle.cpp
133         ${TESTWEBKITAPI_DIR}/Tests/WebKit2/InjectedBundleBasic_Bundle.cpp
134         ${TESTWEBKITAPI_DIR}/Tests/WebKit2/InjectedBundleFrameHitTest_Bundle.cpp
135         ${TESTWEBKITAPI_DIR}/Tests/WebKit2/InjectedBundleInitializationUserDataCallbackWins_Bundle.cpp
136         ${TESTWEBKITAPI_DIR}/Tests/WebKit2/LoadCanceledNoServerRedirectCallback_Bundle.cpp
137         ${TESTWEBKITAPI_DIR}/Tests/WebKit2/MouseMoveAfterCrash_Bundle.cpp
138         ${TESTWEBKITAPI_DIR}/Tests/WebKit2/NewFirstVisuallyNonEmptyLayoutFails_Bundle.cpp
139         ${TESTWEBKITAPI_DIR}/Tests/WebKit2/NewFirstVisuallyNonEmptyLayoutForImages_Bundle.cpp
140         ${TESTWEBKITAPI_DIR}/Tests/WebKit2/NewFirstVisuallyNonEmptyLayoutFrames_Bundle.cpp
141         ${TESTWEBKITAPI_DIR}/Tests/WebKit2/NewFirstVisuallyNonEmptyLayout_Bundle.cpp
142         ${TESTWEBKITAPI_DIR}/Tests/WebKit2/ParentFrame_Bundle.cpp
143         ${TESTWEBKITAPI_DIR}/Tests/WebKit2/ProvisionalURLAfterWillSendRequestCallback_Bundle.cpp
144         ${TESTWEBKITAPI_DIR}/Tests/WebKit2/ResponsivenessTimerDoesntFireEarly_Bundle.cpp
145         ${TESTWEBKITAPI_DIR}/Tests/WebKit2/ShouldGoToBackForwardListItem_Bundle.cpp
146         ${TESTWEBKITAPI_DIR}/Tests/WebKit2/TextFieldDidBeginAndEndEditing_Bundle.cpp
147         ${TESTWEBKITAPI_DIR}/Tests/WebKit2/UserMessage_Bundle.cpp
148         ${TESTWEBKITAPI_DIR}/Tests/WebKit2/WillLoad_Bundle.cpp
149         ${TESTWEBKITAPI_DIR}/Tests/WebKit2/WillSendSubmitEvent_Bundle.cpp
150     )
151
152     target_link_libraries(TestWebKitAPIInjectedBundle ${TestWebKitAPI_LIBRARIES})
153     add_dependencies(TestWebKitAPIInjectedBundle WTF ${ForwardingHeadersForTestWebKitAPI_NAME})
154
155     if (COMPILER_IS_GCC_OR_CLANG)
156         WEBKIT_ADD_TARGET_CXX_FLAGS(TestWebKitAPIInjectedBundle -Wno-dangling-else
157                                                                 -Wno-sign-compare
158                                                                 -Wno-undef
159                                                                 -Wno-unused-parameter)
160     endif ()
161 endif ()
162
163 if (WIN32)
164     add_definitions(-DGTEST_LINKED_AS_SHARED_LIBRARY=0)
165 else ()
166     add_definitions(-DGTEST_LINKED_AS_SHARED_LIBRARY=1)
167 endif ()
168
169 add_definitions(-DGTEST_HAS_RTTI=0
170     -DTEST_WEBKIT2_RESOURCES_DIR=\"${TESTWEBKITAPI_DIR}/Tests/WebKit\"
171 )
172
173 # FIXME: This works around compatibility problems in the old version of the third-pary
174 # googletest source code checkout. It should be removed once we upgrade to a newer version.
175 if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
176     add_definitions(-DGTEST_HAS_TR1_TUPLE=0)
177 endif ()
178
179 add_executable(TestWTF
180     ${test_main_SOURCES}
181     ${TestWTF_SOURCES}
182 )
183
184 if (WIN32)
185     add_dependencies(TestWTF TestWTFLib)
186 endif ()
187
188 target_link_libraries(TestWTF ${test_wtf_LIBRARIES})
189 add_dependencies(TestWTF WTF ${ForwardingHeadersForTestWebKitAPI_NAME} ${ForwardingNetworkHeadersForTestWebKitAPI_NAME})
190 add_test(TestWTF ${TESTWEBKITAPI_RUNTIME_OUTPUT_DIRECTORY_WTF}/TestWTF)
191 set_tests_properties(TestWTF PROPERTIES TIMEOUT 60)
192 set_target_properties(TestWTF PROPERTIES
193     RUNTIME_OUTPUT_DIRECTORY ${TESTWEBKITAPI_RUNTIME_OUTPUT_DIRECTORY_WTF}
194 )
195
196 if (COMPILER_IS_GCC_OR_CLANG)
197     WEBKIT_ADD_TARGET_CXX_FLAGS(TestWTF -Wno-dangling-else
198                                         -Wno-sign-compare
199                                         -Wno-undef
200                                         -Wno-unused-parameter)
201 endif ()
202
203 if (ENABLE_WEBKIT)
204     add_library(TestWebKitAPIBase
205         ${test_main_SOURCES}
206         ${webkit2_api_harness_SOURCES}
207         ${TESTWEBKITAPI_DIR}/JavaScriptTest.cpp
208         ${TESTWEBKITAPI_DIR}/PlatformUtilities.cpp
209         ${TESTWEBKITAPI_DIR}/TestsController.cpp
210     )
211
212     target_link_libraries(TestWebKitAPIBase JavaScriptCore WTF WebKit2 gtest)
213
214     add_dependencies(TestWebKitAPIBase WebKit2 ${ForwardingHeadersForTestWebKitAPI_NAME} ${ForwardingNetworkHeadersForTestWebKitAPI_NAME})
215
216     if (COMPILER_IS_GCC_OR_CLANG)
217         WEBKIT_ADD_TARGET_CXX_FLAGS(TestWebKitAPIBase -Wno-sign-compare
218                                                       -Wno-undef
219                                                       -Wno-unused-parameter)
220     endif ()
221 endif ()