-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
169 lines (145 loc) · 6.6 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
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.11)
CMAKE_POLICY(SET CMP0003 NEW)
PROJECT(picotls)
# The following lines are examples for OpenSSL
#set(OPENSSL_ROOT_DIR /home/user/proj2/openssl)
#set(OPENSSL_USE_STATIC_LIBS TRUE)
# The following lines are examples for BoringSSL
#set(BORING_ROOT /home/user/proj/thirdparty/boringssl)
#set(BORING_LIBRARY_DIR /home/user/proj/thirdparty/lib)
# The following lines are examples for Brotli
#set(BROTLI_ROOT /home/user/proj/thirdparty/brotli)
#set(BROTLI_DEC /home/user/proj/thirdparty/lib/libbrotlidec-static.a)
#set(BROTLI_ENC /home/user/proj/thirdparty/lib/libbrotlienc-static.a)
FIND_PACKAGE(PkgConfig REQUIRED)
IF (BORING_ROOT AND BORING_LIBRARY_DIR)
set(PKG_CONFIG_EXECUTABLE 0)
set(OPENSSL_INCLUDE_DIR "${BORING_ROOT}/include")
set(OPENSSL_FOUND ON)
set(OPENSSL_SSL_LIBRARY ${BORING_LIBRARY_DIR}/libssl.a ${BORING_LIBRARY_DIR}/libdecrepit.a)
set(OPENSSL_CRYPTO_LIBRARY "${BORING_LIBRARY_DIR}/libcrypto.a")
set(OPENSSL_LIBRARIES ${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY})
set(OPENSSL_VERSION "1.1.0a")
message("Using BoringSSL lib: " ${OPENSSL_LIBRARIES})
ELSE ()
FIND_PACKAGE(OpenSSL)
message("Using system OPENSSL lib: " ${OPENSSL_LIBRARIES})
ENDIF ()
IF (BROTLI_ROOT)
set(BROTLI_ENC_INCLUDE_DIRS $BROTLI_ROOT/c/include)
message("Using Brotli include")
ENDIF ()
IF (BROTLI_DEC)
set(BROTLI_DEC_FOUND ON)
message("Using Brotli dec library")
ELSE ()
PKG_CHECK_MODULES(BROTLI_DEC libbrotlidec)
ENDIF ()
IF (BROTLI_ENC)
set(BROLI_ENC_FOUND ON)
message("Using Brotli enc library")
ELSE ()
PKG_CHECK_MODULES(BROTLI_ENC libbrotlienc)
ENDIF ()
SET(CMAKE_C_FLAGS "-std=c99 -Wall -O2 -g ${CC_WARNING_FLAGS} ${CMAKE_C_FLAGS}")
INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR} deps/cifra/src/ext deps/cifra/src deps/micro-ecc deps/picotest include)
SET(MINICRYPTO_LIBRARY_FILES
deps/micro-ecc/uECC.c
deps/cifra/src/aes.c
deps/cifra/src/blockwise.c
deps/cifra/src/chacha20.c
deps/cifra/src/chash.c
deps/cifra/src/curve25519.c
deps/cifra/src/drbg.c
deps/cifra/src/hmac.c
deps/cifra/src/gcm.c
deps/cifra/src/gf128.c
deps/cifra/src/modes.c
deps/cifra/src/poly1305.c
deps/cifra/src/sha256.c
deps/cifra/src/sha512.c)
IF (BORING_ROOT)
SET(MINICRYPTO_LIBRARY_FILES ${MINICRYPTO_LIBRARY_FILES})
ENDIF ()
SET(CORE_FILES
lib/picotls.c
lib/pembase64.c)
IF (BROTLI_DEC_FOUND AND BROTLI_ENC_FOUND)
INCLUDE_DIRECTORIES(${BROTLI_DEC_INCLUDE_DIRS} ${BROTLI_ENC_INCLUDE_DIRS})
LINK_DIRECTORIES(${BROTLI_DEC_LIBRARY_DIRS} ${BROTLI_ENC_LIBRARY_DIRS})
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DPICOTLS_USE_BROTLI=1")
LIST(APPEND CORE_FILES
lib/certificate_compression.c)
LIST(APPEND CORE_EXTRA_LIBS ${BROTLI_DEC_LIBRARIES} ${BROTLI_ENC_LIBRARIES})
ENDIF ()
ADD_LIBRARY(picotls-core ${CORE_FILES})
TARGET_LINK_LIBRARIES(picotls-core ${CORE_EXTRA_LIBS})
ADD_LIBRARY(picotls-minicrypto ${MINICRYPTO_LIBRARY_FILES} lib/cifra.c lib/minicrypto-pem.c lib/uecc.c lib/asn1.c lib/ffx.c)
TARGET_LINK_LIBRARIES(picotls-minicrypto picotls-core)
ADD_EXECUTABLE(test-minicrypto.t ${MINICRYPTO_LIBRARY_FILES} deps/picotest/picotest.c t/picotls.c t/minicrypto.c lib/asn1.c lib/pembase64.c lib/ffx.c)
SET(TEST_EXES test-minicrypto.t)
IF (OPENSSL_FOUND AND NOT (OPENSSL_VERSION VERSION_LESS "1.0.1"))
MESSAGE(WARNING "Enabling OpenSSL support")
INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR})
IF (BORING_ROOT)
ADD_LIBRARY(picotls-openssl lib/openssl.c lib/boring.c)
ELSE ()
ADD_LIBRARY(picotls-openssl lib/openssl.c)
ENDIF ()
TARGET_LINK_LIBRARIES(picotls-openssl ${OPENSSL_LIBRARIES} picotls-core ${CMAKE_DL_LIBS})
ADD_EXECUTABLE(cli t/cli.c lib/pembase64.c)
TARGET_LINK_LIBRARIES(cli picotls-openssl picotls-core)
ADD_EXECUTABLE(picotls-esni src/esni.c)
TARGET_LINK_LIBRARIES(picotls-esni picotls-openssl picotls-core ${OPENSSL_LIBRARIES} ${CMAKE_DL_LIBS})
ADD_EXECUTABLE(test-openssl.t ${MINICRYPTO_LIBRARY_FILES} lib/cifra.c lib/uecc.c lib/asn1.c lib/pembase64.c lib/ffx.c deps/picotest/picotest.c t/picotls.c t/openssl.c)
SET_TARGET_PROPERTIES(test-openssl.t PROPERTIES COMPILE_FLAGS "-DPTLS_MEMORY_DEBUG=1")
TARGET_LINK_LIBRARIES(test-openssl.t picotls-openssl)
ADD_EXECUTABLE(ptlsbench t/ptlsbench.c)
SET_TARGET_PROPERTIES(ptlsbench PROPERTIES COMPILE_FLAGS "-DPTLS_MEMORY_DEBUG=1")
TARGET_LINK_LIBRARIES(ptlsbench picotls-minicrypto picotls-openssl picotls-core ${OPENSSL_LIBRARIES} ${CMAKE_DL_LIBS})
SET(TEST_EXES ${TEST_EXES} test-openssl.t)
ELSE ()
MESSAGE(WARNING "Disabling OpenSSL support (requires 1.0.1 or newer) version is ${OPENSSL_VERSION}")
ENDIF ()
ADD_CUSTOM_TARGET(check env BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR} prove --exec '' -v ${CMAKE_CURRENT_BINARY_DIR}/*.t t/*.t WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DEPENDS ${TEST_EXES} cli)
IF (CMAKE_SYSTEM_NAME STREQUAL "Linux")
SET(CMAKE_C_FLAGS "-D_GNU_SOURCE -pthread ${CMAKE_C_FLAGS}")
ELSEIF ("${CMAKE_SYSTEM_NAME}" MATCHES "SunOS")
TARGET_LINK_LIBRARIES(cli "socket" "nsl")
ENDIF ()
FIND_LIBRARY(LIBC_RESOLV_LIB "resolv")
IF (LIBC_RESOLV_LIB)
TARGET_LINK_LIBRARIES(cli ${LIBC_RESOLV_LIB})
ENDIF ()
IF (BUILD_FUZZER)
IF (NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
MESSAGE(FATAL ERROR "The fuzzer needs clang as a compiler")
ENDIF()
ADD_EXECUTABLE(fuzz-asn1 fuzz/fuzz-asn1.c)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_GNU_SOURCE")
INCLUDE_DIRECTORIES(t include ${OPENSSL_INCLUDE_DIR})
ADD_DEFINITIONS(-DPTLS_FUZZ_HANDSHAKE=1)
ADD_EXECUTABLE(fuzz-server-hello fuzz/fuzz-server-hello.c)
ADD_EXECUTABLE(fuzz-client-hello fuzz/fuzz-client-hello.c)
IF (OSS_FUZZ)
# Use https://github.com/google/oss-fuzz compatible options
SET(LIB_FUZZER FuzzingEngine)
SET_TARGET_PROPERTIES(fuzz-asn1
fuzz-server-hello
fuzz-client-hello
PROPERTIES
LINKER_LANGUAGE CXX)
ELSE()
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=fuzzer-no-link")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=fuzzer-no-link")
SET_TARGET_PROPERTIES(fuzz-asn1
fuzz-server-hello
fuzz-client-hello
PROPERTIES
COMPILE_FLAGS "-fsanitize=fuzzer"
LINK_FLAGS "-fsanitize=fuzzer")
ENDIF (OSS_FUZZ)
TARGET_LINK_LIBRARIES(fuzz-asn1 picotls-minicrypto picotls-core picotls-openssl ${OPENSSL_LIBRARIES} ${LIB_FUZZER})
TARGET_LINK_LIBRARIES(fuzz-server-hello picotls-core picotls-openssl ${OPENSSL_LIBRARIES} ${LIB_FUZZER})
TARGET_LINK_LIBRARIES(fuzz-client-hello picotls-core picotls-openssl ${OPENSSL_LIBRARIES} ${LIB_FUZZER})
ENDIF()