Congratulations on the 20th anniversary of ClamAV® !

Congratulations on the 20th anniversary of ClamAV® !

ClamAV turns 20

Tomasz Kojm, the original developer of ClamAV, released the first 0.10 version of the open source antivirus engine on May 8, 2002. Thus, ClamAV turned 20 years old on May 8, 2022.
ClamAV will then move closer to the long-awaited release of the 1.0.0 version

Memorandum: How to build ClamAV® using the CMake Build System on macOS

How to build ClamAV® using the CMake Build System on macOS

Autotools build system has been dropped.
CMake is now the required build system in the ClamAV 0.104.x.
Instead of Autotools (eg: ./configure && make && sudo make install), CMake is required to build ClamAV.
Besides CMake, you need some libclamav dependencies (libpcre2 for RegEx, openssl for Crypto, json-c for JSON) to build ClamAV. And it may also be necessary to install other libraries such as pkg-config.
For further information, see " ClamAV 0.104.0 released" and "Installation Instructions".

Starting with ClamAV 0.105.x, Rust toolchain is required to compile portions of libclamav. See "Install Rust toolchain".
Also, "Issue 358 353 292 cmake ncurses issues" has been fixed, so you do not need to install ncurses now.

I'm running the latest stable release ClamAV 0.105.1 on macOS 12.5 Monterey now.
ClamAV 0.105.1 is available on the Download page of ClamavNet, and the release note is here!

This memorandum describes how to build ClamAV using the CMake build system and includes the following:
  1) Install CMake Build System
  2) Install Rust toolchain
  3) Install pkg-config
  4) Install Libcheck/Check
  5) Install PCRE2 Libraries
  6) Install OpenSSL Libraries
      6-1.When you use LibreSSL…
      6-2.When you use OpenSSL…
  7) Install JSON-C Libraries
  8) Install Ninja Build System
  9) Build ClamAV with CMake Build System
      9-1.When you use LibreSSL…
      9-2.When you use OpenSSL…
10) Build ClamAV with Ninja Build System
    10-1.When you use LibreSSL…
    10-2.When you use OpenSSL…
11) Links…

Regarding the Autotools build system, see "How to install ClamAV® from the Git sources on macOS".



1) Install CMake

CMake is an open-source, cross-platform family of tools designed to build, test and package software.

1. Download the latest CMake
    You can get CMake binary distribution for macOS.
    Download CMake.app and place it in the Applications directory.
cd ~
curl -LO https://github.com/Kitware/CMake/releases/download/v3.24.0/cmake-3.24.0-macos-universal.tar.gz
tar xzf cmake-3.24.0-macos-universal.tar.gz
cp -r ~/cmake-3.24.0-macos-universal/CMake.app /Applications

2. For Command Line Use (to install symlinks to '/usr/local/bin')
sudo "/Applications/CMake.app/Contents/bin/cmake-gui" --install

3. You can confirm the installation:
which cmake
/usr/local/bin/cmake
cmake --version
cmake version 3.24.0




Without using CMake.app you can build binary by yourself.


1. Download the latest CMake
cd ~
curl -LO https://github.com/Kitware/CMake/releases/download/v3.24.0/cmake-3.24.0.tar.gz
tar xzf cmake-3.24.0.tar.gz

2. Bootstrap CMake
cd cmake-3.24.0
./bootstrap --prefix=/usr/local/cmake

3. Compile and install CMake
make && sudo make install

4. Set search path
export PATH="/usr/local/cmake/bin:$PATH"




2) Install Rust toolchain

1. Download rustup and Install Rust toolchain
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

2. Set search path
export PATH="$HOME/.cargo/bin:$PATH"

