CMake: Handle -D, -I, -F and -L configure arguments

Introduce new CMake variables and map
-D to QT_EXTRA_DEFINES,
-I to QT_EXTRA_INCLUDEPATHS,
-L to QT_EXTRA_LIBDIRS,
and -F to QT_EXTRA_FRAMEWORKPATHS.

Those variables only affect the Qt build, not user projects.

Fixes: QTBUG-85878
Change-Id: I229df2eed1505a2619068d0d32975962b052569a
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Joerg Bornemann 2020-08-13 14:36:50 +02:00
parent a930e657ed
commit d6e41abd62
6 changed files with 75 additions and 4 deletions

View File

@ -187,6 +187,25 @@ if (GCC AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "9.2")
target_compile_options(PlatformCommonInternal INTERFACE $<$<COMPILE_LANGUAGE:CXX>:-Wsuggest-override>)
endif()
if(DEFINED QT_EXTRA_DEFINES)
target_compile_definitions(PlatformCommonInternal INTERFACE ${QT_EXTRA_DEFINES})
endif()
if(DEFINED QT_EXTRA_INCLUDEPATHS)
target_include_directories(PlatformCommonInternal INTERFACE ${QT_EXTRA_INCLUDEPATHS})
endif()
if(DEFINED QT_EXTRA_LIBDIRS)
target_link_directories(PlatformCommonInternal INTERFACE ${QT_EXTRA_LIBDIRS})
endif()
if(DEFINED QT_EXTRA_FRAMEWORKPATHS AND APPLE)
list(TRANSFORM QT_EXTRA_FRAMEWORKPATHS PREPEND "-F" OUTPUT_VARIABLE __qt_fw_flags)
target_compile_options(PlatformCommonInternal INTERFACE ${__qt_fw_flags})
target_link_options(PlatformCommonInternal INTERFACE ${__qt_fw_flags})
unset(__qt_fw_flags)
endif()
function(qt_get_implicit_sse2_genex_condition out_var)
set(is_shared_lib "$<STREQUAL:$<TARGET_PROPERTY:TYPE>,SHARED_LIBRARY>")
set(is_static_lib "$<STREQUAL:$<TARGET_PROPERTY:TYPE>,STATIC_LIBRARY>")

View File

@ -515,6 +515,22 @@ endif()\n")
string(APPEND QT_EXTRA_BUILD_INTERNALS_VARS
"set(QT_DISABLE_RPATH \"${QT_DISABLE_RPATH}\" CACHE STRING \"\")\n")
endif()
if(DEFINED QT_EXTRA_DEFINES)
string(APPEND QT_EXTRA_BUILD_INTERNALS_VARS
"set(QT_EXTRA_DEFINES \"${QT_EXTRA_DEFINES}\" CACHE STRING \"\")\n")
endif()
if(DEFINED QT_EXTRA_INCLUDEPATHS)
string(APPEND QT_EXTRA_BUILD_INTERNALS_VARS
"set(QT_EXTRA_INCLUDEPATHS \"${QT_EXTRA_INCLUDEPATHS}\" CACHE STRING \"\")\n")
endif()
if(DEFINED QT_EXTRA_FRAMEWORKPATHS)
string(APPEND QT_EXTRA_BUILD_INTERNALS_VARS
"set(QT_EXTRA_FRAMEWORKPATHS \"${QT_EXTRA_FRAMEWORKPATHS}\" CACHE STRING \"\")\n")
endif()
if(DEFINED QT_EXTRA_LIBDIRS)
string(APPEND QT_EXTRA_BUILD_INTERNALS_VARS
"set(QT_EXTRA_LIBDIRS \"${QT_EXTRA_LIBDIRS}\" CACHE STRING \"\")\n")
endif()
if(DEFINED QT_EXTRA_RPATHS)
string(APPEND QT_EXTRA_BUILD_INTERNALS_VARS
"set(QT_EXTRA_RPATHS \"${QT_EXTRA_RPATHS}\" CACHE STRING \"\")\n")

View File

@ -612,6 +612,23 @@ function(qt_generate_global_module_pri_file)
list(JOIN corrected_private_config " " private_config_joined)
set(content "")
if(DEFINED QT_EXTRA_DEFINES)
list(JOIN QT_EXTRA_DEFINES " " value)
string(APPEND content "EXTRA_DEFINES += ${value}\n")
endif()
if(DEFINED QT_EXTRA_INCLUDEPATHS)
qt_to_qmake_path_list(value ${QT_EXTRA_INCLUDEPATHS})
string(APPEND content "EXTRA_INCLUDEPATH += ${value}\n")
endif()
if(DEFINED QT_EXTRA_LIBDIRS)
qt_to_qmake_path_list(value ${QT_EXTRA_LIBDIRS})
string(APPEND content "EXTRA_LIBDIR += ${value}\n")
endif()
if(DEFINED QT_EXTRA_FRAMEWORKPATHS)
qt_to_qmake_path_list(value ${QT_EXTRA_FRAMEWORKPATHS})
string(APPEND content "EXTRA_FRAMEWORKPATH += ${value}\n")
endif()
set(arch "${TEST_architecture_arch}")
list(JOIN TEST_subarch_result " " subarchs)
if(CMAKE_CROSSCOMPILING)

View File

@ -599,6 +599,10 @@ elseif(nr_of_build_configs GREATER 1)
endif()
translate_list_input(device-option QT_QMAKE_DEVICE_OPTIONS)
translate_list_input(defines QT_EXTRA_DEFINES)
translate_list_input(fpaths QT_EXTRA_FRAMEWORKPATHS)
translate_list_input(includes QT_EXTRA_INCLUDEPATHS)
translate_list_input(lpaths QT_EXTRA_LIBDIRS)
translate_list_input(rpaths QT_EXTRA_RPATHS)
foreach(input ${config_inputs})

View File

@ -1,3 +1,18 @@
# Create a QMake list (values space-separated) containing paths.
# Entries that contain whitespace characters are quoted.
function(qt_to_qmake_path_list out_var)
set(quoted_paths "")
foreach(path ${ARGN})
if(path MATCHES "[ \t]")
list(APPEND quoted_paths "\"${path}\"")
else()
list(APPEND quoted_paths "${path}")
endif()
endforeach()
list(JOIN quoted_paths " " result)
set("${out_var}" "${result}" PARENT_SCOPE)
endfunction()
macro(qt_add_string_to_qconfig_cpp str)
string(LENGTH "${str}" length)
string(APPEND QT_CONFIG_STRS " \"${str}\\0\"\n")

View File

@ -78,10 +78,10 @@ The effort of this is tracked in QTBUG-85373 and QTBUG-85349.
| | | passed via -DCMAKE_TOOLCHAIN_FILE=<filename> |
| -no-gcc-sysroot | | |
| -no-pkg-config | | |
| -D <string> | | |
| -I <string> | | |
| -L <string> | | |
| -F <string> | | |
| -D <string> | -DQT_EXTRA_DEFINES=<string1>;<string2> | |
| -I <string> | -DQT_EXTRA_INCLUDEPATHS=<string1>;<string2> | |
| -L <string> | -DQT_EXTRA_LIBDIRS=<string1>;<string2> | |
| -F <string> | -DQT_EXTRA_FRAMEWORKPATHS=<string1>;<string2> | |
| -sdk <sdk> | | |
| -android-sdk path | | |
| -android-ndk path | | |