11#
22CMAKE_MINIMUM_REQUIRED (VERSION 2.8.12 FATAL_ERROR)
3+ if (APPLE AND CMAKE_VERSION VERSION_LESS "3.17.0" )
4+ message (WARNING "CMake>=3.17.0 required to make the generated shared library have the same Mach-O headers as autotools" )
5+ endif ()
6+
37if (POLICY CMP0065)
48 cmake_policy (SET CMP0065 NEW) #3.4 don't use `-rdynamic` with executables
59endif ()
@@ -25,7 +29,7 @@ endif()
2529# MinSizeRel : Release Min Size build
2630# None : No build type
2731IF (NOT CMAKE_BUILD_TYPE )
28- SET (CMAKE_BUILD_TYPE "Debug " CACHE STRING "Build Type" FORCE)
32+ SET (CMAKE_BUILD_TYPE "Release " CACHE STRING "Build Type" FORCE)
2933ENDIF (NOT CMAKE_BUILD_TYPE )
3034# Set a value type to properly display CMAKE_BUILD_TYPE on GUI if the
3135# value type is "UNINITIALIZED".
@@ -83,9 +87,21 @@ SET(LIBARCHIVE_VERSION_STRING "${VERSION}")
8387# libarchive 3.1 == interface version 13
8488math (EXPR INTERFACE_VERSION "13 + ${_minor} " )
8589
86- # Set SOVERSION == Interface version
87- # ?? Should there be more here ??
88- SET (SOVERSION "${INTERFACE_VERSION} " )
90+ # Set SOVERSION so it matches libtool's conventions
91+ # libtool accepts a string "current:revision:age"; in libarchive, that's set to
92+ # - current: ${INTERFACE_VERSION} = 13 + ${_minor}
93+ # - revision: ${_revision}
94+ # - age: ${_minor}
95+ # Since libtool computes SOVERSION as "current - age", it's just '13' again
96+ math (EXPR SOVERSION "${INTERFACE_VERSION} - ${_minor} " )
97+ set (SOVERSION_FULL "${SOVERSION} .${_trimmed_minor} .${_trimmed_revision} " )
98+
99+ # Override CMake's default shared library versioning scheme, which uses SOVERSION and VERSION,
100+ # to match libtool's conventions (see https://github.com/mesonbuild/meson/issues/1451)
101+ # - compatibility version: current + 1 = ${INTERFACE_VERSION} + 1
102+ # - current version: ${current + 1}.${revision}
103+ math (EXPR MACHO_COMPATIBILITY_VERSION "${INTERFACE_VERSION} + 1" )
104+ set (MACHO_CURRENT_VERSION "${MACHO_COMPATIBILITY_VERSION} .${_revision} " )
89105
90106# Enable CMAKE_PUSH_CHECK_STATE() and CMAKE_POP_CHECK_STATE() macros
91107# saving and restoring the state of the variables.
@@ -107,7 +123,7 @@ endif ()
107123# aggressive about diagnosing build problems; this can get
108124# relaxed somewhat in final shipping versions.
109125IF (CMAKE_C_COMPILER_ID MATCHES "^GNU$" OR
110- CMAKE_C_COMPILER_ID MATCHES "^Clang$" )
126+ CMAKE_C_COMPILER_ID MATCHES "^Clang$" AND NOT MSVC )
111127 SET (CMAKE_REQUIRED_FLAGS "-Wall -Wformat -Wformat-security" )
112128 #################################################################
113129 # Set compile flags for all build types.
@@ -144,7 +160,7 @@ IF (CMAKE_C_COMPILER_ID MATCHES "^GNU$" OR
144160 SET (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-dead_strip" )
145161 ENDIF (NOT CMAKE_SYSTEM_NAME MATCHES "Darwin" )
146162ENDIF (CMAKE_C_COMPILER_ID MATCHES "^GNU$" OR
147- CMAKE_C_COMPILER_ID MATCHES "^Clang$" )
163+ CMAKE_C_COMPILER_ID MATCHES "^Clang$" AND NOT MSVC )
148164IF (CMAKE_C_COMPILER_ID MATCHES "^XL$" )
149165 SET (CMAKE_C_COMPILER "xlc_r" )
150166 SET (CMAKE_REQUIRED_FLAGS "-qflag=e:e -qformat=sec" )
@@ -443,7 +459,10 @@ SET(ADDITIONAL_LIBS "")
443459# Find ZLIB
444460#
445461IF (ENABLE_ZLIB)
446- FIND_PACKAGE (ZLIB)
462+ # Require zlib >= 1.2.1, see: https://github.com/libarchive/libarchive/issues/615
463+ # zlib 1.2.0 should also work, but it is difficult to test for. Let's require
464+ # zlib >= 1.2.1 for consistency with the autoconf build.
465+ FIND_PACKAGE (ZLIB 1.2.1)
447466ELSE ()
448467 SET (ZLIB_FOUND FALSE ) # Override cached value
449468ENDIF ()
@@ -743,7 +762,6 @@ LA_CHECK_INCLUDE_FILE("sys/mkdev.h" HAVE_SYS_MKDEV_H)
743762LA_CHECK_INCLUDE_FILE("sys/mount.h" HAVE_SYS_MOUNT_H)
744763LA_CHECK_INCLUDE_FILE("sys/param.h" HAVE_SYS_PARAM_H)
745764LA_CHECK_INCLUDE_FILE("sys/poll.h" HAVE_SYS_POLL_H)
746- LA_CHECK_INCLUDE_FILE("sys/queue.h" HAVE_SYS_QUEUE_H)
747765LA_CHECK_INCLUDE_FILE("sys/richacl.h" HAVE_SYS_RICHACL_H)
748766LA_CHECK_INCLUDE_FILE("sys/select.h" HAVE_SYS_SELECT_H)
749767LA_CHECK_INCLUDE_FILE("sys/stat.h" HAVE_SYS_STAT_H)
@@ -863,6 +881,14 @@ IF(NOT OPENSSL_FOUND)
863881 ENDIF (LIBMD_FOUND)
864882ENDIF (NOT OPENSSL_FOUND)
865883
884+ # libbsd for readpassphrase on Haiku
885+ IF ("${CMAKE_SYSTEM_NAME} " MATCHES "Haiku" )
886+ MESSAGE (STATUS "Adding libbsd for Haiku" )
887+ SET (CMAKE_REQUIRED_LIBRARIES "bsd" )
888+ FIND_LIBRARY (LIBBSD_LIBRARY NAMES bsd)
889+ LIST (APPEND ADDITIONAL_LIBS ${LIBBSD_LIBRARY} )
890+ ENDIF ("${CMAKE_SYSTEM_NAME} " MATCHES "Haiku" )
891+
866892#
867893# How to prove that CRYPTO functions, which have several names on various
868894# platforms, just see if archive_digest.c can compile and link against
@@ -2174,6 +2200,11 @@ IF(APPLE)
21742200 ADD_DEFINITIONS (-Wno-deprecated-declarations)
21752201ENDIF (APPLE )
21762202
2203+ OPTION (DONT_FAIL_ON_CRC_ERROR "Ignore CRC errors during parsing (For fuzzing)" OFF )
2204+ IF (DONT_FAIL_ON_CRC_ERROR)
2205+ ADD_DEFINITIONS (-DDONT_FAIL_ON_CRC_ERROR=1)
2206+ ENDIF (DONT_FAIL_ON_CRC_ERROR)
2207+
21772208IF (ENABLE_TEST)
21782209 ADD_CUSTOM_TARGET (run_all_tests)
21792210ENDIF (ENABLE_TEST)
0 commit comments