|
| 1 | +# |
| 2 | +# CMake build for LTFS. Coexists with the autotools build; both are |
| 3 | +# maintained. The package version is read from the top-level VERSION file |
| 4 | +# (the single source of truth shared with configure.ac). |
| 5 | +# |
| 6 | +cmake_minimum_required(VERSION 3.18) |
| 7 | + |
| 8 | +# --- Version (single source of truth: ./VERSION) ----------------------------- |
| 9 | +file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/VERSION" _ltfs_ver_lines) |
| 10 | +list(GET _ltfs_ver_lines 0 LTFS_VERSION_NUM) |
| 11 | +list(LENGTH _ltfs_ver_lines _ltfs_ver_n) |
| 12 | +set(LTFS_VERSION_SUFFIX "") |
| 13 | +if(_ltfs_ver_n GREATER 1) |
| 14 | + list(GET _ltfs_ver_lines 1 LTFS_VERSION_SUFFIX) |
| 15 | +endif() |
| 16 | +if(LTFS_VERSION_SUFFIX STREQUAL "") |
| 17 | + set(LTFS_VERSION_FULL "${LTFS_VERSION_NUM}") |
| 18 | +else() |
| 19 | + set(LTFS_VERSION_FULL "${LTFS_VERSION_NUM} ${LTFS_VERSION_SUFFIX}") |
| 20 | +endif() |
| 21 | + |
| 22 | +project(ltfs VERSION ${LTFS_VERSION_NUM} LANGUAGES C) |
| 23 | + |
| 24 | +set(LTFS_PACKAGE_NAME "LTFS") |
| 25 | +set(LTFS_PACKAGE_TARNAME "ltfs") |
| 26 | +set(LTFS_BUGREPORT "IBM corporation.") |
| 27 | + |
| 28 | +set(CMAKE_C_STANDARD 99) |
| 29 | +set(CMAKE_C_STANDARD_REQUIRED ON) |
| 30 | +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) |
| 31 | + set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "" FORCE) |
| 32 | +endif() |
| 33 | + |
| 34 | +include(GNUInstallDirs) |
| 35 | +include(CheckIncludeFile) |
| 36 | +include(CheckSymbolExists) |
| 37 | +include(CheckTypeSize) |
| 38 | +include(CheckCCompilerFlag) |
| 39 | + |
| 40 | +# --- Options (mirror the autotools --enable/--with switches) ------------------ |
| 41 | +option(LTFS_ENABLE_SNMP "Build with SNMP support" ON) |
| 42 | +option(LTFS_ENABLE_LINTAPE "Build the IBM lin_tape backend (Linux only)" OFF) |
| 43 | +option(LTFS_SUPPORT_BUGGY_IFS "Work around buggy tape interfaces" OFF) |
| 44 | +option(LTFS_LIVELINK "Enable livelink symlink mode" ON) |
| 45 | +option(LTFS_MESSAGE_CHECK "Compile in message-checking mode" OFF) |
| 46 | +option(LTFS_WERROR "Treat warnings as errors" OFF) |
| 47 | +option(LTFS_DEBUG "Compile with extra debugging output" OFF) |
| 48 | + |
| 49 | +# New locking defaults ON for NetBSD (its old locking is broken), OFF elsewhere. |
| 50 | +if(CMAKE_SYSTEM_NAME STREQUAL "NetBSD") |
| 51 | + option(LTFS_NEW_LOCKING "Use the new locking implementation" ON) |
| 52 | +else() |
| 53 | + option(LTFS_NEW_LOCKING "Use the new locking implementation" OFF) |
| 54 | +endif() |
| 55 | + |
| 56 | +# Default plugin selection, matching configure.ac. |
| 57 | +if(CMAKE_SYSTEM_NAME STREQUAL "Linux") |
| 58 | + set(_default_tape "sg") |
| 59 | +elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") |
| 60 | + set(_default_tape "iokit") |
| 61 | +elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") |
| 62 | + set(_default_tape "cam") |
| 63 | +elseif(CMAKE_SYSTEM_NAME STREQUAL "NetBSD") |
| 64 | + set(_default_tape "scsipi-ibmtape") |
| 65 | +endif() |
| 66 | +set(DEFAULT_TAPE "${_default_tape}" CACHE STRING "Default tape backend plugin") |
| 67 | +set(DEFAULT_IOSCHED "unified" CACHE STRING "Default I/O scheduler plugin") |
| 68 | +set(DEFAULT_KMI "none" CACHE STRING "Default key manager plugin") |
| 69 | + |
| 70 | +# --- Dependencies ------------------------------------------------------------ |
| 71 | +# find_package is used wherever a CMake package exists (LibXml2, ICU, Threads). |
| 72 | +# libfuse, libuuid, and net-snmp ship no CMake config; pkg-config is their |
| 73 | +# canonical interface, wrapped as IMPORTED_TARGETs (PkgConfig::*). |
| 74 | +find_package(PkgConfig REQUIRED) |
| 75 | + |
| 76 | +pkg_check_modules(FUSE REQUIRED IMPORTED_TARGET fuse>=2.6.0) |
| 77 | + |
| 78 | +find_package(LibXml2 2.6.16 REQUIRED) |
| 79 | + |
| 80 | +if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") |
| 81 | + pkg_check_modules(UUID REQUIRED IMPORTED_TARGET uuid>=1.6) |
| 82 | +else() |
| 83 | + pkg_check_modules(UUID REQUIRED IMPORTED_TARGET uuid>=1.36) |
| 84 | +endif() |
| 85 | + |
| 86 | +# ICU via the CMake module (replaces the removed icu-config). |
| 87 | +find_package(ICU REQUIRED COMPONENTS uc i18n io data) |
| 88 | +set(LTFS_ICU6X OFF) |
| 89 | +if(ICU_VERSION VERSION_GREATER_EQUAL "60") |
| 90 | + set(LTFS_ICU6X ON) |
| 91 | +endif() |
| 92 | + |
| 93 | +find_package(Threads REQUIRED) |
| 94 | +if(NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin") |
| 95 | + find_library(RT_LIBRARY rt) |
| 96 | +endif() |
| 97 | + |
| 98 | +# SNMP (optional). |
| 99 | +if(LTFS_ENABLE_SNMP) |
| 100 | + pkg_check_modules(NETSNMP IMPORTED_TARGET net-snmp>=5.3) |
| 101 | + if(NOT NETSNMP_FOUND) |
| 102 | + message(WARNING "net-snmp not found via pkg-config; disabling SNMP") |
| 103 | + set(LTFS_ENABLE_SNMP OFF) |
| 104 | + endif() |
| 105 | +endif() |
| 106 | + |
| 107 | +# Platform-specific libraries (declared for all platforms; used where built). |
| 108 | +# backtrace() has a CMake module (libc on glibc, libexecinfo on the BSDs); |
| 109 | +# cam/bsdxml/mt and the Apple frameworks ship neither CMake configs nor |
| 110 | +# pkg-config files, so find_library is the canonical way to locate them. |
| 111 | +if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") |
| 112 | + find_library(CAM_LIBRARY cam REQUIRED) |
| 113 | + find_library(BSDXML_LIBRARY bsdxml REQUIRED) |
| 114 | + find_library(MT_LIBRARY mt REQUIRED) |
| 115 | + find_package(Backtrace REQUIRED) |
| 116 | +elseif(CMAKE_SYSTEM_NAME STREQUAL "NetBSD") |
| 117 | + find_package(Backtrace REQUIRED) |
| 118 | +elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") |
| 119 | + find_library(IOKIT_FRAMEWORK IOKit REQUIRED) |
| 120 | + find_library(COREFOUNDATION_FRAMEWORK CoreFoundation REQUIRED) |
| 121 | +endif() |
| 122 | + |
| 123 | +# ICU host tools for the message bundles. |
| 124 | +find_program(GENRB genrb REQUIRED) |
| 125 | +find_program(PKGDATA pkgdata REQUIRED) |
| 126 | + |
| 127 | +# --- Feature checks for config.h --------------------------------------------- |
| 128 | +check_include_file("sys/sysctl.h" HAVE_SYS_SYSCTL_H) |
| 129 | +check_include_file("fcntl.h" HAVE_FCNTL_H) |
| 130 | +check_include_file("limits.h" HAVE_LIMITS_H) |
| 131 | +check_include_file("stddef.h" HAVE_STDDEF_H) |
| 132 | +check_include_file("stdint.h" HAVE_STDINT_H) |
| 133 | +check_include_file("stdlib.h" HAVE_STDLIB_H) |
| 134 | +check_include_file("string.h" HAVE_STRING_H) |
| 135 | +check_include_file("sys/ioctl.h" HAVE_SYS_IOCTL_H) |
| 136 | +check_include_file("sys/mount.h" HAVE_SYS_MOUNT_H) |
| 137 | +check_include_file("sys/time.h" HAVE_SYS_TIME_H) |
| 138 | +check_include_file("termios.h" HAVE_TERMIOS_H) |
| 139 | +check_include_file("unistd.h" HAVE_UNISTD_H) |
| 140 | +check_type_size("time_t" SIZEOF_TIME_T) |
| 141 | + |
| 142 | +# xmlTextReaderSetup and XML_PARSE_HUGE (need libxml2 flags in scope). |
| 143 | +# XML_PARSE_HUGE is an enumerator, not a macro, so it needs a compile test. |
| 144 | +include(CheckCSourceCompiles) |
| 145 | +set(CMAKE_REQUIRED_INCLUDES ${LIBXML2_INCLUDE_DIRS}) |
| 146 | +set(CMAKE_REQUIRED_LIBRARIES ${LIBXML2_LIBRARIES}) |
| 147 | +check_symbol_exists(xmlTextReaderSetup "libxml/xmlreader.h" HAVE_XML_READER_SETUP) |
| 148 | +check_c_source_compiles(" |
| 149 | +#include <libxml/parser.h> |
| 150 | +int main(void) { int foo = XML_PARSE_HUGE; (void)foo; return 0; }" |
| 151 | + HAVE_XML_PARSE_HUGE) |
| 152 | +unset(CMAKE_REQUIRED_INCLUDES) |
| 153 | +unset(CMAKE_REQUIRED_LIBRARIES) |
| 154 | + |
| 155 | +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.h.in |
| 156 | + ${CMAKE_CURRENT_BINARY_DIR}/config.h @ONLY) |
| 157 | + |
| 158 | +# --- Common compile settings ------------------------------------------------- |
| 159 | +# Definitions every translation unit gets, mirroring AM_CPPFLAGS/AM_CFLAGS. |
| 160 | +add_compile_definitions( |
| 161 | + _GNU_SOURCE |
| 162 | + LTFS_CONFIG_FILE="${CMAKE_INSTALL_FULL_SYSCONFDIR}/ltfs.conf" |
| 163 | + LTFS_BASE_DIR="${CMAKE_INSTALL_PREFIX}" |
| 164 | +) |
| 165 | +if(LTFS_ENABLE_SNMP) |
| 166 | + add_compile_definitions(ENABLE_SNMP) |
| 167 | +endif() |
| 168 | +if(LTFS_NEW_LOCKING) |
| 169 | + add_compile_definitions(USE_NEW_LOCKING) |
| 170 | +endif() |
| 171 | +if(NOT LTFS_LIVELINK) |
| 172 | + add_compile_definitions(POSIXLINK_ONLY) |
| 173 | +endif() |
| 174 | +if(LTFS_MESSAGE_CHECK) |
| 175 | + add_compile_definitions(MSG_CHECK) |
| 176 | +endif() |
| 177 | +if(LTFS_DEBUG) |
| 178 | + add_compile_definitions(DEBUG TRACE) |
| 179 | +endif() |
| 180 | +if(LTFS_ICU6X) |
| 181 | + add_compile_definitions(ICU6x) |
| 182 | +endif() |
| 183 | +if(LTFS_SUPPORT_BUGGY_IFS AND (CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Darwin")) |
| 184 | + add_compile_definitions(SUPPORT_BUGGY_IFS) |
| 185 | +endif() |
| 186 | + |
| 187 | +# -Wno-unused-parameter: callback signatures (FUSE operations, plugin ops) |
| 188 | +# must keep parameters they do not use. |
| 189 | +# -Wno-missing-field-initializers: designated initializers of operation and |
| 190 | +# option tables intentionally leave the remaining members zeroed. |
| 191 | +add_compile_options(-Wall -Wextra -Wno-unused-parameter |
| 192 | + -Wno-missing-field-initializers -Wsign-compare -fsigned-char) |
| 193 | +if(LTFS_WERROR) |
| 194 | + add_compile_options(-Werror -Wno-deprecated-declarations) |
| 195 | +endif() |
| 196 | + |
| 197 | +# config.h (binary dir) and the src tree on the include path for every target. |
| 198 | +include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/src) |
| 199 | + |
| 200 | +# CRC files need SSE4.2 on capable x86; detected once, applied to the ltfs_crc |
| 201 | +# object library (see src/tape_drivers). |
| 202 | +set(LTFS_CRC_OPTIONS "") |
| 203 | +if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64|i[3-6]86") |
| 204 | + check_c_compiler_flag("-msse4.2" LTFS_HAVE_MSSE42) |
| 205 | + if(LTFS_HAVE_MSSE42) |
| 206 | + set(LTFS_CRC_OPTIONS -msse4.2 -D__SSE42__) |
| 207 | + endif() |
| 208 | +endif() |
| 209 | + |
| 210 | +# Helper modules. |
| 211 | +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) |
| 212 | +include(LtfsMessages) |
| 213 | +include(LtfsPlugin) |
| 214 | + |
| 215 | +enable_testing() |
| 216 | + |
| 217 | +# --- Subprojects ------------------------------------------------------------- |
| 218 | +add_subdirectory(messages) |
| 219 | +add_subdirectory(src) |
| 220 | +add_subdirectory(conf) |
| 221 | +add_subdirectory(man) |
| 222 | +add_subdirectory(init.d) |
| 223 | +add_subdirectory(tests) |
| 224 | + |
| 225 | +# pkg-config file (reuse the autotools template). |
| 226 | +set(prefix "${CMAKE_INSTALL_PREFIX}") |
| 227 | +set(exec_prefix "\${prefix}") |
| 228 | +set(libdir "${CMAKE_INSTALL_FULL_LIBDIR}") |
| 229 | +set(includedir "${CMAKE_INSTALL_FULL_INCLUDEDIR}") |
| 230 | +set(PACKAGE "ltfs") |
| 231 | +set(VERSION "${LTFS_VERSION_FULL}") |
| 232 | +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/ltfs.pc.in |
| 233 | + ${CMAKE_CURRENT_BINARY_DIR}/ltfs.pc @ONLY) |
| 234 | +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ltfs.pc |
| 235 | + DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) |
0 commit comments