1
- cmake_minimum_required (VERSION 2.8.8 )
1
+ cmake_minimum_required (VERSION 3.0 )
2
2
include (CheckFunctionExists)
3
+ include (CheckSymbolExists)
3
4
include (CheckLibraryExists)
4
5
include (CheckIncludeFiles)
5
6
include (CheckTypeSize)
@@ -8,7 +9,7 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}" ${CMAKE_MODULE_PATH})
8
9
include (cmake_export_symbol)
9
10
include (GNUInstallDirs)
10
11
11
- project (LibreSSL C)
12
+ project (LibreSSL C ASM )
12
13
13
14
enable_testing ()
14
15
@@ -28,10 +29,11 @@ string(REPLACE ":" "." TLS_VERSION ${TLS_VERSION})
28
29
string (REGEX REPLACE "\\ ..*" "" TLS_MAJOR_VERSION ${TLS_VERSION} )
29
30
30
31
option (LIBRESSL_SKIP_INSTALL "Skip installation" ${LIBRESSL_SKIP_INSTALL} )
32
+ option (LIBRESSL_APPS "Build apps" ON )
33
+ option (LIBRESSL_TESTS "Build tests" ON )
31
34
option (ENABLE_ASM "Enable assembly" ON )
32
35
option (ENABLE_EXTRATESTS "Enable extra tests that may be unreliable on some platforms" OFF )
33
36
option (ENABLE_NC "Enable installing TLS-enabled nc(1)" OFF )
34
- option (ENABLE_VSTEST "Enable test on Visual Studio" OFF )
35
37
set (OPENSSLDIR ${OPENSSLDIR} CACHE PATH "Set the default openssl directory" FORCE)
36
38
37
39
if (NOT LIBRESSL_SKIP_INSTALL)
@@ -47,39 +49,45 @@ endif()
47
49
48
50
if (CMAKE_SYSTEM_NAME MATCHES "OpenBSD" )
49
51
add_definitions (-DHAVE_ATTRIBUTE__BOUNDED__)
52
+ add_definitions (-DHAVE_ATTRIBUTE__DEAD__)
50
53
endif ()
51
54
52
55
if (CMAKE_SYSTEM_NAME MATCHES "Linux" )
53
56
add_definitions (-D_DEFAULT_SOURCE)
54
57
add_definitions (-D_BSD_SOURCE)
55
58
add_definitions (-D_POSIX_SOURCE)
56
59
add_definitions (-D_GNU_SOURCE)
60
+ set (PLATFORM_LIBS ${PLATFORM_LIBS} pthread)
57
61
endif ()
58
62
59
- if (CMAKE_SYSTEM_NAME MATCHES "MINGW" )
63
+ if (WIN32 OR ( CMAKE_SYSTEM_NAME MATCHES "MINGW" ) )
60
64
set (BUILD_NC false )
65
+ add_definitions (-D_GNU_SOURCE)
66
+ add_definitions (-D_POSIX)
67
+ add_definitions (-D_POSIX_SOURCE)
68
+ add_definitions (-D__USE_MINGW_ANSI_STDIO)
61
69
endif ()
62
70
63
- if (WIN32 )
64
- set (BUILD_NC false )
65
- endif ()
71
+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 -Wall" )
66
72
67
73
if (CMAKE_SYSTEM_NAME MATCHES "HP-UX" )
68
74
if (CMAKE_C_COMPILER MATCHES "gcc" )
69
- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall - std=gnu99 -fno-strict-aliasing" )
75
+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -fno-strict-aliasing" )
70
76
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mlp64" )
71
77
else ()
72
- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O2 +DD64 +Otype_safety=off" )
78
+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} +DD64 +Otype_safety=off" )
73
79
endif ()
74
80
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_XOPEN_SOURCE=600 -D__STRICT_ALIGNMENT" )
81
+ set (PLATFORM_LIBS ${PLATFORM_LIBS} pthread)
75
82
endif ()
76
83
77
84
if (CMAKE_SYSTEM_NAME MATCHES "SunOS" )
78
- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall - std=gnu99 -fno-strict-aliasing" )
85
+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -fno-strict-aliasing" )
79
86
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__EXTENSIONS__" )
80
87
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_XOPEN_SOURCE=600" )
81
88
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DBSD_COMP" )
82
- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fpic -m64" )
89
+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fpic" )
90
+ set (PLATFORM_LIBS ${PLATFORM_LIBS} nsl socket)
83
91
endif ()
84
92
85
93
add_definitions (-DLIBRESSL_INTERNAL)
@@ -98,8 +106,9 @@ if(WIN32)
98
106
add_definitions (-D_CRT_SECURE_NO_WARNINGS)
99
107
add_definitions (-D_CRT_DEPRECATED_NO_WARNINGS)
100
108
add_definitions (-D_REENTRANT -D_POSIX_THREAD_SAFE_FUNCTIONS)
101
- add_definitions (-DWIN32_LEAN_AND_MEAN -D_WIN32_WINNT=0x0501 )
109
+ add_definitions (-DWIN32_LEAN_AND_MEAN -D_WIN32_WINNT=0x0600 )
102
110
add_definitions (-DCPPFLAGS -DOPENSSL_NO_SPEED -DNO_SYSLOG -DNO_CRYPT)
111
+ set (PLATFORM_LIBS ${PLATFORM_LIBS} ws2_32)
103
112
endif ()
104
113
105
114
if (MSVC )
@@ -154,11 +163,6 @@ if(HAVE_ASPRINTF)
154
163
add_definitions (-DHAVE_ASPRINTF)
155
164
endif ()
156
165
157
- check_function_exists(inet_pton HAVE_INET_PTON)
158
- if (HAVE_INET_PTON)
159
- add_definitions (-DHAVE_INET_PTON)
160
- endif ()
161
-
162
166
check_function_exists(reallocarray HAVE_REALLOCARRAY)
163
167
if (HAVE_REALLOCARRAY)
164
168
add_definitions (-DHAVE_REALLOCARRAY)
@@ -229,11 +233,31 @@ if(HAVE_GETENTROPY)
229
233
add_definitions (-DHAVE_GETENTROPY)
230
234
endif ()
231
235
232
- check_function_exists (getpagesize HAVE_GETPAGESIZE)
236
+ check_symbol_exists (getpagesize unistd.h HAVE_GETPAGESIZE)
233
237
if (HAVE_GETPAGESIZE)
234
238
add_definitions (-DHAVE_GETPAGESIZE)
235
239
endif ()
236
240
241
+ check_function_exists(getprogname HAVE_GETPROGNAME)
242
+ if (HAVE_GETPROGNAME)
243
+ add_definitions (-DHAVE_GETPROGNAME)
244
+ endif ()
245
+
246
+ check_function_exists(syslog_r HAVE_SYSLOG_R)
247
+ if (HAVE_SYSLOG_R)
248
+ add_definitions (-DHAVE_SYSLOG_R)
249
+ endif ()
250
+
251
+ check_function_exists(syslog HAVE_SYSLOG)
252
+ if (HAVE_SYSLOG)
253
+ add_definitions (-DHAVE_SYSLOG)
254
+ endif ()
255
+
256
+ check_symbol_exists(timespecsub sys/time.h HAVE_TIMESPECSUB)
257
+ if (HAVE_TIMESPECSUB)
258
+ add_definitions (-DHAVE_TIMESPECSUB)
259
+ endif ()
260
+
237
261
check_function_exists(timingsafe_bcmp HAVE_TIMINGSAFE_BCMP)
238
262
if (HAVE_TIMINGSAFE_BCMP)
239
263
add_definitions (-DHAVE_TIMINGSAFE_BCMP)
@@ -258,46 +282,36 @@ if(ENABLE_ASM)
258
282
if ("${CMAKE_C_COMPILER_ABI} " STREQUAL "ELF" )
259
283
if ("${CMAKE_SYSTEM_PROCESSOR} " MATCHES "(x86_64|amd64)" )
260
284
set (HOST_ASM_ELF_X86_64 true )
285
+ elseif ("${CMAKE_SYSTEM_PROCESSOR} " MATCHES "arm" )
286
+ set (HOST_ASM_ELF_ARMV4 true )
261
287
elseif (CMAKE_SYSTEM_NAME STREQUAL "SunOS" AND "${CMAKE_SYSTEM_PROCESSOR} " STREQUAL "i386" )
262
288
set (HOST_ASM_ELF_X86_64 true )
263
289
endif ()
264
290
elseif (APPLE AND "${CMAKE_SYSTEM_PROCESSOR} " STREQUAL "x86_64" )
265
291
set (HOST_ASM_MACOSX_X86_64 true )
292
+ elseif (MSVC AND "${CMAKE_GENERATOR} " MATCHES "Win64" AND FALSE )
293
+ # XXX Disabled for now, CMake's MASM support seems to either never
294
+ # build supply ASM or build it with the C compiler in a mode where it
295
+ # does not parse correctly. It might be easier to get NASM support working.
296
+ set (HOST_ASM_MASM_X86_64 true )
297
+ ENABLE_LANGUAGE (ASM_MASM)
298
+ elseif (CMAKE_SYSTEM_NAME MATCHES "MINGW" AND "${CMAKE_SYSTEM_PROCESSOR} " STREQUAL "x86_64" )
299
+ set (HOST_ASM_MINGW64_X86_64 true )
266
300
endif ()
267
301
endif ()
268
302
269
- if (NOT (CMAKE_SYSTEM_NAME MATCHES "(Darwin|CYGWIN)" ))
270
- set (BUILD_SHARED true )
271
- endif ()
272
-
273
- # USE_SHARED builds applications (e.g. openssl) using shared LibreSSL.
274
- # By default, applications use LibreSSL static library to avoid dependencies.
275
- # USE_SHARED isn't set by default; use -DUSE_SHARED=ON with CMake to enable.
276
- # Can be helpful for debugging; don't use for public releases.
277
- if (NOT BUILD_SHARED)
278
- set (USE_SHARED off )
279
- endif ()
280
-
281
- if (USE_SHARED)
282
- set (OPENSSL_LIBS tls-shared ssl-shared crypto-shared)
283
- else ()
284
- set (OPENSSL_LIBS tls ssl crypto)
285
- endif ()
286
-
287
- if (CMAKE_HOST_WIN32 )
288
- set (OPENSSL_LIBS ${OPENSSL_LIBS} ws2_32)
289
- endif ()
290
303
if (CMAKE_SYSTEM_NAME MATCHES "Linux" )
304
+ # Check if we need -lrt to get clock_gettime on Linux
291
305
check_library_exists(rt clock_gettime "time.h" HAVE_CLOCK_GETTIME)
292
306
if (HAVE_CLOCK_GETTIME)
293
- set (OPENSSL_LIBS ${OPENSSL_LIBS } rt)
307
+ set (PLATFORM_LIBS ${PLATFORM_LIBS } rt)
294
308
endif ()
309
+ else ()
310
+ # Otherwise, simply check if it exists
311
+ check_function_exists(clock_gettime HAVE_CLOCK_GETTIME)
295
312
endif ()
296
- if (CMAKE_SYSTEM_NAME MATCHES "HP-UX" )
297
- set (OPENSSL_LIBS ${OPENSSL_LIBS} pthread)
298
- endif ()
299
- if (CMAKE_SYSTEM_NAME MATCHES "SunOS" )
300
- set (OPENSSL_LIBS ${OPENSSL_LIBS} nsl socket)
313
+ if (HAVE_CLOCK_GETTIME)
314
+ add_definitions (-DHAVE_CLOCK_GETTIME)
301
315
endif ()
302
316
303
317
check_type_size(time_t SIZEOF_TIME_T)
@@ -309,15 +323,20 @@ if(SIZEOF_TIME_T STREQUAL "4")
309
323
endif ()
310
324
add_definitions (-DSIZEOF_TIME_T=${SIZEOF_TIME_T} )
311
325
326
+ set (OPENSSL_LIBS tls ssl crypto ${PLATFORM_LIBS} )
327
+
312
328
add_subdirectory (crypto)
313
329
add_subdirectory (ssl)
314
- add_subdirectory (apps)
330
+ if (LIBRESSL_APPS)
331
+ add_subdirectory (apps)
332
+ endif ()
315
333
add_subdirectory (tls)
316
334
add_subdirectory (include )
317
335
if (NOT MSVC )
318
336
add_subdirectory (man)
319
337
endif ()
320
- if (NOT MSVC OR ENABLE_VSTEST)
338
+ # Tests require the openssl executable and are unavailable when building shared libraries
339
+ if (LIBRESSL_APPS AND LIBRESSL_TESTS)
321
340
add_subdirectory (tests)
322
341
endif ()
323
342
@@ -327,6 +346,7 @@ if(NOT MSVC)
327
346
set (exec_prefix \${prefix} )
328
347
set (libdir \${exec_prefix} /${CMAKE_INSTALL_LIBDIR} )
329
348
set (includedir \${prefix} /include )
349
+ string (REGEX REPLACE ";" " -l" PLATFORM_LDADD ";${PLATFORM_LIBS} " )
330
350
file (STRINGS "VERSION" VERSION LIMIT_COUNT 1)
331
351
file (GLOB OPENSSL_PKGCONFIGS "*.pc.in" )
332
352
foreach (file ${OPENSSL_PKGCONFIGS} )
0 commit comments