CMake: pro2cmake.py: Handle SIMD sources
Change-Id: Ib445888e769432e8c247ae2d2fb5d8af2d5cd275 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
parent
d48160be9e
commit
6e16f127ad
@ -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)
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user