1
+ cmake_minimum_required (VERSION 3.16.4)
1
2
if (MSVC )
2
- cmake_minimum_required (VERSION 3.16.4)
3
3
cmake_policy (SET CMP0091 NEW)
4
- else ()
5
- cmake_minimum_required (VERSION 3.0)
6
4
endif ()
7
5
8
6
project (LibreSSL C ASM)
@@ -41,6 +39,7 @@ option(ENABLE_ASM "Enable assembly" ON)
41
39
option (ENABLE_EXTRATESTS "Enable extra tests that may be unreliable on some platforms" OFF )
42
40
option (ENABLE_NC "Enable installing TLS-enabled nc(1)" OFF )
43
41
set (OPENSSLDIR ${OPENSSLDIR} CACHE PATH "Set the default openssl directory" FORCE)
42
+ set (LIBRESSL_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR} /cmake/LibreSSL" CACHE STRING "Installation directory for the CMake targets" )
44
43
45
44
option (USE_STATIC_MSVC_RUNTIMES "Use /MT instead of /MD in MSVC" OFF )
46
45
if (USE_STATIC_MSVC_RUNTIMES)
@@ -51,6 +50,20 @@ if(NOT LIBRESSL_SKIP_INSTALL)
51
50
set ( ENABLE_LIBRESSL_INSTALL ON )
52
51
endif (NOT LIBRESSL_SKIP_INSTALL)
53
52
53
+ # Set a default build type if none was specified
54
+ set (default_build_type "Release" )
55
+
56
+ if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES )
57
+ message (STATUS "Setting build type to '${default_build_type} ' as none was specified." )
58
+ set (CMAKE_BUILD_TYPE "${default_build_type} " CACHE
59
+ STRING "Choose the type of build." FORCE)
60
+ # Set the possible values of build type for cmake-gui
61
+ set_property (CACHE CMAKE_BUILD_TYPE PROPERTY
62
+ STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo" )
63
+ endif ()
64
+
65
+ # Enable asserts regardless of build type
66
+ add_definitions (-UNDEBUG)
54
67
55
68
set (BUILD_NC true )
56
69
@@ -79,7 +92,7 @@ if(WIN32 OR (CMAKE_SYSTEM_NAME MATCHES "MINGW"))
79
92
add_definitions (-D__USE_MINGW_ANSI_STDIO)
80
93
endif ()
81
94
82
- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 - Wall" )
95
+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall" )
83
96
84
97
if (CMAKE_SYSTEM_NAME MATCHES "HP-UX" )
85
98
if (CMAKE_C_COMPILER MATCHES "gcc" )
@@ -121,7 +134,7 @@ if(WIN32)
121
134
if (NOT CMAKE_SYSTEM_NAME MATCHES "WindowsStore" )
122
135
add_definitions (-D_WIN32_WINNT=0x0600)
123
136
endif ()
124
- set (PLATFORM_LIBS ${PLATFORM_LIBS} ws2_32 bcrypt)
137
+ set (PLATFORM_LIBS ${PLATFORM_LIBS} ws2_32 ntdll bcrypt)
125
138
endif ()
126
139
127
140
if (MSVC )
@@ -135,17 +148,17 @@ if(MSVC)
135
148
"C4100" # 'identifier' : unreferenced formal parameter
136
149
"C4127" # conditional expression is constant
137
150
"C4146" # unary minus operator applied to unsigned type,
138
- # result still unsigned
151
+ # result still unsigned
139
152
"C4244" # 'argument' : conversion from 'type1' to 'type2',
140
- # possible loss of data
153
+ # possible loss of data
141
154
"C4245" # 'conversion' : conversion from 'type1' to 'type2',
142
- # signed/unsigned mismatch
155
+ # signed/unsigned mismatch
143
156
"C4267" # 'var' : conversion from 'size_t' to 'type',
144
- # possible loss of data
157
+ # possible loss of data
145
158
"C4389" # 'operator' : signed/unsigned mismatch
146
159
"C4706" # assignment within conditional expression
147
160
"C4996" # The POSIX name for this item is deprecated.
148
- # Instead, use the ISO C and C++ conformant name
161
+ # Instead, use the ISO C and C++ conformant name
149
162
)
150
163
elseif (CMAKE_C_COMPILER_ID MATCHES "Intel" )
151
164
add_definitions (-D_CRT_SUPPRESS_RESTRICT)
@@ -176,6 +189,11 @@ if(HAVE_ASPRINTF)
176
189
add_definitions (-DHAVE_ASPRINTF)
177
190
endif ()
178
191
192
+ check_function_exists(getopt HAVE_GETOPT)
193
+ if (HAVE_GETOPT)
194
+ add_definitions (-DHAVE_GETOPT)
195
+ endif ()
196
+
179
197
check_function_exists(reallocarray HAVE_REALLOCARRAY)
180
198
if (HAVE_REALLOCARRAY)
181
199
add_definitions (-DHAVE_REALLOCARRAY)
@@ -306,28 +324,37 @@ if(HAVE_NETINET_IP_H)
306
324
add_definitions (-DHAVE_NETINET_IP_H)
307
325
endif ()
308
326
309
- if ("${CMAKE_SYSTEM_PROCESSOR} " MATCHES "(aarch64|arm64)" )
327
+ # This isn't ready for universal binaries yet, since we do conditional
328
+ # compilation based on the architecture, but this makes cross compiling for a
329
+ # single architecture work on macOS at least.
330
+ #
331
+ # Don't set CMAKE_OSX_ARCHITECTURES to more than a single value for now.
332
+ if (APPLE AND (NOT CMAKE_OSX_ARCHITECTURES STREQUAL "" ))
333
+ set (CMAKE_SYSTEM_PROCESSOR "${CMAKE_OSX_ARCHITECTURES} " )
334
+ endif ()
335
+
336
+ if ("${CMAKE_SYSTEM_PROCESSOR} " MATCHES "(aarch64|arm64|ARM64)" )
310
337
set (HOST_AARCH64 true )
311
338
elseif ("${CMAKE_SYSTEM_PROCESSOR} " MATCHES "arm" )
312
339
set (HOST_ARM true )
313
340
elseif ("${CMAKE_SYSTEM_NAME} " STREQUAL "SunOS" AND "${CMAKE_SYSTEM_PROCESSOR} " STREQUAL "i386" )
314
341
set (HOST_X86_64 true )
315
- elseif ("${CMAKE_SYSTEM_PROCESSOR} " MATCHES "(x86_64|amd64)" )
342
+ elseif ("${CMAKE_SYSTEM_PROCESSOR} " MATCHES "(x86_64|amd64|AMD64 )" )
316
343
set (HOST_X86_64 true )
317
- elseif ("${CMAKE_SYSTEM_NAME } " MATCHES "[i? 86|x86] " )
344
+ elseif ("${CMAKE_SYSTEM_PROCESSOR } " MATCHES "(i[3-6] 86|[xX]86) " )
318
345
set (ENABLE_ASM false )
319
346
set (HOST_I386 true )
320
- elseif ("${CMAKE_SYSTEM_NAME } " MATCHES "mips64" )
347
+ elseif ("${CMAKE_SYSTEM_PROCESSOR } " MATCHES "mips64" )
321
348
set (HOST_MIPS64 true )
322
- elseif ("${CMAKE_SYSTEM_NAME } " MATCHES "mips" )
349
+ elseif ("${CMAKE_SYSTEM_PROCESSOR } " MATCHES "mips" )
323
350
set (HOST_MIPS true )
324
- elseif ("${CMAKE_SYSTEM_NAME } " MATCHES "powerpc" )
351
+ elseif ("${CMAKE_SYSTEM_PROCESSOR } " MATCHES "powerpc" )
325
352
set (HOST_POWERPC true )
326
- elseif ("${CMAKE_SYSTEM_NAME } " MATCHES "ppc64" )
353
+ elseif ("${CMAKE_SYSTEM_PROCESSOR } " MATCHES "ppc64" )
327
354
set (HOST_PPC64 true )
328
- elseif ("${CMAKE_SYSTEM_NAME } " MATCHES "riscv64" )
355
+ elseif ("${CMAKE_SYSTEM_PROCESSOR } " MATCHES "riscv64" )
329
356
set (HOST_RISCV64 true )
330
- elseif ("${CMAKE_SYSTEM_NAME } " MATCHES "sparc64" )
357
+ elseif ("${CMAKE_SYSTEM_PROCESSOR } " MATCHES "sparc64" )
331
358
set (HOST_SPARC64 true )
332
359
else ()
333
360
set (ENABLE_ASM false )
@@ -348,7 +375,7 @@ if(ENABLE_ASM)
348
375
elseif (MSVC AND ("${CMAKE_GENERATOR} " MATCHES "Win64" OR "${CMAKE_GENERATOR_PLATFORM} " STREQUAL "x64" ))
349
376
set (HOST_ASM_MASM_X86_64 true )
350
377
ENABLE_LANGUAGE (ASM_MASM)
351
- elseif (CMAKE_SYSTEM_NAME MATCHES " MINGW" AND "${CMAKE_SYSTEM_PROCESSOR} " STREQUAL "x86_64" )
378
+ elseif (MINGW AND "${CMAKE_SYSTEM_PROCESSOR} " STREQUAL "x86_64" )
352
379
set (HOST_ASM_MINGW64_X86_64 true )
353
380
endif ()
354
381
endif ()
@@ -374,7 +401,6 @@ if(SIZEOF_TIME_T STREQUAL "4")
374
401
message (WARNING " ** Warning, this system is unable to represent times past 2038\n "
375
402
" ** It will behave incorrectly when handling valid RFC5280 dates" )
376
403
endif ()
377
- add_definitions (-DSIZEOF_TIME_T=${SIZEOF_TIME_T} )
378
404
379
405
set (OPENSSL_LIBS ssl crypto ${PLATFORM_LIBS} )
380
406
set (LIBTLS_LIBS tls ${PLATFORM_LIBS} )
@@ -416,6 +442,38 @@ if (BUILD_APPLE_XCFRAMEWORK)
416
442
endif (ENABLE_LIBRESSL_INSTALL)
417
443
endif (BUILD_APPLE_XCFRAMEWORK)
418
444
445
+ file (STRINGS "VERSION" VERSION LIMIT_COUNT 1)
446
+ include (CMakePackageConfigHelpers)
447
+ write_basic_package_version_file(
448
+ "LibreSSLConfigVersion.cmake"
449
+ VERSION "${VERSION} "
450
+ COMPATIBILITY SameMajorVersion
451
+ )
452
+
453
+ set (INCLUDE_DIRECTORY "${CMAKE_BINARY_DIR} /include" )
454
+ configure_package_config_file(
455
+ "${CMAKE_CURRENT_LIST_DIR} /LibreSSLConfig.cmake.in"
456
+ "${CMAKE_CURRENT_BINARY_DIR} /LibreSSLConfig.cmake"
457
+ PATH_VARS INCLUDE_DIRECTORY
458
+ INSTALL_DESTINATION "${CMAKE_CURRENT_BINARY_DIR} "
459
+ INSTALL_PREFIX "${CMAKE_CURRENT_BINARY_DIR} "
460
+ )
461
+
462
+ if (ENABLE_LIBRESSL_INSTALL)
463
+ set (INCLUDE_DIRECTORY "${CMAKE_INSTALL_INCLUDEDIR} " )
464
+ configure_package_config_file(
465
+ "${CMAKE_CURRENT_LIST_DIR} /LibreSSLConfig.cmake.in"
466
+ "${CMAKE_CURRENT_BINARY_DIR} /install-config/LibreSSLConfig.cmake"
467
+ PATH_VARS INCLUDE_DIRECTORY
468
+ INSTALL_DESTINATION "${LIBRESSL_INSTALL_CMAKEDIR} "
469
+ )
470
+ install (FILES
471
+ "${CMAKE_CURRENT_BINARY_DIR} /install-config/LibreSSLConfig.cmake"
472
+ "${CMAKE_CURRENT_BINARY_DIR} /LibreSSLConfigVersion.cmake"
473
+ DESTINATION "${LIBRESSL_INSTALL_CMAKEDIR} "
474
+ )
475
+ endif ()
476
+
419
477
if (ENABLE_LIBRESSL_INSTALL)
420
478
if (NOT MSVC )
421
479
# Create pkgconfig files.
@@ -426,7 +484,6 @@ if(ENABLE_LIBRESSL_INSTALL)
426
484
if (PLATFORM_LIBS)
427
485
string (REGEX REPLACE ";" " -l" PLATFORM_LDADD ";${PLATFORM_LIBS} " )
428
486
endif ()
429
- file (STRINGS "VERSION" VERSION LIMIT_COUNT 1)
430
487
file (GLOB OPENSSL_PKGCONFIGS "*.pc.in" )
431
488
foreach (file ${OPENSSL_PKGCONFIGS} )
432
489
get_filename_component (filename ${file} NAME )
0 commit comments