3. You can confirm the installation:
rustup --version
rustup 1.25.1 (bb60b1e89 2022-07-12)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.63.0 (4b91a6ea7 2022-08-08)`

rustc --version
rustc 1.63.0 (4b91a6ea7 2022-08-08)

cargo --version
cargo 1.63.0 (fd9c4297c 2022-07-01)

4. You can maintain the toolchain by periodically executing:
rustup update stable
info: syncing channel updates for 'stable-x86_64-apple-darwin'
info: latest update on 2022-08-11, rust version 1.63.0 (4b91a6ea7 2022-08-08)
info: downloading component 'cargo'
info: downloading component 'clippy'
info: downloading component 'rust-docs'
info: downloading component 'rust-std'
info: downloading component 'rustc'
 52.8 MiB /  52.8 MiB (100 %)  42.8 MiB/s in  1s ETA:  0s
info: downloading component 'rustfmt'
info: removing previous version of component 'cargo'
info: removing previous version of component 'clippy'
info: removing previous version of component 'rust-docs'
info: removing previous version of component 'rust-std'
info: removing previous version of component 'rustc'
info: removing previous version of component 'rustfmt'
info: installing component 'cargo'
info: installing component 'clippy'
info: installing component 'rust-docs'
 18.4 MiB /  18.4 MiB (100 %)   5.5 MiB/s in  2s ETA:  0s
info: installing component 'rust-std'
 24.8 MiB /  24.8 MiB (100 %)  13.1 MiB/s in  1s ETA:  0s
info: installing component 'rustc'
 52.8 MiB /  52.8 MiB (100 %)  15.0 MiB/s in  3s ETA:  0s
info: installing component 'rustfmt'

  stable-x86_64-apple-darwin updated - rustc 1.63.0 (4b91a6ea7 2022-08-08) (from rustc 1.62.1 (e092d0b6b 2022-07-16))

info: checking for self-updates




3) Install pkg-config

1. Download the latest pkg-config
cd ~
curl -O https://pkg-config.freedesktop.org/releases/pkg-config-0.29.2.tar.gz
tar zxf pkg-config-0.29.2.tar.gz

2. Configure pkg-config
cd pkg-config-0.29.2
export LDFLAGS="-framework CoreFoundation" 
./configure --with-internal-glib --prefix=/usr/local/pkgconfig

3. Compile and install pkg-config
make && make check
sudo make install

4. Set search path
export PATH="/usr/local/keyconfig/bin:$PATH"




4) Install Libcheck/Check

1. Download the latest Check
cd ~
curl -LO https://github.com/libcheck/check/releases/download/0.15.2/check-0.15.2.tar.gz
tar zxf check-0.15.2.tar.gz

2. Configure Check
cd check-0.15.2
./configure --prefix=/usr/local/check

3. Compile and install Check
make && make check
sudo make install
4. Set search path
export PATH="/usr/local/check/bin:$PATH"




5) Install PCRE2 Libraries

1. Download the latest PCRE2
cd ~
curl -LO https://github.com/PCRE2Project/pcre2/releases/download/pcre2-10.40/pcre2-10.40.tar.bz2
tar zxf pcre2-10.40.tar.bz2

2. Configure PCRE2
cd pcre2-10.40
./configure --prefix=/usr/local/pcre2

3. Compile and install PCRE2
make && make check
sudo make install




6) Install OpenSSL Libraries

6-1. When you use LibreSSL…

1. Download the latest LibreSSL
cd ~
curl -O https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-3.5.3.tar.gz
tar zxf libressl-3.5.3.tar.gz

2. Configure LibreSSL
cd libressl-3.5.3
./configure --prefix=/usr/local/libressl

3. Compile and install LibreSSL
make && make check
sudo make install

4. Set search path
export PATH="/usr/local/libressl/bin:$PATH"

5. You can confirm the installation:
which openssl
/usr/local/libressl/bin/openssl
openssl version
LibreSSL 3.5.3





6-2. When you use OpenSSL…

1. Download the latest OpenSSL
cd ~
curl -O https://www.openssl.org/source/openssl-3.0.5.tar.gz
tar zxf openssl-3.0.5.tar.gz

2. Configure OpenSSL
cd openssl-3.0.5
./configure darwin64-x86_64-cc --prefix=/usr/local/openssl

3. Compile and install OpenSSL
make && make test
sudo make install

4. Set search path
export PATH="/usr/local/openssl/bin:$PATH"

5. You can confirm the installation:
which openssl
/usr/local/openssl/bin/openssl
openssl version
OpenSSL 3.0.5 5 Jul 2022 (Library: OpenSSL 3.0.5 5 Jul 2022)




7) Install JSON-C Libraries

JSON-C is a JSON implementation in C.

1. Download JSON-C
cd ~
curl -LO https://s3.amazonaws.com/json-c_releases/releases/json-c-0.16.tar.gz
tar xzf json-c-0.16.tar.gz

2. Configure and Generate JSON-C
cd json-c-json-c-0.16
mkdir build
cd build
cmake -D CMAKE_INSTALL_PREFIX=/usr/local/json-c ..

3. Compile and install JSON-C
make && make test
sudo make install

4. Create Symbolic Link
sudo ln -s /usr/local/json-c/lib/libjson-c.5.dylib /usr/local/lib/




8) Install Ninja Build System

Ninja is a small build system with a focus on speed.
So this is an optional install.

1. Download Ninja
cd ~
curl -LO https://github.com/ninja-build/ninja/archive/v1.11.0.tar.gz
tar xzf v1.11.0.tar.gz

2. Configure and Generate Ninja
cd ninja-1.11.0
mkdir build
cd build
cmake -D CMAKE_INSTALL_PREFIX=/usr/local/ninja/ ..

3. Compile and install Ninja
make && make test
sudo make install

4. Create Symbolic Link
sudo ln -s /usr/local/ninja/bin/ninja /usr/local/bin/

5. You can confirm the installation:
which ninja
/usr/local/bin/ninja
ninja --version
1.11.0




9) Build ClamAV with CMake Build System

9-1. When you use LibreSSL…

1. Download the latest Stable Release ClamAV 0.105.1 from the ClamavNet.
cd ~
0.105.1
tar zxf clamav-0.105.1.tar.gz

2. Set CMake options and library paths and Configure and Generate.
cd clamav-0.105.1
mkdir build
cd build 
cmake \
-D CMAKE_BUILD_TYPE=Release \
-D OPTIMIZE=ON \
-D BYTECODE_RUNTIME="interpreter" \
-D CMAKE_INSTALL_PREFIX=/usr/local/clamXav/ \
-D ENABLE_JSON_SHARED=OFF \
-D ENABLE_TESTS=ON \
-D LIBCHECK_ROOT_DIR=/usr/local/check \
-D LIBCHECK_INCLUDE_DIR=/usr/local/check/include/ \
-D LIBCHECK_LIBRARY=/usr/local/check/lib/libcheck.0.dylib \
-D OPENSSL_ROOT_DIR=/usr/local/libressl/ \
-D OPENSSL_CRYPTO_LIBRARY=/usr/local/libressl/lib/libcrypto.49.dylib \
-D OPENSSL_SSL_LIBRARY=/usr/local/libressl/lib/libssl.52.dylib \
-D PCRE2_LIBRARY=/usr/local/pcre2/lib/libpcre2-8.0.dylib \
-D PCRE2_INCLUDE_DIR=/usr/local/pcre2/include/ \
-D JSONC_LIBRARY=/usr/local/json-c/lib/libjson-c.5.dylib \
-D JSONC_INCLUDE_DIR=/usr/local/json-c/include/json-c/ \
..

3. You get results as below:
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/xxx/clamav-0.105.1/build

4. Compile and make test;
make && make test

5. You get results as below:
Running tests...
Test project /Users/xxx/Desktop/clamav-0.105.1/build
    Start 1: libclamav
1/6 Test #1: libclamav ........................   Passed   11.17 sec
    Start 2: libclamav_rust
2/6 Test #2: libclamav_rust ...................   Passed   69.80 sec
    Start 3: clamscan
3/6 Test #3: clamscan .........................   Passed    3.92 sec
    Start 4: clamd
4/6 Test #4: clamd ............................   Passed   11.40 sec
    Start 5: freshclam
5/6 Test #5: freshclam ........................   Passed   28.07 sec
    Start 6: sigtool
6/6 Test #6: sigtool ..........................   Passed    0.22 sec

100% tests passed, 0 tests failed out of 6

6. Install ClamAV®
sudo make install





9-2. When you use OpenSSL…

1. Download the latest Stable Release ClamAV 0.105.1 from the ClamavNet.
cd ~
curl -LO https://www.clamav.net/downloads/release_candidate/clamav-0.105.1.tar.gz
tar zxf clamav-clamav-0.105.1.tar.gz

2. Set CMake options and library paths and Configure and Generate.
cd clamav-0.105.1
mkdir build
cd build 
cmake \
-D CMAKE_BUILD_TYPE=Release \
-D CMAKE_INSTALL_PREFIX=/usr/local/clamXav/ \
-D BYTECODE_RUNTIME="interpreter" \
-D OPTIMIZE=ON \
-D ENABLE_JSON_SHARED=OFF \
-D ENABLE_TESTS=ON \
-D LIBCHECK_ROOT_DIR=/usr/local/check \
-D LIBCHECK_INCLUDE_DIR=/usr/local/check/include/ \
-D LIBCHECK_LIBRARY=/usr/local/check/lib/libcheck.0.dylib \
-D OPENSSL_ROOT_DIR=/usr/local/openssl/ \
-D OPENSSL_CRYPTO_LIBRARY=/usr/local/openssl/lib/libcrypto.3.dylib \
-D OPENSSL_SSL_LIBRARY=/usr/local/openssl/lib/libssl.3.dylib \
-D PCRE2_LIBRARY=/usr/local/pcre2/lib/libpcre2-8.0.dylib \
-D PCRE2_INCLUDE_DIR=/usr/local/pcre2/include/ \
-D JSONC_LIBRARY=/usr/local/json-c/lib/libjson-c.5.dylib \
-D JSONC_INCLUDE_DIR=/usr/local/json-c/include/json-c/ \
..

3. You get results as below:
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/xxx/clamav-0.105.1/build

4. Compile and install ClamAV®
make && make test
sudo make install




10) Build ClamAV with Ninja Build System

10-1. When you use LibreSSL…

1. Download the latest Stable Release ClamAV 0.105.1 from the ClamavNet.
cd ~
curl -LO https://www.clamav.net/downloads/release_candidate/clamav-0.105.1.tar.gz
tar zxf clamav-0.105.1.tar.gz

2. Set the build generator to Ninja, set Options and Library Paths, Configure and Generate
cd clamav-0.105.1
mkdir build
cd build 
cmake -G Ninja \
-D CMAKE_BUILD_TYPE=Release \
-D CMAKE_INSTALL_PREFIX=/usr/local/clamXav/ \
-D ENABLE_JSON_SHARED=OFF \
-D BYTECODE_RUNTIME="interpreter" \
-D ENABLE_TESTS=ON \
-D LIBCHECK_ROOT_DIR=/usr/local/check \
-D LIBCHECK_INCLUDE_DIR=/usr/local/check/include/ \
-D LIBCHECK_LIBRARY=/usr/local/check/lib/libcheck.0.dylib \
-D OPENSSL_ROOT_DIR=/usr/local/libressl/ \
-D OPENSSL_CRYPTO_LIBRARY=/usr/local/libressl/lib/libcrypto.49.dylib \
-D OPENSSL_SSL_LIBRARY=/usr/local/libressl/lib/libssl.52.dylib \
-D PCRE2_LIBRARY=/usr/local/pcre2/lib/libpcre2-8.0.dylib \
-D PCRE2_INCLUDE_DIR=/usr/local/pcre2/include/ \
-D JSONC_LIBRARY=/usr/local/json-c/lib/libjson-c.5.dylib \
-D JSONC_INCLUDE_DIR=/usr/local/json-c/include/json-c/ \
..

3. You get results as below:
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/xxx/clamav-0.105.1/build

4. Compile and make test
ninja && ninja test

5. You get results as below:
Running tests...
Test project /Users/eiichi/Desktop/clamav-0.105.1/build
    Start 1: libclamav
1/6 Test #1: libclamav ........................   Passed   10.27 sec
    Start 2: libclamav_rust
2/6 Test #2: libclamav_rust ...................   Passed   69.69 sec
    Start 3: clamscan
3/6 Test #3: clamscan .........................   Passed    3.70 sec
    Start 4: clamd
4/6 Test #4: clamd ............................   Passed   11.37 sec
    Start 5: freshclam
5/6 Test #5: freshclam ........................   Passed   32.46 sec
    Start 6: sigtool
6/6 Test #6: sigtool ..........................   Passed    0.24 sec

100% tests passed, 0 tests failed out of 6

6. Install ClamAV®
sudo ninja install





10-2. When you use OpenSSL…

1. Download the latest Stable Release ClamAV 0.105.1 from the ClamavNet.
cd ~
curl -LO https://www.clamav.net/downloads/release_candidate/clamav-0.105.1.tar.gz
tar zxf clamav-0.105.1.tar.gz

2. Set the build generator to Ninja, set Options and Library Paths, Configure and Generate
cd clamav-0.105.1
mkdir build
cd build 
cmake -G Ninja \
-D CMAKE_BUILD_TYPE=Release \
-D CMAKE_INSTALL_PREFIX=/usr/local/clamXav/ \
-D ENABLE_JSON_SHARED=OFF \
-D BYTECODE_RUNTIME="interpreter" \
-D ENABLE_TESTS=ON \
-D LIBCHECK_ROOT_DIR=/usr/local/check \
-D LIBCHECK_INCLUDE_DIR=/usr/local/check/include/ \
-D LIBCHECK_LIBRARY=/usr/local/check/lib/libcheck.0.dylib \
-D OPENSSL_ROOT_DIR=/usr/local/openssl/ \
-D OPENSSL_CRYPTO_LIBRARY=/usr/local/openssl/lib/libcrypto.3.dylib \
-D OPENSSL_SSL_LIBRARY=/usr/local/openssl/lib/libssl.3.dylib \
-D PCRE2_LIBRARY=/usr/local/pcre2/lib/libpcre2-8.0.dylib \
-D PCRE2_INCLUDE_DIR=/usr/local/pcre2/include/ \
-D JSONC_LIBRARY=/usr/local/json-c/lib/libjson-c.5.dylib \
-D JSONC_INCLUDE_DIR=/usr/local/json-c/include/json-c/ \
..

3. You get results as below:
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/xxx/clamav-0.105.1/build

4. Compile and install ClamAV®
ninja && ninja test
sudo ninja install



Links…

mail