blob: 9828799007c230a6976f8a079abfba55292068dc [file] [log] [blame]
macro(append_to_parent_scope var)
list(APPEND ${var} ${ARGN})
set(${var} "${${var}}" PARENT_SCOPE)
endmacro()
function(add_perlasm_target dest src)
get_filename_component(dir ${dest} DIRECTORY)
if(dir STREQUAL "")
set(dir ".")
endif()
add_custom_command(
OUTPUT ${dest}
COMMAND ${CMAKE_COMMAND} -E make_directory ${dir}
COMMAND ${PERL_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/${src} ${ARGN}
${dest}
DEPENDS
${src}
${PROJECT_SOURCE_DIR}/crypto/perlasm/arm-xlate.pl
${PROJECT_SOURCE_DIR}/crypto/perlasm/x86_64-xlate.pl
${PROJECT_SOURCE_DIR}/crypto/perlasm/x86asm.pl
${PROJECT_SOURCE_DIR}/crypto/perlasm/x86gas.pl
${PROJECT_SOURCE_DIR}/crypto/perlasm/x86masm.pl
${PROJECT_SOURCE_DIR}/crypto/perlasm/x86nasm.pl
WORKING_DIRECTORY .
)
endfunction()
# perlasm generates perlasm output from a given file. arch specifies the
# architecture. dest specifies the basename of the output file. The list of
# generated files will be appended to ${var}_ASM and ${var}_NASM depending on
# the assembler used.
function(perlasm var arch dest src)
if(arch STREQUAL "aarch64")
add_perlasm_target("${dest}-apple.S" ${src} ios64)
add_perlasm_target("${dest}-linux.S" ${src} linux64)
add_perlasm_target("${dest}-win.S" ${src} win64)
append_to_parent_scope("${var}_ASM" "${dest}-apple.S" "${dest}-linux.S" "${dest}-win.S")
elseif(arch STREQUAL "arm")
add_perlasm_target("${dest}-apple.S" ${src} ios32)
add_perlasm_target("${dest}-linux.S" ${src} linux32)
append_to_parent_scope("${var}_ASM" "${dest}-apple.S" "${dest}-linux.S")
elseif(arch STREQUAL "x86")
add_perlasm_target("${dest}-apple.S" ${src} macosx -fPIC -DOPENSSL_IA32_SSE2)
add_perlasm_target("${dest}-linux.S" ${src} elf -fPIC -DOPENSSL_IA32_SSE2)
add_perlasm_target("${dest}-win.asm" ${src} win32n -DOPENSSL_IA32_SSE2)
append_to_parent_scope("${var}_ASM" "${dest}-apple.S" "${dest}-linux.S")
append_to_parent_scope("${var}_NASM" "${dest}-win.asm")
elseif(arch STREQUAL "x86_64")
add_perlasm_target("${dest}-apple.S" ${src} macosx)
add_perlasm_target("${dest}-linux.S" ${src} elf)
add_perlasm_target("${dest}-win.asm" ${src} nasm)
append_to_parent_scope("${var}_ASM" "${dest}-apple.S" "${dest}-linux.S")
append_to_parent_scope("${var}_NASM" "${dest}-win.asm")
else()
message(FATAL_ERROR "Unknown perlasm architecture: $arch")
endif()
endfunction()