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 <simon.hausmann@qt.io>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Joerg Bornemann 2020-02-26 10:39:47 +01:00
parent fb2f42b604
commit 1a30a82830
3 changed files with 16 additions and 5 deletions

View File

@ -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}")

View File

@ -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 <sys/neutrino.h>
@ -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

View File

@ -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?!