[CMake] Properly test if compiler supports compiler flags
authormcatanzaro@igalia.com <mcatanzaro@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 8 Aug 2017 15:03:48 +0000 (15:03 +0000)
committermcatanzaro@igalia.com <mcatanzaro@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 8 Aug 2017 15:03:48 +0000 (15:03 +0000)
commitc04c2d4522cdd0b913b050f7eaec84e8e5a1d057
tree560da523dbf43b05a28ba70226ed4b0c73c405ce
parent67893dcf7d528697a9e090cf048935910d53f73c
[CMake] Properly test if compiler supports compiler flags
https://bugs.webkit.org/show_bug.cgi?id=174490

Reviewed by Konstantin Tokarev.

.:

This turned out to be a massive pain. I didn't want to merely check options before using
them: I also wanted to organize the code to avoid setting similar flags in different places.
Right now we set a bunch of global flags in OptionsCommon.cmake, and a bunch more flags in
WEBKIT_SET_EXTRA_COMPILER_FLAGS on a per-target basis.

Setting flags per-target seems better in general, e.g. because it makes it very easy to
disable warnings for particular ThirdParty targets. But it turns out that all the flags set
on a per-target basis get passed to both the C compiler and the C++ compiler, so it's
impossible to pass C++-only flags there. That's terrible. It's possible to make the flags
language-conditional using generator expressions, but that doesn't work for the Visual
Studio backend, so we would have to drop support for that (not going to happen). The CMake
documentation suggests that C and C++ files ought to be built in separate targets to avoid
this. It's a mess, basically.

So I've wound up removing WEBKIT_SET_EXTRA_COMPILER_FLAGS and adding most of those flags to
CMAKE_C_FLAGS and CMAKE_CXX_FLAGS instead. Really the only disadvantage of this is we now
have to suppress individual warnings when building ANGLESupport in WebCore. That's not the
end of the world. The only remaining useful feature of WEBKIT_SET_EXTRA_COMPILER_FLAGS was
to add -fPIC to static library targets, but turns out CMake does that for us if we just set
the variable CMAKE_POSITION_INDEPENDENT_CODE, so we can get rid of it completely.

Of course there are also macros for setting target-specific compiler flags, which we
frequently need in order to suppress specific warnings, particularly warnings coming from
third-party libraries like ANGLE and gtest. But remember the footgun: these macros will test
the flag against only one compiler, but must work with both C and C++ compilers unless the
build target exclusively contains targets built with just one of those compilers. Yuck.

* CMakeLists.txt:
* Source/CMakeLists.txt:
* Source/PlatformGTK.cmake:
* Source/cmake/OptionsCommon.cmake:
* Source/cmake/WebKitCommon.cmake:
* Source/cmake/WebKitCompilerFlags.cmake: Added.
* Source/cmake/WebKitMacros.cmake:

Source/JavaScriptCore:

* API/tests/PingPongStackOverflowTest.cpp:
(testPingPongStackOverflow):
* API/tests/testapi.c:
* b3/testb3.cpp:
(JSC::B3::testPatchpointLotsOfLateAnys):

Source/ThirdParty:

* brotli/CMakeLists.txt:
* gtest/CMakeLists.txt:
* woff2/CMakeLists.txt:
* xdgmime/CMakeLists.txt:

Source/WebCore:

* CMakeLists.txt:
* PlatformGTK.cmake:
* PlatformWPE.cmake:

Source/WebDriver:

* WebDriverService.cpp:
(WebDriver::WebDriverService::run):
* glib/SessionHostGlib.cpp:

Source/WebKit:

* CMakeLists.txt:
* PlatformGTK.cmake:

Source/WTF:

* wtf/Compiler.h:

Tools:

