Selectively build files based on ENABLE_KEM_SIDH/SIKE macros

This commit is contained in:
Christian Paquin 2020-06-22 15:44:20 -04:00
parent 78c5f77b08
commit d1344c7f24

View File

@ -1,6 +1,23 @@
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR if(OQS_ENABLE_KEM_sike_p434 OR
OQS_ENABLE_KEM_sike_p503 OR
OQS_ENABLE_KEM_sike_p610 OR
OQS_ENABLE_KEM_sike_p751 OR
OQS_ENABLE_KEM_sike_p434_compressed OR
OQS_ENABLE_KEM_sike_p503_compressed OR
OQS_ENABLE_KEM_sike_p610_compressed OR
OQS_ENABLE_KEM_sike_p751_compressed OR
OQS_ENABLE_KEM_sidh_p434 OR
OQS_ENABLE_KEM_sidh_p503 OR
OQS_ENABLE_KEM_sidh_p610 OR
OQS_ENABLE_KEM_sidh_p751 OR
OQS_ENABLE_KEM_sidh_p434_compressed OR
OQS_ENABLE_KEM_sidh_p503_compressed OR
OQS_ENABLE_KEM_sidh_p610_compressed OR
OQS_ENABLE_KEM_sidh_p751_compressed)
if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR
CMAKE_C_COMPILER_ID MATCHES "Clang") CMAKE_C_COMPILER_ID MATCHES "Clang")
# The way various files are #include'd in the SIKE implementations leads to unused functions # The way various files are #include'd in the SIKE implementations leads to unused functions
# We will not raise warnings for these # We will not raise warnings for these
@ -14,75 +31,124 @@ if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR
add_compile_options(-Wno-error) add_compile_options(-Wno-error)
endif() endif()
endif() endif()
endif() endif()
if(CMAKE_C_COMPILER_ID MATCHES "Clang") if(CMAKE_C_COMPILER_ID MATCHES "Clang")
# Clang emits spurious warnings where # Clang emits spurious warnings where
# the "{0}" structure initializer is used. # the "{0}" structure initializer is used.
add_compile_options(-Wno-missing-braces) add_compile_options(-Wno-missing-braces)
endif() endif()
if(WIN32 AND NOT (MINGW OR MSYS OR CYGWIN)) if(WIN32 AND NOT (MINGW OR MSYS OR CYGWIN))
# ignore warning about cast from int to OQS_STATUS # ignore warning about cast from int to OQS_STATUS
add_compile_options(/wd4133) add_compile_options(/wd4133)
endif() endif()
set(SRCS kem_sike.c set(SRCS kem_sike.c)
external/P434/P434.c if(OQS_ENABLE_KEM_sike_p434 OR OQS_ENABLE_KEM_sidh_p434)
external/P434/P434_compressed.c set(SRCS ${SRCS} external/P434/P434.c)
external/P503/P503.c endif()
external/P503/P503_compressed.c if(OQS_ENABLE_KEM_sike_p434_compressed OR OQS_ENABLE_KEM_sidh_p434_compressed)
external/P610/P610.c set(SRCS ${SRCS} external/P434/P434_compressed.c)
external/P610/P610_compressed.c endif()
external/P751/P751.c if(OQS_ENABLE_KEM_sike_p503 OR OQS_ENABLE_KEM_sidh_p503)
external/P751/P751_compressed.c) set(SRCS ${SRCS} external/P503/P503.c)
endif()
if(OQS_ENABLE_KEM_sike_p503_compressed OR OQS_ENABLE_KEM_sidh_p503_compressed)
set(SRCS ${SRCS} external/P503/P503_compressed.c)
endif()
if(OQS_ENABLE_KEM_sike_p610 OR OQS_ENABLE_KEM_sidh_p610)
set(SRCS ${SRCS} external/P610/P610.c)
endif()
if(OQS_ENABLE_KEM_sike_p610_compressed OR OQS_ENABLE_KEM_sidh_p610_compressed)
set(SRCS ${SRCS} external/P610/P610_compressed.c)
endif()
if(OQS_ENABLE_KEM_sike_p751 OR OQS_ENABLE_KEM_sidh_p751)
set(SRCS ${SRCS} external/P751/P751.c)
endif()
if(OQS_ENABLE_KEM_sike_p751_compressed OR OQS_ENABLE_KEM_sidh_p751_compressed)
set(SRCS ${SRCS} external/P751/P751_compressed.c)
endif()
if(ARCH STREQUAL "x86_64") if(ARCH STREQUAL "x86_64")
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin") if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
set(SRCS ${SRCS} external/P503/AMD64/fp_x64_asm.S if(OQS_ENABLE_KEM_sike_p503 OR OQS_ENABLE_KEM_sidh_p503 OR OQS_ENABLE_KEM_sike_p503_compressed OR OQS_ENABLE_KEM_sidh_p503_compressed)
external/P751/AMD64/fp_x64_asm.S) set(SRCS ${SRCS} external/P503/AMD64/fp_x64_asm.S)
endif()
if(OQS_ENABLE_KEM_sike_p751 OR OQS_ENABLE_KEM_sidh_p751 OR OQS_ENABLE_KEM_sike_p751_compressed OR OQS_ENABLE_KEM_sidh_p751_compressed)
set(SRCS ${SRCS} external/P751/AMD64/fp_x64_asm.S)
endif()
if(OQS_USE_BMI2_INSTRUCTIONS AND NOT OQS_PORTABLE_BUILD) if(OQS_USE_BMI2_INSTRUCTIONS AND NOT OQS_PORTABLE_BUILD)
set(SRCS ${SRCS} external/P434/AMD64/fp_x64_asm.S if(OQS_ENABLE_KEM_sike_p434 OR OQS_ENABLE_KEM_sidh_p434 OR OQS_ENABLE_KEM_sike_p434_compressed OR OQS_ENABLE_KEM_sidh_p434_compressed)
external/P610/AMD64/fp_x64_asm.S) set(SRCS ${SRCS} external/P434/AMD64/fp_x64_asm.S)
endif()
if(OQS_ENABLE_KEM_sike_p610 OR OQS_ENABLE_KEM_sidh_p610 OR OQS_ENABLE_KEM_sike_p610_compressed OR OQS_ENABLE_KEM_sidh_p610_compressed)
set(SRCS ${SRCS} external/P610/AMD64/fp_x64_asm.S)
endif()
add_compile_options(-mbmi2) add_compile_options(-mbmi2)
endif() endif()
endif() endif()
elseif(ARCH STREQUAL "arm64") elseif(ARCH STREQUAL "arm64")
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin") if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
set(SRCS ${SRCS} external/P434/ARM64/fp_arm64_asm.S if(OQS_ENABLE_KEM_sike_p434 OR OQS_ENABLE_KEM_sidh_p434 OR OQS_ENABLE_KEM_sike_p434_compressed OR OQS_ENABLE_KEM_sidh_p434_compressed)
external/P503/ARM64/fp_arm64_asm.S set(SRCS ${SRCS} external/P434/ARM64/fp_arm64_asm.S)
external/P610/ARM64/fp_arm64_asm.S endif()
external/P751/ARM64/fp_arm64_asm.S) if(OQS_ENABLE_KEM_sike_p503 OR OQS_ENABLE_KEM_sidh_p503 OR OQS_ENABLE_KEM_sike_p503_compressed OR OQS_ENABLE_KEM_sidh_p503_compressed)
set(SRCS ${SRCS} external/P503/ARM64/fp_arm64_asm.S)
endif()
if(OQS_ENABLE_KEM_sike_p610 OR OQS_ENABLE_KEM_sidh_p610 OR OQS_ENABLE_KEM_sike_p610_compressed OR OQS_ENABLE_KEM_sidh_p610_compressed)
set(SRCS ${SRCS} external/P610/ARM64/fp_arm64_asm.S)
endif()
if(OQS_ENABLE_KEM_sike_p751 OR OQS_ENABLE_KEM_sidh_p751 OR OQS_ENABLE_KEM_sike_p751_compressed OR OQS_ENABLE_KEM_sidh_p751_compressed)
set(SRCS ${SRCS} external/P751/ARM64/fp_arm64_asm.S)
endif()
endif()
endif() endif()
endif()
add_library(sike OBJECT ${SRCS}) add_library(sike OBJECT ${SRCS})
if(ARCH STREQUAL "x86") if(ARCH STREQUAL "x86")
target_compile_definitions(sike PRIVATE _GENERIC_ _X86_) target_compile_definitions(sike PRIVATE _GENERIC_ _X86_)
elseif(ARCH STREQUAL "x86_64") elseif(ARCH STREQUAL "x86_64")
target_compile_definitions(sike PRIVATE _AMD64_) target_compile_definitions(sike PRIVATE _AMD64_)
if(OQS_USE_BMI2_INSTRUCTIONS AND NOT OQS_PORTABLE_BUILD) if(OQS_USE_BMI2_INSTRUCTIONS AND NOT OQS_PORTABLE_BUILD)
target_compile_definitions(sike PRIVATE _MULX_ _ADX_) target_compile_definitions(sike PRIVATE _MULX_ _ADX_)
endif() endif()
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin") if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
target_compile_definitions(sike PRIVATE USE_SIKEP503_ASM if(OQS_ENABLE_KEM_sike_p503 OR OQS_ENABLE_KEM_sidh_p503 OR OQS_ENABLE_KEM_sike_p503_compressed OR OQS_ENABLE_KEM_sidh_p503_compressed)
USE_SIKEP751_ASM) target_compile_definitions(sike PRIVATE USE_SIKEP503_ASM)
endif()
if(OQS_ENABLE_KEM_sike_p751 OR OQS_ENABLE_KEM_sidh_p751 OR OQS_ENABLE_KEM_sike_p751_compressed OR OQS_ENABLE_KEM_sidh_p751_compressed)
target_compile_definitions(sike PRIVATE USE_SIKEP751_ASM)
endif()
if(OQS_USE_BMI2_INSTRUCTIONS AND NOT OQS_PORTABLE_BUILD) if(OQS_USE_BMI2_INSTRUCTIONS AND NOT OQS_PORTABLE_BUILD)
target_compile_definitions(sike PRIVATE USE_SIKEP434_ASM if(OQS_ENABLE_KEM_sike_p434 OR OQS_ENABLE_KEM_sidh_p434 OR OQS_ENABLE_KEM_sike_p434_compressed OR OQS_ENABLE_KEM_sidh_p434_compressed)
USE_SIKEP610_ASM) target_compile_definitions(sike PRIVATE USE_SIKEP434_ASM)
endif()
if(OQS_ENABLE_KEM_sike_p610 OR OQS_ENABLE_KEM_sidh_p610 OR OQS_ENABLE_KEM_sike_p610_compressed OR OQS_ENABLE_KEM_sidh_p610_compressed)
target_compile_definitions(sike PRIVATE USE_SIKEP610_ASM)
endif() endif()
endif() endif()
elseif(ARCH STREQUAL "arm") endif()
elseif(ARCH STREQUAL "arm")
target_compile_definitions(sike PRIVATE _GENERIC_ _ARM_) target_compile_definitions(sike PRIVATE _GENERIC_ _ARM_)
elseif(ARCH STREQUAL "arm64") elseif(ARCH STREQUAL "arm64")
target_compile_definitions(sike PRIVATE _ARM64_) target_compile_definitions(sike PRIVATE _ARM64_)
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin") if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
target_compile_definitions(sike PRIVATE USE_SIKEP434_ASM if(OQS_ENABLE_KEM_sike_p434 OR OQS_ENABLE_KEM_sidh_p434 OR OQS_ENABLE_KEM_sike_p434_compressed OR OQS_ENABLE_KEM_sidh_p434_compressed)
USE_SIKEP503_ASM target_compile_definitions(sike PRIVATE USE_SIKEP434_ASM)
USE_SIKEP610_ASM
USE_SIKEP751_ASM)
endif() endif()
endif() if(OQS_ENABLE_KEM_sike_p503 OR OQS_ENABLE_KEM_sidh_p503 OR OQS_ENABLE_KEM_sike_p503_compressed OR OQS_ENABLE_KEM_sidh_p503_compressed)
if(CMAKE_C_COMPILER_ID STREQUAL "GNU") target_compile_definitions(sike PRIVATE USE_SIKEP503_ASM)
endif()
if(OQS_ENABLE_KEM_sike_p610 OR OQS_ENABLE_KEM_sidh_p610 OR OQS_ENABLE_KEM_sike_p610_compressed OR OQS_ENABLE_KEM_sidh_p610_compressed)
target_compile_definitions(sike PRIVATE USE_SIKEP610_ASM)
endif()
if(OQS_ENABLE_KEM_sike_p751 OR OQS_ENABLE_KEM_sidh_p751 OR OQS_ENABLE_KEM_sike_p751_compressed OR OQS_ENABLE_KEM_sidh_p751_compressed)
target_compile_definitions(sike PRIVATE USE_SIKEP751_ASM)
endif()
endif()
endif()
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
target_compile_definitions(sike PRIVATE COMPILER_GCC) target_compile_definitions(sike PRIVATE COMPILER_GCC)
elseif(CMAKE_C_COMPILER_ID MATCHES "Clang") elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
target_compile_definitions(sike PRIVATE COMPILER_CLANG) target_compile_definitions(sike PRIVATE COMPILER_CLANG)
endif() endif()
endif()