clamav/cmake/Version.cmake
Micah Snyder e0e0c8f955 CMake: Support to build deb, rpm, & macOS pkg packages
CMake/CPack is already used to build:
- TGZ source tarball
- WiX-based installer (Windows)
- ZIP install packages (Windows)

This commit adds support for building:
- macOS PKG installer
- DEB package
- RPM package

This should also enable building FreeBSD packages, but while I was able
to build all of the static dependencies using Mussels, CMake/CPack 3.20
doesn't appear to have the the FreeBSD generator despite being in the
documentation.

The package names are will be in this format:
  clamav-<version><suffix>.<os>.<arch>.<extension>

This includes changing the Windows .zip and .msi installer names.

E.g.:
- clamav-0.104.0-rc.macos.x86_64.pkg
- clamav-0.104.0-rc.win.win32.msi
- clamav-0.104.0-rc.win.win32.zip
- clamav-0.104.0-rc.win.x64.msi
- clamav-0.104.0-rc.linux.x86_64.deb
- clamav-0.104.0-rc.linux.x86_64.rpm

Notes about building the packages:

I've only tested this with building ClamAV using static dependencies that
I build using the clamav_deps "host-static" recipes from the "clamav"
Mussels cookbook. Eg:

  msl build clamav_deps -t host-static

Here's an example configuration to build clam in this way, installing to
/usr/local/clamav:

```sh
cmake .. \
  -D CMAKE_FIND_PACKAGE_PREFER_CONFIG=TRUE \
  -D CMAKE_PREFIX_PATH=$HOME/.mussels/install/host-static \
  -D CMAKE_INSTALL_PREFIX="/usr/local/clamav" \
  -D CMAKE_MODULE_PATH=$HOME/.mussels/install/host-static/lib/cmake \
  -D CMAKE_BUILD_TYPE=RelWithDebInfo \
  -D ENABLE_EXAMPLES=OFF \
  -D JSONC_INCLUDE_DIR="$HOME/.mussels/install/host-static/include/json-c" \
  -D JSONC_LIBRARY="$HOME/.mussels/install/host-static/lib/libjson-c.a" \
  -D ENABLE_JSON_SHARED=OFF \
  -D BZIP2_INCLUDE_DIR="$HOME/.mussels/install/host-static/include" \
  -D BZIP2_LIBRARY_RELEASE="$HOME/.mussels/install/host-static/lib/libbz2_static.a" \
  -D OPENSSL_ROOT_DIR="$HOME/.mussels/install/host-static" \
  -D OPENSSL_INCLUDE_DIR="$HOME/.mussels/install/host-static/include" \
  -D OPENSSL_CRYPTO_LIBRARY="$HOME/.mussels/install/host-static/lib/libcrypto.a" \
  -D OPENSSL_SSL_LIBRARY="$HOME/.mussels/install/host-static/lib/libssl.a" \
  -D LIBXML2_INCLUDE_DIR="$HOME/.mussels/install/host-static/include/libxml2" \
  -D LIBXML2_LIBRARY="$HOME/.mussels/install/host-static/lib/libxml2.a" \
  -D PCRE2_INCLUDE_DIR="$HOME/.mussels/install/host-static/include" \
  -D PCRE2_LIBRARY="$HOME/.mussels/install/host-static/lib/libpcre2-8.a" \
  -D CURSES_INCLUDE_DIR="$HOME/.mussels/install/host-static/include" \
  -D CURSES_LIBRARY="$HOME/.mussels/install/host-static/lib/libncurses.a" \
  -D ZLIB_INCLUDE_DIR="$HOME/.mussels/install/host-static/include" \
  -D ZLIB_LIBRARY="$HOME/.mussels/install/host-static/lib/libz.a" \
  -D LIBCHECK_INCLUDE_DIR="$HOME/.mussels/install/host-static/include" \
  -D LIBCHECK_LIBRARY="$HOME/.mussels/install/host-static/lib/libcheck.a"
```

Set CPACK_PACKAGING_INSTALL_PREFIX to customize the resulting package's
install location. This can be different than the install prefix. E.g.:
```sh
  -D CMAKE_INSTALL_PREFIX="/usr/local/clamav" \
  -D CPACK_PACKAGING_INSTALL_PREFIX="/usr/local/clamav" \
```

Then `make` and then one of these, depending on the platform:
```sh
cpack        # macOS: productbuild is default
cpack -G DEB # Debian-based
cpack -G RPM # RPM-based
```

On macOS you'll need to `pip3 install markdown` so that the NEWS.md file can
be converted to html so it will render in the installer.

On RPM-based systems, you'll need rpmbuild (install rpm-build)

This commit also fixes an issue where the html manual (if present) was
not correctly added to the Windows (or now other) install packages.

Fix num to hex function for Windows installer guid

Fix win32 cpack build

Fix macOS cpack build
2021-08-18 13:53:34 -07:00

24 lines
944 B
CMake

# Converts a version such as 1.2.255 to 0x0102ff
function(HexVersion version_hex_var major minor patch)
math(EXPR version_dec "${major} * 256 * 256 + ${minor} * 256 + ${patch}")
set(version_hex "0x")
foreach(i RANGE 5 0 -1)
math(EXPR num "(${version_dec} >> (4 * ${i})) & 15")
string(SUBSTRING "0123456789abcdef" ${num} 1 num_hex)
set(version_hex "${version_hex}${num_hex}")
endforeach()
set(${version_hex_var} "${version_hex}" PARENT_SCOPE)
endfunction()
# Converts a number such as 104 to 68
function(NumberToHex number output)
set(hex "")
foreach(i RANGE 1)
math(EXPR nibble "${number} & 15")
string(SUBSTRING "0123456789abcdef" "${nibble}" 1 nibble_hex)
string(APPEND hex "${nibble_hex}")
math(EXPR number "${number} >> 4")
endforeach()
string(REGEX REPLACE "(.)(.)" "\\2\\1" hex "${hex}")
set("${output}" "${hex}" PARENT_SCOPE)
endfunction()