1+ cmake_minimum_required (VERSION 3.16.4)
12if (MSVC )
2- cmake_minimum_required (VERSION 3.16.4)
33 cmake_policy (SET CMP0091 NEW)
4- else ()
5- cmake_minimum_required (VERSION 3.0)
64endif ()
75
86project (LibreSSL C ASM)
@@ -41,6 +39,7 @@ option(ENABLE_ASM "Enable assembly" ON)
4139option (ENABLE_EXTRATESTS "Enable extra tests that may be unreliable on some platforms" OFF )
4240option (ENABLE_NC "Enable installing TLS-enabled nc(1)" OFF )
4341set (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" )
4443
4544option (USE_STATIC_MSVC_RUNTIMES "Use /MT instead of /MD in MSVC" OFF )
4645if (USE_STATIC_MSVC_RUNTIMES)
@@ -51,6 +50,20 @@ if(NOT LIBRESSL_SKIP_INSTALL)
5150 set ( ENABLE_LIBRESSL_INSTALL ON )
5251endif (NOT LIBRESSL_SKIP_INSTALL)
5352
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)
5467
5568set (BUILD_NC true )
5669
@@ -79,7 +92,7 @@ if(WIN32 OR (CMAKE_SYSTEM_NAME MATCHES "MINGW"))
7992 add_definitions (-D__USE_MINGW_ANSI_STDIO)
8093endif ()
8194
82- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 - Wall" )
95+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall" )
8396
8497if (CMAKE_SYSTEM_NAME MATCHES "HP-UX" )
8598 if (CMAKE_C_COMPILER MATCHES "gcc" )
@@ -121,7 +134,7 @@ if(WIN32)
121134 if (NOT CMAKE_SYSTEM_NAME MATCHES "WindowsStore" )
122135 add_definitions (-D_WIN32_WINNT=0x0600)
123136 endif ()
124- set (PLATFORM_LIBS ${PLATFORM_LIBS} ws2_32 bcrypt)
137+ set (PLATFORM_LIBS ${PLATFORM_LIBS} ws2_32 ntdll bcrypt)
125138endif ()
126139
127140if (MSVC )
@@ -135,17 +148,17 @@ if(MSVC)
135148 "C4100" # 'identifier' : unreferenced formal parameter
136149 "C4127" # conditional expression is constant
137150 "C4146" # unary minus operator applied to unsigned type,
138- # result still unsigned
151+ # result still unsigned
139152 "C4244" # 'argument' : conversion from 'type1' to 'type2',
140- # possible loss of data
153+ # possible loss of data
141154 "C4245" # 'conversion' : conversion from 'type1' to 'type2',
142- # signed/unsigned mismatch
155+ # signed/unsigned mismatch
143156 "C4267" # 'var' : conversion from 'size_t' to 'type',
144- # possible loss of data
157+ # possible loss of data
145158 "C4389" # 'operator' : signed/unsigned mismatch
146159 "C4706" # assignment within conditional expression
147160 "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
149162 )
150163 elseif (CMAKE_C_COMPILER_ID MATCHES "Intel" )
151164 add_definitions (-D_CRT_SUPPRESS_RESTRICT)
@@ -176,6 +189,11 @@ if(HAVE_ASPRINTF)
176189 add_definitions (-DHAVE_ASPRINTF)
177190endif ()
178191
192+ check_function_exists(getopt HAVE_GETOPT)
193+ if (HAVE_GETOPT)
194+ add_definitions (-DHAVE_GETOPT)
195+ endif ()
196+
179197check_function_exists(reallocarray HAVE_REALLOCARRAY)
180198if (HAVE_REALLOCARRAY)
181199 add_definitions (-DHAVE_REALLOCARRAY)
@@ -306,28 +324,37 @@ if(HAVE_NETINET_IP_H)
306324 add_definitions (-DHAVE_NETINET_IP_H)
307325endif ()
308326
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)" )
310337 set (HOST_AARCH64 true )
311338elseif ("${CMAKE_SYSTEM_PROCESSOR} " MATCHES "arm" )
312339 set (HOST_ARM true )
313340elseif ("${CMAKE_SYSTEM_NAME} " STREQUAL "SunOS" AND "${CMAKE_SYSTEM_PROCESSOR} " STREQUAL "i386" )
314341 set (HOST_X86_64 true )
315- elseif ("${CMAKE_SYSTEM_PROCESSOR} " MATCHES "(x86_64|amd64)" )
342+ elseif ("${CMAKE_SYSTEM_PROCESSOR} " MATCHES "(x86_64|amd64|AMD64 )" )
316343 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) " )
318345 set (ENABLE_ASM false )
319346 set (HOST_I386 true )
320- elseif ("${CMAKE_SYSTEM_NAME } " MATCHES "mips64" )
347+ elseif ("${CMAKE_SYSTEM_PROCESSOR } " MATCHES "mips64" )
321348 set (HOST_MIPS64 true )
322- elseif ("${CMAKE_SYSTEM_NAME } " MATCHES "mips" )
349+ elseif ("${CMAKE_SYSTEM_PROCESSOR } " MATCHES "mips" )
323350 set (HOST_MIPS true )
324- elseif ("${CMAKE_SYSTEM_NAME } " MATCHES "powerpc" )
351+ elseif ("${CMAKE_SYSTEM_PROCESSOR } " MATCHES "powerpc" )
325352 set (HOST_POWERPC true )
326- elseif ("${CMAKE_SYSTEM_NAME } " MATCHES "ppc64" )
353+ elseif ("${CMAKE_SYSTEM_PROCESSOR } " MATCHES "ppc64" )
327354 set (HOST_PPC64 true )
328- elseif ("${CMAKE_SYSTEM_NAME } " MATCHES "riscv64" )
355+ elseif ("${CMAKE_SYSTEM_PROCESSOR } " MATCHES "riscv64" )
329356 set (HOST_RISCV64 true )
330- elseif ("${CMAKE_SYSTEM_NAME } " MATCHES "sparc64" )
357+ elseif ("${CMAKE_SYSTEM_PROCESSOR } " MATCHES "sparc64" )
331358 set (HOST_SPARC64 true )
332359else ()
333360 set (ENABLE_ASM false )
@@ -348,7 +375,7 @@ if(ENABLE_ASM)
348375 elseif (MSVC AND ("${CMAKE_GENERATOR} " MATCHES "Win64" OR "${CMAKE_GENERATOR_PLATFORM} " STREQUAL "x64" ))
349376 set (HOST_ASM_MASM_X86_64 true )
350377 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" )
352379 set (HOST_ASM_MINGW64_X86_64 true )
353380 endif ()
354381endif ()
@@ -374,7 +401,6 @@ if(SIZEOF_TIME_T STREQUAL "4")
374401 message (WARNING " ** Warning, this system is unable to represent times past 2038\n "
375402 " ** It will behave incorrectly when handling valid RFC5280 dates" )
376403endif ()
377- add_definitions (-DSIZEOF_TIME_T=${SIZEOF_TIME_T} )
378404
379405set (OPENSSL_LIBS ssl crypto ${PLATFORM_LIBS} )
380406set (LIBTLS_LIBS tls ${PLATFORM_LIBS} )
@@ -416,6 +442,38 @@ if (BUILD_APPLE_XCFRAMEWORK)
416442 endif (ENABLE_LIBRESSL_INSTALL)
417443endif (BUILD_APPLE_XCFRAMEWORK)
418444
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+
419477if (ENABLE_LIBRESSL_INSTALL)
420478 if (NOT MSVC )
421479 # Create pkgconfig files.
@@ -426,7 +484,6 @@ if(ENABLE_LIBRESSL_INSTALL)
426484 if (PLATFORM_LIBS)
427485 string (REGEX REPLACE ";" " -l" PLATFORM_LDADD ";${PLATFORM_LIBS} " )
428486 endif ()
429- file (STRINGS "VERSION" VERSION LIMIT_COUNT 1)
430487 file (GLOB OPENSSL_PKGCONFIGS "*.pc.in" )
431488 foreach (file ${OPENSSL_PKGCONFIGS} )
432489 get_filename_component (filename ${file} NAME )
0 commit comments