Skip to content

Commit 8b224d4

Browse files
[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: http://svn.webkit.org/repository/webkit/trunk@220403 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent b422ebb commit 8b224d4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+489
-238
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ set(WebKit_LIBRARY_TYPE SHARED)
126126
set(WebKit2_LIBRARY_TYPE SHARED)
127127
set(WebCoreTestSupport_LIBRARY_TYPE STATIC)
128128

129+
set(CMAKE_POSITION_INDEPENDENT_CODE True)
130+
129131
# -----------------------------------------------------------------------------
130132
# Install JavaScript shell
131133
# -----------------------------------------------------------------------------

ChangeLog

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,45 @@
1+
2017-08-08 Michael Catanzaro <[email protected]>
2+
3+
[CMake] Properly test if compiler supports compiler flags
4+
https://bugs.webkit.org/show_bug.cgi?id=174490
5+
6+
Reviewed by Konstantin Tokarev.
7+
8+
This turned out to be a massive pain. I didn't want to merely check options before using
9+
them: I also wanted to organize the code to avoid setting similar flags in different places.
10+
Right now we set a bunch of global flags in OptionsCommon.cmake, and a bunch more flags in
11+
WEBKIT_SET_EXTRA_COMPILER_FLAGS on a per-target basis.
12+
13+
Setting flags per-target seems better in general, e.g. because it makes it very easy to
14+
disable warnings for particular ThirdParty targets. But it turns out that all the flags set
15+
on a per-target basis get passed to both the C compiler and the C++ compiler, so it's
16+
impossible to pass C++-only flags there. That's terrible. It's possible to make the flags
17+
language-conditional using generator expressions, but that doesn't work for the Visual
18+
Studio backend, so we would have to drop support for that (not going to happen). The CMake
19+
documentation suggests that C and C++ files ought to be built in separate targets to avoid
20+
this. It's a mess, basically.
21+
22+
So I've wound up removing WEBKIT_SET_EXTRA_COMPILER_FLAGS and adding most of those flags to
23+
CMAKE_C_FLAGS and CMAKE_CXX_FLAGS instead. Really the only disadvantage of this is we now
24+
have to suppress individual warnings when building ANGLESupport in WebCore. That's not the
25+
end of the world. The only remaining useful feature of WEBKIT_SET_EXTRA_COMPILER_FLAGS was
26+
to add -fPIC to static library targets, but turns out CMake does that for us if we just set
27+
the variable CMAKE_POSITION_INDEPENDENT_CODE, so we can get rid of it completely.
28+
29+
Of course there are also macros for setting target-specific compiler flags, which we
30+
frequently need in order to suppress specific warnings, particularly warnings coming from
31+
third-party libraries like ANGLE and gtest. But remember the footgun: these macros will test
32+
the flag against only one compiler, but must work with both C and C++ compilers unless the
33+
build target exclusively contains targets built with just one of those compilers. Yuck.
34+
35+
* CMakeLists.txt:
36+
* Source/CMakeLists.txt:
37+
* Source/PlatformGTK.cmake:
38+
* Source/cmake/OptionsCommon.cmake:
39+
* Source/cmake/WebKitCommon.cmake:
40+
* Source/cmake/WebKitCompilerFlags.cmake: Added.
41+
* Source/cmake/WebKitMacros.cmake:
42+
143
2017-08-07 Brian Burg <[email protected]>
244

345
Remove CANVAS_PATH compilation guard

Source/CMakeLists.txt

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -43,29 +43,3 @@ if (ENABLE_WEBDRIVER)
4343
endif ()
4444

4545
WEBKIT_INCLUDE_CONFIG_FILES_IF_EXISTS()
46-
47-
# -----------------------------------------------------------------------------
48-
# Set compiler flags for all targets
49-
# -----------------------------------------------------------------------------
50-
if (NOT USE_SYSTEM_MALLOC)
51-
WEBKIT_SET_EXTRA_COMPILER_FLAGS(bmalloc ${ADDITIONAL_COMPILER_FLAGS})
52-
endif ()
53-
WEBKIT_SET_EXTRA_COMPILER_FLAGS(WTF ${ADDITIONAL_COMPILER_FLAGS})
54-
WEBKIT_SET_EXTRA_COMPILER_FLAGS(JavaScriptCore ${ADDITIONAL_COMPILER_FLAGS})
55-
56-
if (ENABLE_WEBCORE)
57-
WEBKIT_SET_EXTRA_COMPILER_FLAGS(PAL ${ADDITIONAL_COMPILER_FLAGS})
58-
WEBKIT_SET_EXTRA_COMPILER_FLAGS(WebCoreTestSupport ${ADDITIONAL_COMPILER_FLAGS})
59-
WEBKIT_SET_EXTRA_COMPILER_FLAGS(WebCore ${ADDITIONAL_COMPILER_FLAGS})
60-
WEBKIT_SET_EXTRA_COMPILER_FLAGS(WebCoreDerivedSources ${ADDITIONAL_COMPILER_FLAGS})
61-
endif ()
62-
63-
if (ENABLE_WEBKIT_LEGACY)
64-
# FIXME: Rename this target to WebKitLegacy.
65-
WEBKIT_SET_EXTRA_COMPILER_FLAGS(WebKit ${ADDITIONAL_COMPILER_FLAGS})
66-
endif ()
67-
68-
if (ENABLE_WEBKIT)
69-
# FIXME: Rename this target to WebKit.
70-
WEBKIT_SET_EXTRA_COMPILER_FLAGS(WebKit2 ${ADDITIONAL_COMPILER_FLAGS})
71-
endif ()

Source/JavaScriptCore/API/tests/PingPongStackOverflowTest.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ int testPingPongStackOverflow()
142142
"PingPongStackOverflowObject.__proto__ = undefined;" \
143143
"undefined instanceof PingPongStackOverflowObject;";
144144

145-
JSValueRef scriptResult = nullptr;
146145
JSValueRef exception = nullptr;
147146
JSStringRef script = JSStringCreateWithUTF8CString(scriptString);
148147

@@ -161,7 +160,7 @@ int testPingPongStackOverflow()
161160
Options::maxPerThreadStackUsage() = stackSize + Options::softReservedZoneSize();
162161

163162
exception = nullptr;
164-
scriptResult = JSEvaluateScript(context, script, nullptr, nullptr, 1, &exception);
163+
JSEvaluateScript(context, script, nullptr, nullptr, 1, &exception);
165164

166165
if (!exception) {
167166
printf("FAIL: PingPongStackOverflowError not thrown in PingPongStackOverflow test\n");

Source/JavaScriptCore/API/tests/testapi.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,13 +1134,20 @@ static bool globalContextNameTest()
11341134
return result;
11351135
}
11361136

1137+
#if COMPILER(GCC)
1138+
#pragma GCC diagnostic push
1139+
#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
1140+
#endif
11371141
static void checkConstnessInJSObjectNames()
11381142
{
11391143
JSStaticFunction fun;
11401144
fun.name = "something";
11411145
JSStaticValue val;
11421146
val.name = "something";
11431147
}
1148+
#if COMPILER(GCC)
1149+
#pragma GCC diagnostic pop
1150+
#endif
11441151

11451152
#ifdef __cplusplus
11461153
extern "C" {

Source/JavaScriptCore/ChangeLog

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
2017-08-08 Michael Catanzaro <[email protected]>
2+
3+
[CMake] Properly test if compiler supports compiler flags
4+
https://bugs.webkit.org/show_bug.cgi?id=174490
5+
6+
Reviewed by Konstantin Tokarev.
7+
8+
* API/tests/PingPongStackOverflowTest.cpp:
9+
(testPingPongStackOverflow):
10+
* API/tests/testapi.c:
11+
* b3/testb3.cpp:
12+
(JSC::B3::testPatchpointLotsOfLateAnys):
13+
114
2017-08-06 Yusuke Suzuki <[email protected]>
215

316
[Linux] Clear WasmMemory with madvice instead of memset

Source/JavaScriptCore/b3/testb3.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8481,7 +8481,7 @@ void testPatchpointLotsOfLateAnys()
84818481
});
84828482
root->appendNewControlValue(proc, Return, Origin(), patchpoint);
84838483

