CMake refactoring. (#652)

* Overhauled the propagation of compiler flags

* Added "Dependency" CMake build type

* Removed src/common/CMakeLists.txt and src/crypto/CMakeLists.txt

* Set default build type to exclude CPU extension-based optimizations
This commit is contained in:
xvzcf 2020-03-11 10:48:28 -04:00 committed by GitHub
parent 5653455ff1
commit 0d39a601b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 222 additions and 262 deletions

View File

@ -0,0 +1,81 @@
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
add_compile_options(-Werror)
add_compile_options(-Wall)
add_compile_options(-Wextra)
add_compile_options(-Wpedantic)
# TODO: Uncomment these lines
#add_compile_options(-Wreserved-id-macro)
#add_compile_options(-Wbad-function-cast)
add_compile_options(-fvisibility=hidden)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_compile_options(-g3)
add_compile_options(-fno-omit-frame-pointer)
if(USE_SANITIZER STREQUAL "Address")
add_compile_options(-fno-optimize-sibling-calls)
add_compile_options(-fsanitize-address-use-after-scope)
add_compile_options(-fsanitize=address)
elseif(USE_SANITIZER STREQUAL "Memory")
add_compile_options(-fsanitize=memory)
elseif(USE_SANITIZER STREQUAL "MemoryWithOrigins")
add_compile_options(-fsanitize=memory)
add_compile_options(-fsanitize-memory-track-origins)
elseif(USE_SANITIZER STREQUAL "Undefined")
add_compile_options(-fsanitize=undefined)
if(EXISTS "${BLACKLIST_FILE}")
add_compile_options(-fsanitize-blacklist=${BLACKLIST_FILE})
endif()
elseif(USE_SANITIZER STREQUAL "Thread")
add_compile_options(-fsanitize=thread)
elseif(USE_SANITIZER STREQUAL "Leak")
add_compile_options(-fsanitize=leak)
endif()
elseif(CMAKE_BUILD_TYPE STREQUAL "Optimized")
add_compile_options(-O3)
add_compile_options(-march=native)
add_compile_options(-fomit-frame-pointer)
else() #Build type = Generic/Dependency
add_compile_options(-O3)
add_compile_options(-fomit-frame-pointer)
endif()
elseif(CMAKE_C_COMPILER_ID STREQUAL "GNU")
add_compile_options(-Werror)
add_compile_options(-Wall)
add_compile_options(-Wextra)
add_compile_options(-Wpedantic)
add_compile_options(-Wstrict-prototypes)
add_compile_options(-Wshadow)
add_compile_options(-Wformat=2)
add_compile_options(-Wfloat-equal)
add_compile_options(-Wwrite-strings)
add_compile_options(-fvisibility=hidden)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_compile_options (-Wstrict-overflow=4)
add_compile_options(-ggdb3)
elseif(CMAKE_BUILD_TYPE STREQUAL "Optimized")
add_compile_options(-O3)
add_compile_options(-march=native)
add_compile_options(-fomit-frame-pointer)
add_compile_options(-fdata-sections)
add_compile_options(-ffunction-sections)
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
add_compile_options(-Wl,-dead_strip)
else ()
add_compile_options(-Wl,--gc-sections)
endif ()
else() #Build type = Generic/Dependency
add_compile_options(-O3)
add_compile_options(-fomit-frame-pointer)
add_compile_options(-fdata-sections)
add_compile_options(-ffunction-sections)
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
add_compile_options(-Wl,-dead_strip)
else ()
add_compile_options(-Wl,--gc-sections)
endif ()
endif()
endif()
if(MINGW OR MSYS OR CYGWIN)
add_compile_options(-Wno-maybe-uninitialized)
endif()

View File

@ -1,89 +0,0 @@
# https://github.com/StableCoder/cmake-scripts/blob/master/sanitizers.cmake
#
# Copyright (C) 2018 by George Cave - gcave@stablecoder.ca
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
set(USE_SANITIZER
""
CACHE
STRING
"Compile with a sanitizer. Options are: Address, Memory, MemoryWithOrigins, Undefined, Thread, Leak, 'Address;Undefined'"
)
function(append value)
foreach(variable ${ARGN})
set(${variable}
"${${variable}} ${value}"
PARENT_SCOPE)
endforeach(variable)
endfunction()
if(USE_SANITIZER)
append("-fno-omit-frame-pointer -g3" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
if(UNIX)
if(uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
append("-O1" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
endif()
if(USE_SANITIZER MATCHES "([Aa]ddress);([Uu]ndefined)"
OR USE_SANITIZER MATCHES "([Uu]ndefined);([Aa]ddress)")
message(STATUS "Building with Address, Undefined sanitizers")
append("-fsanitize=address,undefined" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
elseif(USE_SANITIZER MATCHES "([Aa]ddress)")
# Optional: -fno-optimize-sibling-calls -fsanitize-address-use-after-scope
message(STATUS "Building with Address sanitizer")
append("-fsanitize=address" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
elseif(USE_SANITIZER MATCHES "([Mm]emory([Ww]ith[Oo]rigins)?)")
# Optional: -fno-optimize-sibling-calls -fsanitize-memory-track-origins=2
append("-fsanitize=memory" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
if(USE_SANITIZER MATCHES "([Mm]emory[Ww]ith[Oo]rigins)")
message(STATUS "Building with MemoryWithOrigins sanitizer")
append("-fsanitize-memory-track-origins" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
else()
message(STATUS "Building with Memory sanitizer")
endif()
elseif(USE_SANITIZER MATCHES "([Uu]ndefined)")
message(STATUS "Building with Undefined sanitizer")
append("-fsanitize=undefined" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
if(EXISTS "${BLACKLIST_FILE}")
append("-fsanitize-blacklist=${BLACKLIST_FILE}" CMAKE_C_FLAGS
CMAKE_CXX_FLAGS)
endif()
elseif(USE_SANITIZER MATCHES "([Tt]hread)")
message(STATUS "Building with Thread sanitizer")
append("-fsanitize=thread" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
elseif(USE_SANITIZER MATCHES "([Ll]eak)")
message(STATUS "Building with Leak sanitizer")
append("-fsanitize=leak" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
else()
message(
FATAL_ERROR "Unsupported value of USE_SANITIZER: ${USE_SANITIZER}")
endif()
elseif(MSVC)
if(USE_SANITIZER MATCHES "([Aa]ddress)")
message(STATUS "Building with Address sanitizer")
append("-fsanitize=address" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
else()
message(
FATAL_ERROR
"This sanitizer not yet supported in the MSVC environment: ${USE_SANITIZER}"
)
endif()
else()
message(FATAL_ERROR "USE_SANITIZER is not supported on this platform.")
endif()
endif()

View File

@ -58,11 +58,13 @@ jobs:
<<: *oqsjob
environment:
IMAGE: openquantumsafe/ci-centos-8-amd64:latest
CONFIGURE_ARGS: -DCMAKE_BUILD_TYPE=Optimized
SKIP_TESTS: style
debian-buster-amd64:
<<: *oqsjob
environment:
IMAGE: openquantumsafe/ci-debian-buster-amd64:latest
CONFIGURE_ARGS: -DCMAKE_BUILD_TYPE=Optimized
SKIP_TESTS: style
debian-buster-arm64:
<<: *emulatedjob
@ -89,13 +91,13 @@ jobs:
environment:
IMAGE: openquantumsafe/ci-ubuntu-bionic-x86_64:latest
CC: gcc-7
CONFIGURE_ARGS: -DOQS_USE_OPENSSL=OFF
CONFIGURE_ARGS: -DCMAKE_BUILD_TYPE=Optimized -DOQS_USE_OPENSSL=OFF
ubuntu-bionic-x86_64-gcc7-shared:
<<: *oqsjob
environment:
IMAGE: openquantumsafe/ci-ubuntu-bionic-x86_64:latest
CC: gcc-7
CONFIGURE_ARGS: -DBUILD_SHARED_LIBS=ON
CONFIGURE_ARGS: -DCMAKE_BUILD_TYPE=Optimized -DBUILD_SHARED_LIBS=ON
#TODO: _init and _fini trip test_namespace.py
SKIP_TESTS: namespace
ubuntu-bionic-x86_64-gcc8:
@ -103,6 +105,7 @@ jobs:
environment:
IMAGE: openquantumsafe/ci-ubuntu-bionic-x86_64:latest
CC: gcc-8
CONFIGURE_ARGS: -DCMAKE_BUILD_TYPE=Optimized
ubuntu-bionic-x86_64-asan:
<<: *oqsjob
environment:
@ -119,8 +122,7 @@ jobs:
macos:
xcode: "11.3.0"
environment:
#TODO: Make tests pass with Release build
CONFIGURE_ARGS: -DOQS_USE_OPENSSL=OFF
CONFIGURE_ARGS: -DOQS_USE_OPENSSL=OFF -DCMAKE_BUILD_TYPE=Optimized
SKIP_TESTS: style
steps:
- checkout

View File

@ -1,25 +1,16 @@
cmake_minimum_required (VERSION 3.6)
cmake_minimum_required (VERSION 3.5)
project(liboqs C ASM)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(OQS_VERSION_TEXT "0.2.1-dev")
set(OQS_COMPILE_BUILD_TARGET "${CMAKE_SYSTEM_PROCESSOR}-${CMAKE_HOST_SYSTEM}")
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR
CMAKE_SYSTEM_PROCESSOR STREQUAL "amd64")
if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64|AMD64")
set(ARCH "x86_64")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "AMD64")
# cmake reports AMD64 on Windows, but we might be building for 32-bit.
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(ARCH "x86_64")
else()
set(ARCH "x86")
endif()
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86" OR
CMAKE_SYSTEM_PROCESSOR STREQUAL "i386" OR
CMAKE_SYSTEM_PROCESSOR STREQUAL "i686")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "x86|i386|i686")
set(ARCH "x86")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64" OR
CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|aarch64")
set(ARCH "arm64")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "arm")
set(ARCH "arm")
@ -27,48 +18,25 @@ else()
message(FATAL_ERROR "Unknown or unsupported processor: " ${CMAKE_SYSTEM_PROCESSOR})
endif()
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
if(DEFINED OQS_BUILD_TYPE)
set(CMAKE_BUILD_TYPE ${OQS_BUILD_TYPE})
endif()
if(WIN32)
set(CMAKE_GENERATOR_CC cl)
endif()
if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR
CMAKE_C_COMPILER_ID STREQUAL "Clang" OR
CMAKE_C_COMPILER_ID STREQUAL "AppleClang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden -Werror -Wall -Wextra -Wpedantic -Wimplicit -Wunused -Wcomment -Wchar-subscripts -Wuninitialized -Wstrict-prototypes -Wshadow -Wformat-security -Wwrite-strings")
if(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_LESS "5")
# GCC 4.9 erroneously reports warnings for certain valid code in BIKE
# https://stackoverflow.com/questions/13746033/how-to-repair-warning-missing-braces-around-initializer
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-missing-braces -Wno-missing-field-initializers")
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ggdb3")
elseif(CMAKE_BUILD_TYPE STREQUAL "Generic")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -fomit-frame-pointer ")
else()
if (NOT CMAKE_SYSTEM_NAME STREQUAL "Android")
include(.CMake/cpu-extensions.cmake)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -fomit-frame-pointer -march=native")
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -march=native")
endif()
endif()
endif()
if(CMAKE_C_COMPILER_ID STREQUAL "Clang" OR
CMAKE_C_COMPILER_ID STREQUAL "AppleClang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fcolor-diagnostics -Wno-missing-braces -Wno-missing-field-initializers")
endif()
if(MINGW OR MSYS OR CYGWIN)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-maybe-uninitialized")
endif()
if(BUILD_SHARED_LIBS)
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
endif()
set(OQS_COMPILE_CFLAGS ${CMAKE_C_FLAGS})
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
endif()
include(.CMake/compiler-flags.cmake)
if(CMAKE_BUILD_TYPE STREQUAL "Optimized")
include(.CMake/cpu-extensions.cmake)
endif()
include(.CMake/alg-support.cmake)
include(.CMake/sanitizers.cmake)
if(OQS_USE_OPENSSL)
if(NOT DEFINED OPENSSL_ROOT_DIR)
if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Darwin")
@ -141,23 +109,25 @@ set(PUBLIC_HEADERS ${PUBLIC_HEADERS} ${PROJECT_BINARY_DIR}/include/oqs/oqsconfig
include_directories(${PROJECT_BINARY_DIR}/include)
add_subdirectory(src)
add_subdirectory(tests)
if(NOT CMAKE_BUILD_TYPE STREQUAL "Dependency")
add_subdirectory(tests)
find_package(Doxygen)
if(DOXYGEN_FOUND)
set(DOXYFILE ${PROJECT_SOURCE_DIR}/docs/.Doxyfile)
add_custom_target(
gen_docs
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYFILE}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMENT "Generate API documentation with Doxygen."
USES_TERMINAL)
endif()
find_package(Doxygen)
if(DOXYGEN_FOUND)
set(DOXYFILE ${PROJECT_SOURCE_DIR}/docs/.Doxyfile)
add_custom_target(
gen_docs
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYFILE}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMENT "Generate API documentation with Doxygen."
USES_TERMINAL)
endif()
if(NOT WIN32)
add_custom_target(
prettyprint
COMMAND find src tests -name '*.[ch]' | grep -v '/external/' | grep -v 'kem.*/pqclean_' | grep -v 'sig.*/pqclean_' | xargs astyle --options=.astylerc
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
USES_TERMINAL)
if(NOT WIN32)
add_custom_target(
prettyprint
COMMAND find src tests -name '*.[ch]' | grep -v '/external/' | grep -v 'kem.*/pqclean_' | grep -v 'sig.*/pqclean_' | xargs astyle --options=.astylerc
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
USES_TERMINAL)
endif()
endif()

View File

@ -2,13 +2,13 @@
IF %COMPILER%==msys2 (
@echo on
SET "PATH=C:\msys64\mingw64\bin;%PATH%"
bash -lc "cd ${APPVEYOR_BUILD_FOLDER} && mkdir build && cd build && cmake .. -GNinja -DBUILD_SHARED_LIBS=%BUILD_SHARED% && ninja"
bash -lc "cd ${APPVEYOR_BUILD_FOLDER} && mkdir build && cd build && cmake .. -GNinja -DCMAKE_BUILD_TYPE=Optimized -DBUILD_SHARED_LIBS=%BUILD_SHARED% && ninja"
)
IF %COMPILER%==msvc2019 (
@echo on
CALL "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat"
mkdir build
cd build
cmake .. -GNinja -DBUILD_SHARED_LIBS=%BUILD_SHARED%
cmake .. -GNinja -DCMAKE_BUILD_TYPE=Optimized -DBUILD_SHARED_LIBS=%BUILD_SHARED%
ninja
)

View File

@ -8,7 +8,7 @@ platform: x64
branches:
except:
- /master-new-.*/
environment:
matrix:
- BUILD_SHARED: OFF
@ -22,12 +22,12 @@ environment:
build_script:
- cmd: '%APPVEYOR_BUILD_FOLDER%\appveyor-build.bat'
before_test:
- cmd: |-
SET "PATH=C:\Python37;C:\Python37\Scripts;%PATH%"
pip.exe install pytest pytest-xdist
test_script:
- cmd: |-
cd %APPVEYOR_BUILD_FOLDER%\build

View File

@ -1,4 +1,5 @@
#!/bin/bash
set -e
show_help() {
echo ""
@ -34,7 +35,7 @@ cd "$parent_path/.."
NDK=$1
# Verify NDK is valid directory
if [ -d $NDK ]
if [ -d "$NDK" ]
then
echo "Valid directory for NDK at $NDK"
else
@ -54,6 +55,7 @@ do
a) ABI=$OPTARG;;
s) MINSDKVERSION=$OPTARG;;
b) BUILDDIR=$OPTARG;;
*) exit 1
esac
done
@ -62,8 +64,8 @@ valid_abis=("armeabi-v7a" "arm64-v8a" "x86" "x86_64")
abi_match=false
for i in "${valid_abis[@]}"
do
:
if [ $ABI == $i ]
:
if [ "$ABI" == "$i" ]
then abi_match=true
fi
done
@ -73,13 +75,13 @@ then
else
echo "Invalid Android ABI of $ABI"
echo "Valid ABIs are:"
printf "%s\n" "${valid_abis[@]}"
printf "%s\\n" "${valid_abis[@]}"
exit 1
fi
# Check SDK version is supported
highestSdkVersion=29
if (( 1 <= $MINSDKVERSION && $MINSDKVERSION <= $highestSdkVersion ))
if (( 1 <= MINSDKVERSION && MINSDKVERSION <= highestSdkVersion ))
then
echo "Compiling for SDK $MINSDKVERSION"
else
@ -88,19 +90,22 @@ else
fi
# Remove build directory if it exists
if [ -d $BUILDDIR ]
if [ -d "$BUILDDIR" ]
then
echo "Cleaning up previous build"
rm -r $BUILDDIR
rm -r "$BUILDDIR"
fi
echo "Building in directory $BUILDDIR"
# Build
mkdir $BUILDDIR && cd $BUILDDIR
cmake -DUSE_OPENSSL=OFF -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_TOOLCHAIN_FILE=$NDK/build/cmake/android.toolchain.cmake \
-DANDROID_ABI=$ABI -DANDROID_NATIVE_API_LEVEL=$MINSDKVERSION -DENABLE_SIG_PICNIC=OFF ..
mkdir "$BUILDDIR" && cd "$BUILDDIR"
cmake .. -DUSE_OPENSSL=OFF \
-DBUILD_SHARED_LIBS=ON \
-DCMAKE_TOOLCHAIN_FILE="$NDK"/build/cmake/android.toolchain.cmake \
-DANDROID_ABI="$ABI" \
-DANDROID_NATIVE_API_LEVEL="$MINSDKVERSION" \
-DENABLE_SIG_PICNIC=OFF
cmake --build ./
# Provide rudimentary information following build

View File

@ -1,6 +1,3 @@
add_subdirectory(common)
add_subdirectory(crypto)
if(OQS_ENABLE_KEM_BIKE)
add_subdirectory(kem/bike)
set(KEM_OBJS ${BIKE_OBJS})
@ -59,15 +56,21 @@ if(OQS_ENABLE_SIG_SPHINCS)
set(SIG_OBJS ${SIG_OBJS} $<TARGET_OBJECTS:sphincs>)
endif()
##### OQS_COPY_FROM_PQCLEAN_FRAGMENT_ADD_ALG_OBJECTS_END
include(crypto/sources.cmake)
add_library(oqs kem/kem.c
${KEM_OBJS}
sig/sig.c
${SIG_OBJS}
$<TARGET_OBJECTS:crypto>
$<TARGET_OBJECTS:common>)
${AES_IMPL}
${SHA2_IMPL}
${SHA3_IMPL}
common/common.c
common/rand.c
common/rand_nist.c)
if(OQS_USE_OPENSSL)
target_link_libraries(oqs ${OPENSSL_CRYPTO_LIBRARY})
target_link_libraries(oqs PUBLIC ${OPENSSL_CRYPTO_LIBRARY})
target_include_directories(oqs PUBLIC ${OPENSSL_INCLUDE_DIR})
endif()
set_target_properties(oqs
@ -79,6 +82,8 @@ set_target_properties(oqs
# For Windows DLLs
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
add_library(OQS::oqs ALIAS oqs)
install(TARGETS oqs
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)

View File

@ -1,9 +0,0 @@
set(SRCS common.c
rand.c
rand_nist.c)
add_library(common OBJECT ${SRCS})
if(OQS_USE_OPENSSL)
target_include_directories(common PRIVATE ${OPENSSL_INCLUDE_DIR})
endif()

View File

@ -19,9 +19,3 @@ endif()
if(OQS_USE_AVX2_INSTRUCTIONS AND OQS_USE_AES_INSTRUCTIONS)
set(SHA3_IMPL ${SHA3_IMPL} ${CMAKE_CURRENT_LIST_DIR}/sha3/sha3x4.c)
endif()
add_library(crypto OBJECT ${AES_IMPL} ${SHA2_IMPL} ${SHA3_IMPL})
if(OQS_USE_OPENSSL)
target_include_directories(crypto PRIVATE ${OPENSSL_INCLUDE_DIR})
endif()

View File

@ -1,8 +1,11 @@
# GCC 4.9 erroneously reports warnings for certain valid code in BIKE
# https://stackoverflow.com/questions/13746033/how-to-repair-warning-missing-braces-around-initializer
# We will disable warnings for these
if(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_LESS "5")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-missing-braces -Wno-missing-field-initializers")
if(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND
CMAKE_C_COMPILER_VERSION VERSION_LESS "5")
# GCC 4.9 erroneously reports warnings for certain valid code in BIKE
# https://stackoverflow.com/questions/13746033/how-to-repair-warning-missing-braces-around-initializer
add_compile_options(-Wno-missing-braces)
add_compile_options(-Wno-missing-field-initializers)
elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wno-missing-braces -Wno-missing-field-initializers)
endif()
set(SRCS additional/decode.c
@ -14,8 +17,6 @@ set(SRCS additional/decode.c
additional/error.c
additional/gf2x_mul.c)
add_compile_options(-include ${CMAKE_CURRENT_LIST_DIR}/functions_renaming.h)
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
set(SRCS ${SRCS} additional/sampling_portable.c
additional/secure_decode_portable.c)
@ -38,7 +39,10 @@ else()
set(CPP_DEFS PORTABLE)
endif()
add_compile_options(-include ${CMAKE_CURRENT_LIST_DIR}/functions_renaming.h)
if(OQS_USE_OPENSSL)
# TODO: Find a way to eliminate this include_directories() call
include_directories(${OPENSSL_INCLUDE_DIR})
set(SRCS ${SRCS} additional/openssl_utils.c)
endif()

View File

@ -1,50 +1,53 @@
if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR
CMAKE_C_COMPILER_ID STREQUAL "Clang" OR
CMAKE_C_COMPILER_ID STREQUAL "AppleClang")
CMAKE_C_COMPILER_ID MATCHES "Clang")
# The way various files are #include'd in the SIKE implementations leads to unused functions
# We will not raise warnings for these
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-function ")
add_compile_options(-Wno-unused-function)
# GCC reports warnings about missing const related to how f2elm_t is typedef'd
# Technically GCC is correct, but we will not raise warnings for these
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-pedantic ")
add_compile_options(-Wno-pedantic)
# On GCC 4.9 those warnings can't be turned off, so we disable -Werror
if(CMAKE_C_COMPILER_VERSION VERSION_LESS "5")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error ")
add_compile_options(-Wno-error)
endif()
endif()
endif()
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
# Clang emits spurious warnings where
# the "{0}" structure initializer is used.
add_compile_options(-Wno-missing-braces)
endif()
set(SRCS kem_sike.c
P434/P434.c
P434/P434_compressed.c
P503/P503.c P503/P503_compressed.c
P610/P610.c
P610/P610_compressed.c
P751/P751.c
P751/P751_compressed.c)
P434/P434.c
P434/P434_compressed.c
P503/P503.c P503/P503_compressed.c
P610/P610.c
P610/P610_compressed.c
P751/P751.c
P751/P751_compressed.c)
add_library(sike OBJECT ${SRCS})
if(${ARCH} STREQUAL "x86")
if(ARCH STREQUAL "x86")
target_compile_definitions(sike PRIVATE _GENERIC_ _X86_)
elseif(${ARCH} STREQUAL "x86_64")
elseif(ARCH STREQUAL "x86_64")
target_compile_definitions(sike PRIVATE _AMD64_)
if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Linux")
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
set(SRCS ${SRCS} P503/AMD64/fp_x64_asm.S
P751/AMD64/fp_x64_asm.S)
P751/AMD64/fp_x64_asm.S)
if(USE_BMI2_INSTRUCTIONS)
target_compile_definitions(sike PRIVATE _MULX_ _ADX_)
set(SRCS ${SRCS} P434/AMD64/fp_x64_asm.S
P610/AMD64/fp_x64_asm.S)
P610/AMD64/fp_x64_asm.S)
endif()
endif()
elseif(${ARCH} STREQUAL "arm")
elseif(ARCH STREQUAL "arm")
target_compile_definitions(sike PRIVATE _GENERIC_ _ARM_)
elseif(${ARCH} STREQUAL "arm64")
elseif(ARCH STREQUAL "arm64")
target_compile_definitions(sike PRIVATE _ARM64_)
if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Linux")
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
set(SRCS ${SRCS} P503/AMD64/fp_x64_asm.S
P751/AMD64/fp_x64_asm.S)
P751/AMD64/fp_x64_asm.S)
endif()
endif()

