-
Notifications
You must be signed in to change notification settings - Fork 8
/
CMakeLists.txt
84 lines (69 loc) · 2.62 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
cmake_minimum_required(VERSION 3.16)
set(CMAKE_CXX_STANDARD 17)
project(pqc C CXX)
set(SANITIZE OFF CACHE BOOL "Use address sanitizer")
set(COVERAGE OFF CACHE BOOL "Use code coverage")
set(HASWELL OFF CACHE BOOL "Use MOVBE, MMX, SSE, SSE2, SSE3, SSSE3, SSE4.1, SSE4.2, POPCNT, CX16, SAHF, FXSR, AVX, XSAVE, PCLMUL, FSGSBASE, RDRND, F16C, AVX2, BMI, BMI2, LZCNT, FMA, MOVBE and HLE")
set(BENCHMARK ON CACHE BOOL "Build benchmark")
set(PYTHON ON CACHE BOOL "Build Python module")
set(EXAMPLES ON CACHE BOOL "Build examples")
set(TESTS ON CACHE BOOL "Build tests")
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
set(COMPILER_CLANG ON)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/compiler.id" "Clang")
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(COMPILER_GCC ON)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/compiler.id" "GCC")
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set(COMPILER_MSVC ON)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/compiler.id" "MSVC")
endif()
if(COMPILER_CLANG)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_LIBCPP_DEBUG")
elseif(COMPILER_GCC)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_GLIBCXX_DEBUG")
endif()
if(SANITIZE)
if(COMPILER_CLANG OR COMPILER_GCC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer")
endif()
endif()
if(COVERAGE)
if(COMPILER_CLANG OR COMPILER_GCC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
endif()
endif()
if(HASWELL)
if(COMPILER_CLANG OR COMPILER_GCC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=haswell")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=haswell")
elseif(COMPILER_MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /arch:AVX2")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:AVX2")
endif()
endif()
if(COMPILER_CLANG OR COMPILER_GCC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror")
elseif(COMPILER_MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4 /WX /wd4100")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /WX /wd4100")
endif()
if(PYTHON OR TESTS)
enable_testing()
endif()
add_subdirectory(src)
if(PYTHON)
add_subdirectory(python)
endif()
if(TESTS)
add_subdirectory(test)
endif()
if(EXAMPLES)
add_subdirectory(examples)
endif()
if(BENCHMARK)
add_subdirectory(benchmark)
endif()