* DumpRenderTree/TestNetscapePlugIn/CMakeLists.txt:
* MiniBrowser/gtk/CMakeLists.txt:
* TestRunnerShared/Bindings/JSWrapper.cpp:
(WTR::JSWrapper::initialize):
* TestWebKitAPI/CMakeLists.txt:
* TestWebKitAPI/PlatformGTK.cmake:
* TestWebKitAPI/Tests/WTF/CheckedArithmeticOperations.cpp:
(TestWebKitAPI::CheckedArithmeticTester::run):
* TestWebKitAPI/Tests/WebKitGLib/TestAutomationSession.cpp:
* TestWebKitAPI/Tests/WebKitGLib/TestWebExtensions.cpp:
* TestWebKitAPI/Tests/WebKitGLib/WebExtensionTest.cpp:
(formControlsAssociatedCallback):
* TestWebKitAPI/glib/CMakeLists.txt:
* TestWebKitAPI/glib/WebKitGLib/TestMain.h:
(Test::getResourcesDir):
* WebKitTestRunner/CMakeLists.txt:
* WebKitTestRunner/InjectedBundle/EventSendingController.cpp:
(WTR::menuItemClickCallback):
(WTR::staticConvertMenuItemToType):
* WebKitTestRunner/InjectedBundle/TestRunner.cpp:
(WTR::TestRunner::setUseDashboardCompatibilityMode):
* WebKitTestRunner/InjectedBundle/atk/AccessibilityNotificationHandlerAtk.cpp:
(WTR::AccessibilityNotificationHandler::disconnectAccessibilityCallbacks):
* WebKitTestRunner/InjectedBundle/atk/AccessibilityUIElementAtk.cpp:
(WTR::AccessibilityUIElement::helpText const):
(WTR::AccessibilityUIElement::attributedStringForRange):
* WebKitTestRunner/gtk/EventSenderProxyGtk.cpp:
(WTR::EventSenderProxy::updateTouchPoint):
(WTR::EventSenderProxy::releaseTouchPoint):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@220403 268f45cc-cd09-0410-ab3c-d52691b4dbfc
47 files changed:
CMakeLists.txt
ChangeLog
Source/CMakeLists.txt
Source/JavaScriptCore/API/tests/PingPongStackOverflowTest.cpp
Source/JavaScriptCore/API/tests/testapi.c
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/b3/testb3.cpp
Source/PlatformGTK.cmake
Source/ThirdParty/ChangeLog
Source/ThirdParty/brotli/CMakeLists.txt
Source/ThirdParty/gtest/CMakeLists.txt
Source/ThirdParty/woff2/CMakeLists.txt
Source/ThirdParty/xdgmime/CMakeLists.txt
Source/WTF/ChangeLog
Source/WTF/wtf/Compiler.h
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/PlatformGTK.cmake
Source/WebCore/PlatformWPE.cmake
Source/WebDriver/ChangeLog
Source/WebDriver/WebDriverService.cpp
Source/WebDriver/glib/SessionHostGlib.cpp
Source/WebKit/CMakeLists.txt
Source/WebKit/ChangeLog
Source/WebKit/PlatformGTK.cmake
Source/cmake/OptionsCommon.cmake
Source/cmake/WebKitCommon.cmake
Source/cmake/WebKitCompilerFlags.cmake [new file with mode: 0644]
Source/cmake/WebKitMacros.cmake
Tools/ChangeLog
Tools/DumpRenderTree/TestNetscapePlugIn/CMakeLists.txt
Tools/MiniBrowser/gtk/CMakeLists.txt
Tools/TestRunnerShared/Bindings/JSWrapper.cpp
Tools/TestWebKitAPI/CMakeLists.txt
Tools/TestWebKitAPI/PlatformGTK.cmake
Tools/TestWebKitAPI/Tests/WTF/CheckedArithmeticOperations.cpp
Tools/TestWebKitAPI/Tests/WebKitGLib/TestAutomationSession.cpp
Tools/TestWebKitAPI/Tests/WebKitGLib/TestWebExtensions.cpp
Tools/TestWebKitAPI/Tests/WebKitGLib/WebExtensionTest.cpp
Tools/TestWebKitAPI/glib/CMakeLists.txt
Tools/TestWebKitAPI/glib/WebKitGLib/TestMain.h
Tools/WebKitTestRunner/CMakeLists.txt
Tools/WebKitTestRunner/InjectedBundle/EventSendingController.cpp
Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp
Tools/WebKitTestRunner/InjectedBundle/atk/AccessibilityNotificationHandlerAtk.cpp
Tools/WebKitTestRunner/InjectedBundle/atk/AccessibilityUIElementAtk.cpp
Tools/WebKitTestRunner/gtk/EventSenderProxyGtk.cpp