Commit fa2a2417 authored by Federico Mena Quintero's avatar Federico Mena Quintero

Merge branch 'add-cmake-support' into 'master'

Add CMake build system.

See merge request !19
parents 389961db a9934afb
Pipeline #66250307 passed with stage
in 2 minutes and 48 seconds
......@@ -26,4 +26,26 @@ manual.*
!manual.xml
missing
tests/*.rb2
tests/*.tst
\ No newline at end of file
tests/*.tst
# cmake
CMakeCache.txt
CMakeFiles/
cmake_install.cmake
install_manifest.txt
CTestTestfile.cmake
build.ninja
rules.ninja
.ninja_deps
.ninja_log
lib*.dylib
lib*.so
lib*.so.*
lib*.a
# example build directories
build
builddir
# vscode config directory
.vscode
......@@ -40,7 +40,21 @@ stages:
artifacts:
paths:
- 'meson-log.txt'
.cmake_test:
stage: test
script:
- mkdir builddir && cd builddir
- cmake ..
- cmake --build . --config Release
- make check
after_script:
- cp builddir/CMakeFiles/CMakeOutput.log .
- rm -rf builddir
artifacts:
paths:
- 'CMakeOutput.log'
debian:testing:
extends: '.meson_test'
image: $AMD64_DEBIAN_TESTING
......@@ -55,6 +69,14 @@ ubuntu:bionic:autotools:
- apt update -y
- apt install -y gcc make automake libtool
ubuntu:bionic:cmake:
extends: '.cmake_test'
image: $AMD64_UBUNTU_BIONIC
before_script:
- apt update -y
- apt install -y gcc make python3-pip
- pip3 install cmake
ubuntu:bionic:meson:
extends: '.meson_test'
image: $AMD64_UBUNTU_BIONIC
......
This diff is collapsed.
# Features that can be enabled for cmake (see CMakeLists.txt)
option(ENABLE_WERROR "Turn on compile time warnings")
option(ENABLE_DEBUG "Turn on debug output")
option(ENABLE_APP "Build applications (bzip2, and bzip2recover)"
${ENABLE_APP_DEFAULT})
option(ENABLE_DOCS "Generate documentation"
${ENABLE_DOCS_DEFAULT})
option(ENABLE_EXAMPLES "Build examples"
${ENABLE_EXAMPLES_DEFAULT})
option(ENABLE_LIB_ONLY "Build libbz2 only. This is a short hand for -DENABLE_APP=0 -DENABLE_EXAMPLES=0")
option(ENABLE_STATIC_LIB "Build libbz2 in static mode also")
option(ENABLE_SHARED_LIB "Build libbz2 as a shared library" ON)
......@@ -62,13 +62,62 @@ The [Meson] build system is the preferred way of building Bzip2. You
can use these commands to build Bzip2 in a certain `builddir`
directory.
```
```sh
meson --prefix /usr builddir
ninja -C builddir
meson test -C builddir --print-errorlogs
ninja -C builddir install
```
### Build instructions for Unix & Windows (CMake)
Bzip2 can be compiled with the [CMake] build system.
You can use these commands to build Bzip2 in a certain `build` directory.
#### Basic Release build
```sh
mkdir build && cd build
cmake ..
cmake --build . --config Release
```
#### Basic Debug build
```sh
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE="Debug"
cmake --build . --config Debug
```
#### Build and install to a specific install location (prefix)
```sh
mkdir build && cd build
cmake -DCMAKE_INSTALL_PREFIX:PATH=`pwd`/install ..
cmake --build . --target install --config Release
```
#### Build with example application (dlltest)
```sh
mkdir build && cd build
cmake -DCMAKE_INSTALL_PREFIX:PATH=`pwd`/install .. -DENABLE_EXAMPLES=ON
cmake --build . --target install --config Release
```
#### Build and run tests
- `-V`: Verbose
- `-C`: Required for Windows builds
```sh
mkdir build && cd build
cmake ..
cmake --build . --config Release
ctest -C Release -V
```
### Build instructions for Unix (Autotools)
If you are compiling a tarball:
......@@ -134,7 +183,7 @@ PROGRAM UNLESS YOU ARE PREPARED TO ACCEPT THE POSSIBILITY, HOWEVER
SMALL, THAT THE DATA WILL NOT BE RECOVERABLE.
That is not to say this program is inherently unreliable.
Indeed, I very much hope the opposite is true. Bzip2/libbz2
Indeed, I very much hope the opposite is true. Bzip2/libbz2
has been carefully constructed and extensively tested.
## PATENTS
......
# Convenience function that checks the availability of certain
# C or C++ compiler flags and returns valid ones as a string.
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
function(extract_valid_c_flags varname)
set(valid_flags)
foreach(flag IN LISTS ARGN)
string(REGEX REPLACE "[^a-zA-Z0-9_]+" "_" flag_var ${flag})
set(flag_var "C_FLAG_${flag_var}")
check_c_compiler_flag("${flag}" "${flag_var}")
if(${flag_var})
set(valid_flags "${valid_flags} ${flag}")
endif()
endforeach()
set(${varname} "${valid_flags}" PARENT_SCOPE)
endfunction()
function(extract_valid_cxx_flags varname)
set(valid_flags)
foreach(flag IN LISTS ARGN)
string(REGEX REPLACE "[^a-zA-Z0-9_]+" "_" flag_var ${flag})
set(flag_var "CXX_FLAG_${flag_var}")
check_cxx_compiler_flag("${flag}" "${flag_var}")
if(${flag_var})
set(valid_flags "${valid_flags} ${flag}")
endif()
endforeach()
set(${varname} "${valid_flags}" PARENT_SCOPE)
endfunction()
\ No newline at end of file
# - Try to find cunit
# Once done this will define
# CUNIT_FOUND - System has cunit
# CUNIT_INCLUDE_DIRS - The cunit include directories
# CUNIT_LIBRARIES - The libraries needed to use cunit
find_package(PkgConfig QUIET)
pkg_check_modules(PC_CUNIT QUIET cunit)
find_path(CUNIT_INCLUDE_DIR
NAMES CUnit/CUnit.h
HINTS ${PC_CUNIT_INCLUDE_DIRS}
)
find_library(CUNIT_LIBRARY
NAMES cunit
HINTS ${PC_CUNIT_LIBRARY_DIRS}
)
if(CUNIT_INCLUDE_DIR)
set(_version_regex "^#define[ \t]+CU_VERSION[ \t]+\"([^\"]+)\".*")
file(STRINGS "${CUNIT_INCLUDE_DIR}/CUnit/CUnit.h"
CUNIT_VERSION REGEX "${_version_regex}")
string(REGEX REPLACE "${_version_regex}" "\\1"
CUNIT_VERSION "${CUNIT_VERSION}")
unset(_version_regex)
endif()
include(FindPackageHandleStandardArgs)
# handle the QUIETLY and REQUIRED arguments and set CUNIT_FOUND to TRUE
# if all listed variables are TRUE and the requested version matches.
find_package_handle_standard_args(CUnit REQUIRED_VARS
CUNIT_LIBRARY CUNIT_INCLUDE_DIR
VERSION_VAR CUNIT_VERSION)
if(CUNIT_FOUND)
set(CUNIT_LIBRARIES ${CUNIT_LIBRARY})
set(CUNIT_INCLUDE_DIRS ${CUNIT_INCLUDE_DIR})
endif()
mark_as_advanced(CUNIT_INCLUDE_DIR CUNIT_LIBRARY)
# 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()
set(DOC_TYPES pdf ps html)
find_program(PROG_SH sh)
if(NOT PROG_SH)
message(FATAL_ERROR "Generator not found!")
endif()
foreach(t IN LISTS DOC_TYPES)
add_custom_command(
OUTPUT
manual.${t}
COMMAND
${PROG_SH} xmlproc.sh -${t} manual.${t}
)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/manual.${t}
DESTINATION
${CMAKE_INSTALL_PREFIX}/docs)
endforeach()
set(MAN_FILES bzip2.1 bzgrep.1 bzdiff.1 bzmore.1)
foreach(m IN LISTS MAN_FILES)
install(
FILES
${CMAKE_CURRENT_SOURCE_DIR}/${m}
DESTINATION
${CMAKE_INSTALL_PREFIX}/man/man1)
endforeach()
set(sample1 -1 sample1.ref sample1.bz2)
set(sample2 -1 sample2.ref sample2.bz2)
set(sample3 -1 sample3.ref sample3.bz2)
if(WIN32)
set(BZIP2_EXE "$<CONFIG>/bzip2.exe")
else()
set(BZIP2_EXE bzip2)
endif()
foreach(TEST
"${sample1}"
"${sample2}"
"${sample3}"
)
list(GET TEST 0 block_size)
list(GET TEST 1 file_name)
list(GET TEST 2 zip_name)
add_test(NAME "compress_${file_name}"
COMMAND ${Python3_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/runtest.py
--mode compress
${CMAKE_BINARY_DIR}/${BZIP2_EXE}
${block_size}
${CMAKE_CURRENT_SOURCE_DIR}/${file_name}
${CMAKE_CURRENT_SOURCE_DIR}/${zip_name}
)
endforeach()
foreach(TEST
"${sample1}"
"${sample2}"
"${sample3}"
)
list(GET TEST 0 block_size)
list(GET TEST 1 file_name)
add_test(NAME "decompress_${file_name}"
COMMAND ${Python3_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/runtest.py
--mode decompress
${CMAKE_BINARY_DIR}/${BZIP2_EXE}
${block_size}
${CMAKE_CURRENT_SOURCE_DIR}/${file_name}
)
endforeach()
#include <winver.h>
VS_VERSION_INFO VERSIONINFO
FILEVERSION @PROJECT_VERSION_MAJOR@, @PROJECT_VERSION_MINOR@, @PROJECT_VERSION_PATCH@, 0
PRODUCTVERSION @PROJECT_VERSION_MAJOR@, @PROJECT_VERSION_MINOR@, @PROJECT_VERSION_PATCH@, 0
FILEFLAGSMASK 0x3fL
FILEOS VOS__WINDOWS32
#if defined(LIBBZ2)
FILETYPE VFT_DLL
#else
FILETYPE VFT_APP
#endif
FILESUBTYPE 0x0L
#ifdef _DEBUG
#define VER_STR "@PROJECT_VERSION@.0 (MSVC debug)"
#define DBG "d"
FILEFLAGS 0x1L
#else
#define VER_STR "@PROJECT_VERSION@.0 (MSVC release)"
#define DBG ""
FILEFLAGS 0x0L
#endif
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
// VALUE "Comments", ""
VALUE "CompanyName", "bzip2, http://www.bzip.org/"
VALUE "FileDescription", "bzip2"
VALUE "FileVersion", "1.0.6"
#if defined(LIBBZ2)
VALUE "InternalName", "libbz2"
VALUE "OriginalFilename", "libbz2.dll"
#elif defined(BZIP2)
VALUE "InternalName", "bzip2"
VALUE "OriginalFilename", "bzip2.exe"
#elif defined(BZIP2RECOVER)
VALUE "InternalName", "bzip2recover"
VALUE "OriginalFilename", "bzip2recover.exe"
#endif
VALUE "LegalCopyright", "Copyright (C) 1996-2010 Julian Seward <jseward@bzip.org>. All rights reserved."
VALUE "LegalTrademarks", ""
VALUE "ProductName", "bzip2"
VALUE "ProductVersion", "1.0.6"
// VALUE "SpecialBuild", ""
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 0x4b0
END
END
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment