diff options
author | Guy Harris <guy@alum.mit.edu> | 2015-10-15 19:57:57 -0700 |
---|---|---|
committer | Gerald Combs <gerald@wireshark.org> | 2015-10-19 21:17:52 +0000 |
commit | 08a20705b4d03cb4460e13d3c270077930a75310 (patch) | |
tree | f483dd45eee028bd295cb47e5b2fe1ee1e243763 /CMakeLists.txt | |
parent | b0b53fa5937aa7ba258427ca0f3581dba725230d (diff) |
Do -fPIC only if it's necessary.
Or, at least, undo the unconditional addition of -fPIC to
Qt5Widgets_EXECUTABLE_COMPILE_FLAGS, and add it back only if we need it
to compile a small test program that includes <QtCore>.
-fPIC still shows up for other reasons; perhaps we need to undo other
unconditional operations "helpfully" done by Qt5CoreConfigExtras.cmake.
Change-Id: I76c1b01b3dce7398e4115552bc4ff87bc775e027
Reviewed-on: https://code.wireshark.org/review/11079
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r-- | CMakeLists.txt | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index ef42eb651a..f39d3bc029 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -884,11 +884,55 @@ if(HAVE_LIBZLIB) include_directories(BEFORE ${ZLIB_INCLUDE_DIRS}) endif() if (Qt5Widgets_FOUND) + # # Qt5CoreConfigExtras.cmake in Qt 5.5.0 sets -fPIC unconditionally. # https://bugreports.qt.io/browse/QTBUG-47942 - if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") + # + # If it was added, we remove it, and then check whether it's + # necessary the same way we do for autotools, by checking + # whether we can compile and link a simple file with just + # + # #include <QtCore> + # int main() {} + # + # (Yes, check_XXX_source_compiles() should be renamed + # check_XXX_source_compiles_and_links().) + # + if ("${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}" MATCHES ".*-fPIC.*") list(REMOVE_ITEM Qt5Widgets_EXECUTABLE_COMPILE_FLAGS "-fPIC") - endif() # MSVC + set(CMAKE_REQUIRED_FLAGS ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}) + set(CMAKE_REQUIRED_INCLUDES ${Qt5Core_INCLUDE_DIRS}) + set(CMAKE_REQUIRED_LIBS ${Qt5Core_LIBRARIES}) + check_cxx_source_compiles( + "#include <QtCore> + int main() {}" + WORKS_WITHOUT_FPIC) + if (NOT WORKS_WITHOUT_FPIC) + # + # OK, it won't compile without -fPIC. Try adding it. + # + set(CMAKE_REQUIRED_FLAGS "-fPIC") + check_cxx_source_compiles( + "#include <QtCore> + int main() {}" + WORKS_WITH_FPIC) + if (NOT WORKS_WITH_FPIC) + # + # It won't build with -fPIC or without -fPIC, + # so we're hosed. + # + message(FATAL_ERROR "Couldn't compile Qt without -fPIC nor with -fPIC") + endif() + + # + # It compiles with -fPIC, so add it back. + # + list(APPEND Qt5Widgets_EXECUTABLE_COMPILE_FLAGS "-fPIC") + endif() + set(CMAKE_REQUIRED_FLAGS "") + set(CMAKE_REQUIRED_INCLUDES "") + set(CMAKE_REQUIRED_LIBS "") + endif() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}") set (QT_FOUND ON) set (QT_LIBRARIES ${Qt5Widgets_LIBRARIES} ${Qt5PrintSupport_LIBRARIES}) |