From 1a30a828307ac1a27cb20e7b25fe9cb722497631 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Wed, 26 Feb 2020 10:39:47 +0100 Subject: [PATCH] CMake: Fix stack-protector-strong test and feature And in order to do this we must teach qt_config_compile_test a COMPILE_OPTIONS argument. Change-Id: I66fa45142b544e3a2fc599af1c1a4c69b442b318 Reviewed-by: Simon Hausmann Reviewed-by: Alexandru Croitor --- cmake/QtFeature.cmake | 7 +++++-- configure.cmake | 8 ++++++-- util/cmake/configurejson2cmake.py | 6 +++++- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/cmake/QtFeature.cmake b/cmake/QtFeature.cmake index bb77ca6ffa..7b852b3c2e 100644 --- a/cmake/QtFeature.cmake +++ b/cmake/QtFeature.cmake @@ -625,7 +625,8 @@ function(qt_config_compile_test name) return() endif() - cmake_parse_arguments(arg "" "LABEL;PROJECT_PATH;C_STANDARD;CXX_STANDARD" "LIBRARIES;CODE" ${ARGN}) + cmake_parse_arguments(arg "" "LABEL;PROJECT_PATH;C_STANDARD;CXX_STANDARD" + "COMPILE_OPTIONS;LIBRARIES;CODE" ${ARGN}) if(arg_PROJECT_PATH) message(STATUS "Performing Test ${arg_LABEL}") @@ -664,6 +665,8 @@ function(qt_config_compile_test name) set(CMAKE_CXX_STANDARD "${arg_CXX_STANDARD}") endif() + set(CMAKE_REQUIRED_FLAGS ${arg_COMPILE_OPTIONS}) + # For MSVC we need to explicitly pass -Zc:__cplusplus to get correct __cplusplus # define values. According to common/msvc-version.conf the flag is supported starting # with 1913. @@ -671,7 +674,7 @@ function(qt_config_compile_test name) # No support for the flag in upstream CMake as of 3.17. # https://gitlab.kitware.com/cmake/cmake/issues/18837 if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND MSVC_VERSION GREATER_EQUAL 1913) - set(CMAKE_REQUIRED_FLAGS "-Zc:__cplusplus") + list(APPEND CMAKE_REQUIRED_FLAGS "-Zc:__cplusplus") endif() set(_save_CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}") diff --git a/configure.cmake b/configure.cmake index cfb1d58604..45f5ba0ef4 100644 --- a/configure.cmake +++ b/configure.cmake @@ -283,6 +283,7 @@ alloca(1); # stack_protector qt_config_compile_test(stack_protector LABEL "stack protection" + COMPILE_OPTIONS -fstack-protector-strong CODE "#ifdef __QNXNTO__ # include @@ -300,8 +301,7 @@ int main(int argc, char **argv) /* END TEST: */ return 0; } -"# FIXME: qmake: QMAKE_CXXFLAGS += -fstack-protector-strong -) +") @@ -619,6 +619,10 @@ qt_feature("alloca" PRIVATE LABEL "alloca()" CONDITION QT_FEATURE_alloca_h OR QT_FEATURE_alloca_malloc_h OR TEST_alloca_stdlib_h ) +qt_feature("stack-protector-strong" PRIVATE + LABEL "stack protection" + CONDITION QNX AND TEST_stack_protector +) qt_feature("system-zlib" PRIVATE LABEL "Using system zlib" CONDITION ZLIB_FOUND diff --git a/util/cmake/configurejson2cmake.py b/util/cmake/configurejson2cmake.py index f479732406..f22ff2a3c6 100755 --- a/util/cmake/configurejson2cmake.py +++ b/util/cmake/configurejson2cmake.py @@ -584,6 +584,7 @@ endif() librariesCmakeName = "" languageStandard = "" + compileOptions = "" qmakeFixme = "" cm_fh.write(f"# {test}\n") @@ -612,6 +613,8 @@ endif() languageStandard = "CXX_STANDARD 17" elif details["qmake"] == "CONFIG += c++11 c++14 c++17 c++2a": languageStandard = "CXX_STANDARD 20" + elif details["qmake"] == "QMAKE_CXXFLAGS += -fstack-protector-strong": + compileOptions = details["qmake"][18:] else: qmakeFixme = f"# FIXME: qmake: {details['qmake']}\n" @@ -637,6 +640,8 @@ endif() cm_fh.write(" ") cm_fh.write("\n ".join(library_list)) cm_fh.write("\n") + if compileOptions != "": + cm_fh.write(f" COMPILE_OPTIONS {compileOptions}\n") cm_fh.write(" CODE\n") cm_fh.write('"' + sourceCode + '"') if qmakeFixme != "": @@ -755,7 +760,6 @@ def parseFeature(ctx, feature, data, cm_fh): "shared": None, "silent": None, "sql-sqlite": {"condition": "QT_FEATURE_datestring AND SQLite3_FOUND"}, - "stack-protector-strong": None, "static": None, "static_runtime": None, "stl": None, # Do we really need to test for this in 2018?!