8484-
CHECK(compileAndRun<int>(proc) == (things.size() * (things.size() - 1)) / 2);
8484+
CHECK(static_cast<size_t>(compileAndRun<int>(proc)) == (things.size() * (things.size() - 1)) / 2);
84858485
}
84868486

84878487
void testPatchpointAnyImm(ValueRep rep)

Source/PlatformGTK.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ macro(ADD_GTKDOC_GENERATOR _stamp_name _extra_args)
2424
add_custom_command(
2525
OUTPUT "${CMAKE_BINARY_DIR}/${_stamp_name}"
2626
DEPENDS ${DocumentationDependencies}
27-
COMMAND CC=${CMAKE_C_COMPILER} CFLAGS=${CMAKE_C_FLAGS} ${CMAKE_SOURCE_DIR}/Tools/gtk/generate-gtkdoc ${_extra_args}
27+
COMMAND ${CMAKE_COMMAND} -E env "CC=${CMAKE_C_COMPILER}" "CFLAGS=${CMAKE_C_FLAGS} -Wno-unused-parameter" ${CMAKE_SOURCE_DIR}/Tools/gtk/generate-gtkdoc ${_extra_args}
2828
COMMAND touch ${_stamp_name}
2929
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
30+
VERBATIM
3031
)
3132
endmacro()
3233

Source/ThirdParty/ChangeLog

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
2017-08-08 Michael Catanzaro <[email protected]>
2+
3+
[CMake] Properly test if compiler supports compiler flags
4+
https://bugs.webkit.org/show_bug.cgi?id=174490
5+
6+
Reviewed by Konstantin Tokarev.
7+
8+
* brotli/CMakeLists.txt:
9+
* gtest/CMakeLists.txt:
10+
* woff2/CMakeLists.txt:
11+
* xdgmime/CMakeLists.txt:
12+
113
2017-07-17 Michael Catanzaro <[email protected]>
214

315
[CMake] Macros in WebKitMacros.cmake should be prefixed with WEBKIT_ namespace

Source/ThirdParty/brotli/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ set(BROTLI_SOURCES
1515
include_directories("${BROTLI_INCLUDE_DIRECTORIES}")
1616
add_definitions(-DBROTLI_BUILD_PORTABLE)
1717
add_library(brotli STATIC ${BROTLI_SOURCES})
18-
WEBKIT_SET_EXTRA_COMPILER_FLAGS(brotli)
1918

2019
if (COMPILER_IS_GCC_OR_CLANG)
21-
WEBKIT_ADD_TARGET_PROPERTIES(brotli COMPILE_FLAGS "-Wno-cast-align -Wno-implicit-fallthrough")
20+
WEBKIT_ADD_TARGET_C_FLAGS(brotli -Wno-cast-align
21+
-Wno-implicit-fallthrough)
2222
endif ()

0 commit comments

Comments
 (0)