summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Hunger <tobias.hunger@qt.io>2019-03-11 15:09:33 +0100
committerTobias Hunger <tobias.hunger@qt.io>2019-03-18 11:37:47 +0000
commit6e16f127ad4f1bf8f8191b72be12aa20785d816c (patch)
tree57c60fade7d769b2ab483f937bc24ba530262788
parentd48160be9e752833ab3658d1e7f50b49b60f1a85 (diff)
CMake: pro2cmake.py: Handle SIMD sources
Change-Id: Ib445888e769432e8c247ae2d2fb5d8af2d5cd275 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
-rw-r--r--cmake/QtBuild.cmake52
-rwxr-xr-xutil/cmake/pro2cmake.py26
2 files changed, 78 insertions, 0 deletions
diff --git a/cmake/QtBuild.cmake b/cmake/QtBuild.cmake
index 6eabccb83c..f08415d88e 100644
--- a/cmake/QtBuild.cmake
+++ b/cmake/QtBuild.cmake
@@ -919,6 +919,58 @@ function(add_qt_resource target resourceName)
target_sources(${target} PRIVATE "${generatedSourceCode}")
endfunction()
+
+# Handle files that need special SIMD-related flags.
+# This creates an object library and makes target link
+# to it (privately).
+function(add_qt_simd_part target)
+ qt_parse_all_arguments(arg "add_qt_simd_part" "" ""
+ "NAME;SIMD;${__default_private_args};COMPILE_FLAGS" ${ARGN})
+ if ("x${arg_SIMD}" STREQUAL x)
+ message(FATAL_ERROR "add_qt_simd_part needs a SIMD type to be set.")
+ endif()
+
+ set(condition "QT_FEATURE_${arg_SIMD}")
+ if("${arg_SIMD}" STREQUAL arch_haswell)
+ set(condition "TEST_subarch_avx2 AND TEST_subarch_bmi AND TEST_subarch_bmi2 AND TEST_subarch_f16c AND TEST_subarch_fma AND TEST_subarch_lzcnt AND TEST_subarch_popcnt")
+ elseif("${arg_SIMD}" STREQUAL avx512common)
+ set(condition "TEST_subarch_avx512cd")
+ elseif("${arg_SIMD}" STREQUAL avx512core)
+ set(condition "TEST_subarch_avx512cd AND TEST_subarch_avx512bw AND TEST_subarch_avx512dq AND TEST_subarch_avx512vl")
+ endif()
+
+ set(name "${arg_NAME}")
+ if("x${name}" STREQUAL x)
+ set(name "${target}_simd_${arg_SIMD}")
+ endif()
+
+ qt_evaluate_config_expression(result ${condition})
+ if(${result})
+ if(QT_CMAKE_DEBUG_EXTEND_TARGET)
+ message("add_qt_simd_part(${target} SIMD ${arg_SIMD} ...): Evaluated")
+ endif()
+ string(TOUPPER "QT_CFLAGS_${arg_SIMD}" simd_flags)
+
+ add_library("${name}" OBJECT)
+ target_sources("${name}" PRIVATE ${arg_SOURCES})
+ target_include_directories("${name}" PRIVATE
+ ${arg_INCLUDE_DIRECTORIES}
+ $<TARGET_PROPERTY:${target},INCLUDE_DIRECTORIES>)
+ target_compile_options("${name}" PRIVATE
+ ${${simd_flags}}
+ ${arg_COMPILE_FLAGS}
+ $<TARGET_PROPERTY:${target},COMPILE_OPTIONS>)
+ target_compile_definitions("${name}" PRIVATE
+ $<TARGET_PROPERTY:${target},COMPILE_DEFINITIONS>)
+
+ target_link_libraries("${target}" PRIVATE "${name}")
+ else()
+ if(QT_CMAKE_DEBUG_EXTEND_TARGET)
+ message("add_qt_simd_part(${target} SIMD ${arg_SIMD} ...): Skipped")
+ endif()
+ endif()
+endfunction()
+
# From Qt5CoreMacros
# Function used to create the names of output files preserving relative dirs
function(qt_make_output_file infile prefix suffix source_dir binary_dir result)
diff --git a/util/cmake/pro2cmake.py b/util/cmake/pro2cmake.py
index 7abb8f5a1c..37ead10513 100755
--- a/util/cmake/pro2cmake.py
+++ b/util/cmake/pro2cmake.py
@@ -1208,6 +1208,30 @@ def merge_scopes(scopes: typing.List[Scope]) -> typing.List[Scope]:
return result
+def write_simd_part(cm_fh: typing.IO[str], target: str, scope: Scope, indent: int = 0):
+ simd_options = [ 'sse2', 'sse3', 'ssse3', 'sse4_1', 'sse4_2', 'aesni', 'shani', 'avx', 'avx2',
+ 'avx512f', 'avx512cd', 'avx512er', 'avx512pf', 'avx512dq', 'avx512bw',
+ 'avx512vl', 'avx512ifma', 'avx512vbmi', 'f16c', 'rdrnd', 'neon', 'mips_dsp',
+ 'mips_dspr2',
+ 'arch_haswell', 'avx512common', 'avx512core'];
+ ind = spaces(indent)
+
+ for simd in simd_options:
+ SIMD = simd.upper();
+ sources = scope.get('{}_HEADERS'.format(SIMD), []) \
+ + scope.get('{}_SOURCES'.format(SIMD), []) \
+ + scope.get('{}_C_SOURCES'.format(SIMD), []) \
+ + scope.get('{}_ASM'.format(SIMD), [])
+
+ if not sources:
+ continue
+
+ cm_fh.write('{}add_qt_simd_part({} SIMD {}\n'.format(ind, target, simd))
+ cm_fh.write('{} SOURCES\n'.format(ind))
+ cm_fh.write('{} {}\n'.format(ind, '\n{} '.format(ind).join(sources)))
+ cm_fh.write('{})\n\n'.format(ind))
+
+
def write_main_part(cm_fh: typing.IO[str], name: str, typename: str,
cmake_function: str, scope: Scope, *,
extra_lines: typing.List[str] = [],
@@ -1243,6 +1267,8 @@ def write_main_part(cm_fh: typing.IO[str], name: str, typename: str,
write_resources(cm_fh, name, scope, indent)
+ write_simd_part(cm_fh, name, scope, indent)
+
# Scopes:
if len(scopes) == 1:
return