-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
201 lines (154 loc) · 6.77 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
cmake_minimum_required(VERSION 3.5.0)
project(kdf-lib VERSION 1.0.2)
#
# Global config
#
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)
#
# Options
#
option(KDFLIB_KERNEL_MODE "Build kdf-lib for kernel mode too (Windows only)." OFF)
option(KDFLIB_GENERATE_DOCS "Generate documentation for kdf-lib." OFF)
option(KDFLIB_DOCS_ONLY "Generate documentation only (kdf-lib will not be built." OFF)
option(KDFLIB_GITHUB_DOCS "Generate documentation for GitHub." OFF)
option(KDFLIB_PRETTY_DOCS "Use graphwiz for diagrams." OFF)
option(KDFLIB_ENABLE_TESTING "Enable testing of ciphers, modes of operation and other functions." ON)
#
# Configuration
#
if (WIN32)
set(KDFLIB_WINDOWS_BUILD ON)
else (WIN32)
set(KDFLIB_WINDOWS_BUILD OFF)
endif (WIN32)
if (KDFLIB_GENERATE_DOCS AND KDFLIB_DOCS_ONLY)
#
# Building docs only
#
set(KDFLIB_BUILD_LIB OFF)
set(KDFLIB_BUILD_TESTS OFF)
set(KDFLIB_BUILD_DOCS ON)
set(KDFLIB_BUILD_GITHUB_DOCS ${KDFLIB_GITHUB_DOCS})
set(KDFLIB_BUILD_PRETTY_DOCS ${KDFLIB_PRETTY_DOCS})
#
# Just set this to OFF, because no binary is built
#
set(KDFLIB_BUILD_KERNEL_LIB OFF)
else (KDFLIB_GENERATE_DOCS AND KDFLIB_DOCS_ONLY)
#
# Here I assume other flags, but library
# will be built always here.
#
set(KDFLIB_BUILD_LIB ON)
set(KDFLIB_BUILD_TESTS ${KDFLIB_ENABLE_TESTING})
set(KDFLIB_BUILD_DOCS ${KDFLIB_GENERATE_DOCS})
set(KDFLIB_BUILD_GITHUB_DOCS ${KDFLIB_GITHUB_DOCS})
set(KDFLIB_BUILD_PRETTY_DOCS ${KDFLIB_PRETTY_DOCS})
#
# Kernel mode library is supporten on Windows only
#
if (KDFLIB_WINDOWS_BUILD)
set(KDFLIB_BUILD_KERNEL_LIB ${KDFLIB_KERNEL_MODE})
else (KDFLIB_WINDOWS_BUILD)
message(STATUS "[${PROJECT_NAME}]: Non-Windows version, KDFLIB_BUILD_KERNEL_LIB will set to OFF.")
set(KDFLIB_BUILD_KERNEL_LIB OFF)
endif (KDFLIB_WINDOWS_BUILD)
endif (KDFLIB_GENERATE_DOCS AND KDFLIB_DOCS_ONLY)
message("[${PROJECT_NAME}]: KDFLIB_WINDOWS_BUILD = ${KDFLIB_WINDOWS_BUILD}")
message("[${PROJECT_NAME}]: KDFLIB_BUILD_LIB = ${KDFLIB_BUILD_LIB}")
message("[${PROJECT_NAME}]: KDFLIB_BUILD_KERNEL_LIB = ${KDFLIB_BUILD_KERNEL_LIB}")
message("[${PROJECT_NAME}]: KDFLIB_BUILD_TESTS = ${KDFLIB_BUILD_TESTS}")
message("[${PROJECT_NAME}]: KDFLIB_BUILD_DOCS = ${KDFLIB_BUILD_DOCS}")
message("[${PROJECT_NAME}]: KDFLIB_BUILD_GITHUB_DOCS = ${KDFLIB_BUILD_GITHUB_DOCS}")
message("[${PROJECT_NAME}]: KDFLIB_BUILD_PRETTY_DOCS = ${KDFLIB_BUILD_PRETTY_DOCS}")
#
# Just sanity check if we are going well
#
if (NOT KDFLIB_BUILD_LIB AND KDFLIB_BUILD_TESTS)
message(FATAL_ERROR "[${PROJECT_NAME}]: cannot build tests without building kdf-lib itself")
endif (NOT KDFLIB_BUILD_LIB AND KDFLIB_BUILD_TESTS)
#
# Set global directories
#
set(KDFLIB_ROOT ${CMAKE_CURRENT_LIST_DIR})
set(KDFLIB_SOURCES_ROOT ${KDFLIB_ROOT}/src)
set(KDFLIB_INCLUDE_ROOT ${KDFLIB_ROOT}/include)
set(KDFLIB_INCLUDE_DIRECTORIES ${KDFLIB_INCLUDE_ROOT})
#
# Set output directories for all targets
#
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/out)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY})
#
# Now let's build targets according to the flags set before
#
if (KDFLIB_BUILD_LIB)
#
# FindWDK module
#
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/third-party/FindWDK/cmake)
#
# Preprocessor definitions
#
add_compile_definitions(UNICODE)
#
# Implementation directories
#
set(KDFLIB_KDFS_SOURCES_DIR ${KDFLIB_SOURCES_ROOT}/kdfs)
set(KDFLIB_KDFS_INCLUDE_DIR ${KDFLIB_INCLUDE_ROOT}/kdfs)
set(KDFLIB_INTERNAL_INCLUDE_DIRECTORIES ${KDFLIB_INCLUDE_DIRECTORIES})
set(KDFLIB_R1323665_1_022-2018_SOURCES_DIR ${KDFLIB_KDFS_SOURCES_DIR}/r1323665_1_022-2018)
set(KDFLIB_R1323665_1_022-2018_INCLUDE_DIR ${KDFLIB_KDFS_INCLUDE_DIR}/r1323665_1_022-2018)
#
# Source files
#
set(KDFLIB_SOURCE_FILES ${KDFLIB_R1323665_1_022-2018_SOURCES_DIR}/kdf.c)
set(KDFLIB_HEADER_FILES ${KDFLIB_R1323665_1_022-2018_INCLUDE_DIR}/kdf.h
${KDFLIB_INCLUDE_ROOT}/kdflib.h)
set(KDFLIB_SOURCES ${KDFLIB_SOURCE_FILES}
${KDFLIB_HEADER_FILES})
#
# Library itself (may be built for user mode as
# well as for kernel mode)
#
add_library(kdf-lib ${KDFLIB_SOURCES})
if (KDFLIB_BUILD_KERNEL_LIB)
message("[${PROJECT_NAME}]: Building additional target for kernel mode")
find_package(WDK REQUIRED)
wdk_add_library(kdf-lib-km ${KDFLIB_SOURCES})
endif (KDFLIB_BUILD_KERNEL_LIB)
#
# Include directories
#
target_include_directories(kdf-lib PRIVATE ${KDFLIB_INTERNAL_INCLUDE_DIRECTORIES})
if (KDFLIB_BUILD_KERNEL_LIB)
target_include_directories(kdf-lib-km PRIVATE ${KDFLIB_INTERNAL_INCLUDE_DIRECTORIES})
endif (KDFLIB_BUILD_KERNEL_LIB)
#
# On non-Windows builds it is necessary to add some intrinsics support
#
if (NOT KDFLIB_WINDOWS_BUILD)
target_compile_options(kdf-lib PRIVATE -msse2)
endif (NOT KDFLIB_WINDOWS_BUILD)
endif (KDFLIB_BUILD_LIB)
if (KDFLIB_BUILD_TESTS)
include(CTest)
#
# Tests target
#
add_subdirectory(tests)
endif (KDFLIB_BUILD_TESTS)
if (KDFLIB_BUILD_DOCS)
#
# Docs target
#
add_subdirectory(docs)
endif (KDFLIB_BUILD_DOCS)