forked from sebastinas/bfe-bf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
139 lines (113 loc) · 4.33 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
# honor visibility properties
cmake_policy(SET CMP0063 NEW)
# enforce IPO if enabled
cmake_policy(SET CMP0069 NEW)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build." FORCE)
endif()
project(bfe LANGUAGES C CXX VERSION 2.0 DESCRIPTION "Bloom Filter Encryption library")
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# settings
set(MAX_BLOOMFILTER_HASH_COUNT 16 CACHE STRING "Maximal number of bloom filter hash functions.")
set(MAX_BFE_KEY_SIZE 32 CACHE STRING "Maximal size of encapsulated key.")
set(TBFE_ARITY 2 CACHE STRING "Arity of the TBFE tree.")
include(GNUInstallDirs)
include(CheckCCompilerFlag)
include(CheckIPOSupported)
include(CheckIncludeFiles)
include(CheckSymbolExists)
function(check_c_compiler_flag_and_add flag result)
check_c_compiler_flag("${flag}" ${result})
if(${result})
add_compile_options("${flag}")
endif()
endfunction()
check_c_compiler_flag_and_add(-Wall CC_SUPPORTS_WALL)
check_c_compiler_flag_and_add(-Wextra CC_SUPPORTS_WEXTRA)
check_c_compiler_flag_and_add(-Wshadow CC_SUPPORTS_WSHADOW)
check_c_compiler_flag_and_add(-Werror=vla CC_SUPPORTS_WERROR_VLA)
# check availability of some functions
check_symbol_exists(explicit_bzero string.h HAVE_EXPLICIT_BZERO)
check_ipo_supported(RESULT LTO_SUPPORTED)
find_package(relic REQUIRED)
find_package(Doxygen)
find_package(OpenMP REQUIRED)
find_package(libsodium REQUIRED)
find_package(cxxopts)
# generate config.h
configure_file(config.h.in config.h)
list(APPEND BFE_SOURCES
FIPS202-opt64/KeccakHash.c
FIPS202-opt64/KeccakP-1600-opt64.c
FIPS202-opt64/KeccakSpongeWidth1600.c
bfe-bf.c
core.c
crypto_api.c
tbfe-bbg.c
vector.c)
add_library(bfe SHARED ${BFE_SOURCES})
add_library(bfe_static STATIC ${BFE_SOURCES})
target_compile_definitions(bfe_static PRIVATE BFE_STATIC)
if(LTO_SUPPORTED)
set_target_properties(bfe_static PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
set_target_properties(bfe PROPERTIES VERSION ${PROJECT_VERSION})
set_target_properties(bfe PROPERTIES C_VISIBILITY_PRESET hidden)
if(LTO_SUPPORTED)
set_target_properties(bfe PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
configure_file(bfe.pc.in bfe.pc @ONLY)
target_link_libraries(bfe PRIVATE relic::relic)
target_link_libraries(bfe PRIVATE m)
target_include_directories(bfe PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(bfe PRIVATE OpenMP::OpenMP_C)
target_link_libraries(bfe PRIVATE libsodium::sodium)
target_link_libraries(bfe_static PUBLIC relic::relic)
target_link_libraries(bfe_static PUBLIC m)
target_include_directories(bfe_static PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(bfe_static PUBLIC OpenMP::OpenMP_C)
target_link_libraries(bfe_static PUBLIC libsodium::sodium)
install(TARGETS bfe
EXPORT bfe-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install(FILES ${CMAKE_BINARY_DIR}/bfe.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/bfe)
install(EXPORT bfe-targets
NAMESPACE bfe::
FILE bfe-config.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/bfe)
if(DOXYGEN_FOUND)
set(DOXYGEN_RECURSIVE NO)
set(DOXYGEN_EXTRACT_ALL YES)
set(DOXYGEN_OPTIMIZE_OUTPUT_FOR_C YES)
set(DOXYGEN_TYPEDEF_HIDES_STRUCT YES)
set(DOXYGEN_SOURCE_BROWSER YES)
set(DOXYGEN_PREDEFINED "BFE_BF_VISIBLE=")
set(DOXYGEN_ENABLE_PREPROCESSING YES)
set(DOXYGEN_MACRO_EXPANSION YES)
set(DOXYGEN_EXPAND_ONLY_PREDEF YES)
set(DOXYGEN_USE_PDFLATEX YES)
set(DOXYGEN_GENERATE_LATEX YES)
set(DOXYGEN_GENERATE_HTML YES)
doxygen_add_docs(doxygen ${CMAKE_CURRENT_SOURCE_DIR}/include COMMENT "Generate doxygen documentation")
endif()
# benchmarks
if(cxxopts_FOUND)
add_executable(bench bench.cpp)
target_link_libraries(bench PRIVATE bfe cxxopts::cxxopts)
if(LTO_SUPPORTED)
set_target_properties(bench PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
target_include_directories(bench PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
endif()
# testing
enable_testing()
add_subdirectory(tests)