View File

@ -1,6 +1,5 @@
#cmakedefine OQS_VERSION_TEXT "@OQS_VERSION_TEXT@"
#cmakedefine OQS_COMPILE_BUILD_TARGET "@OQS_COMPILE_BUILD_TARGET@"
#cmakedefine OQS_COMPILE_CFLAGS "@OQS_COMPILE_CFLAGS@"
#cmakedefine OQS_KEM_DEFAULT @OQS_KEM_DEFAULT@
#cmakedefine OQS_SIG_DEFAULT @OQS_SIG_DEFAULT@

View File

@ -1,13 +1,19 @@
if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR
CMAKE_C_COMPILER_ID STREQUAL "Clang" OR
CMAKE_C_COMPILER_ID STREQUAL "AppleClang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unguarded-availability-new")
CMAKE_C_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wno-missing-braces)
endif()
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
if(CMAKE_C_COMPILER_VERSION VERSION_GREATER "3.9")
add_compile_options(-Wno-unguarded-availability-new)
else() #Wno-unguarded-availability-new won't be recognized
add_compile_options(-Wno-error)
endif()
endif()
if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Linux" AND
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux" AND
OQS_USE_AVX2_INSTRUCTIONS AND
OQS_USE_BMI2_INSTRUCTIONS)
set(PICNIC_WITH_AVX2 "ON")
set(PICNIC_WITH_AVX2 ON)
endif()
set(SRCS sig_picnic.c
@ -48,15 +54,15 @@ add_library(picnic OBJECT ${SRCS})
target_include_directories(picnic PRIVATE external
external/sha3)
if(PICNIC_WITH_AVX2)
target_include_directories(picnic PRIVATE external/sha3/avx2)
target_include_directories(picnic PRIVATE external/sha3/avx2)
else()
target_include_directories(picnic PRIVATE external/sha3/opt64)
target_include_directories(picnic PRIVATE external/sha3/opt64)
endif()
target_compile_definitions(picnic PRIVATE PICNIC_STATIC
OPTIMIZED_LINEAR_LAYER_EVALUATION
REDUCED_ROUND_KEY_COMPUTATION
WITH_ZKBPP
WITH_KKW
WITH_ZKBPP
WITH_KKW
WITH_LOWMC_128_128_20
WITH_LOWMC_192_192_30
WITH_LOWMC_256_256_38

View File

@ -1,5 +1,7 @@
if (MINGW OR MSYS OR CYGWIN)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__USE_MINGW_ANSI_STDIO=1 -Wno-unknown-pragmas -Wno-unused-parameter")
add_definitions(-D__USE_MINGW_ANSI_STDIO=1)
add_compile_options(-Wno-unknown-pragmas)
add_compile_options(-Wno-unused-parameter)
endif()
if(NOT WIN32)
@ -17,25 +19,18 @@ if(NOT WIN32)
# These functions tested here are
# not part of the liboqs API.
get_directory_property(AES_IMPL
DIRECTORY ${PROJECT_SOURCE_DIR}/src/crypto
DEFINITION AES_IMPL)
include(${PROJECT_SOURCE_DIR}/src/crypto/sources.cmake)
add_executable(test_aes test_aes.c ${AES_IMPL} ${PROJECT_SOURCE_DIR}/src/common/common.c)
target_link_libraries(test_aes ${INTERNAL_TEST_DEPS})
target_link_libraries(test_aes PRIVATE ${INTERNAL_TEST_DEPS})
get_directory_property(SHA2_IMPL
DIRECTORY ${PROJECT_SOURCE_DIR}/src/crypto
DEFINITION SHA2_IMPL)
add_executable(test_hash test_hash.c ${SHA2_IMPL} ${PROJECT_SOURCE_DIR}/src/common/common.c)
target_link_libraries(test_hash ${INTERNAL_TEST_DEPS})
target_link_libraries(test_hash PRIVATE ${INTERNAL_TEST_DEPS})
get_directory_property(SHA3_IMPL
DIRECTORY ${PROJECT_SOURCE_DIR}/src/crypto
DEFINITION SHA3_IMPL)
add_executable(test_sha3 test_sha3.c ${SHA3_IMPL} ${PROJECT_SOURCE_DIR}/src/common/common.c)
target_link_libraries(test_sha3 ${INTERNAL_TEST_DEPS})
target_link_libraries(test_sha3 PRIVATE ${INTERNAL_TEST_DEPS})
set(UNIX_TESTS test_aes test_hash test_sha3)
set(PYTHON3_EXEC python3)
if(BUILD_SHARED_LIBS)
set(USE_LIBOQS_SO --use_liboqs_so)
@ -48,29 +43,29 @@ set(API_TEST_DEPS oqs ${LIBM})
# KEM API tests
add_executable(example_kem example_kem.c)
target_link_libraries(example_kem ${API_TEST_DEPS})
target_link_libraries(example_kem PRIVATE ${API_TEST_DEPS})
add_executable(kat_kem kat_kem.c)
target_link_libraries(kat_kem ${API_TEST_DEPS})
target_link_libraries(kat_kem PRIVATE ${API_TEST_DEPS})
add_executable(test_kem test_kem.c)
target_link_libraries(test_kem ${API_TEST_DEPS})
target_link_libraries(test_kem PRIVATE ${API_TEST_DEPS})
add_executable(speed_kem speed_kem.c)
target_link_libraries(speed_kem ${API_TEST_DEPS})
target_link_libraries(speed_kem PRIVATE ${API_TEST_DEPS})
# SIG API tests
add_executable(example_sig example_sig.c)
target_link_libraries(example_sig ${API_TEST_DEPS})
target_link_libraries(example_sig PRIVATE ${API_TEST_DEPS})
add_executable(kat_sig kat_sig.c)
target_link_libraries(kat_sig ${API_TEST_DEPS})
target_link_libraries(kat_sig PRIVATE ${API_TEST_DEPS})
add_executable(test_sig test_sig.c)
target_link_libraries(test_sig ${API_TEST_DEPS})
target_link_libraries(test_sig PRIVATE ${API_TEST_DEPS})
add_executable(speed_sig speed_sig.c)
target_link_libraries(speed_sig ${API_TEST_DEPS})
target_link_libraries(speed_sig PRIVATE ${API_TEST_DEPS})
# TODO: Get CMake to find python.
# and set PATH variable in Windows

View File

@ -61,12 +61,6 @@ static void print_oqs_configuration(void) {
#else
printf("SHA-3: C\n");
#endif
#if defined(OQS_COMPILE_CFLAGS)
printf("CFLAGS: %s\n", OQS_COMPILE_CFLAGS);
#endif
#if defined(OQS_COMPILE_LDFLAGS)
printf("LDFLAGS: %s\n", OQS_COMPILE_LDFLAGS);
#endif
}
static void print_system_info(void) {