Add CMake build

Co-Authored-by: John Ericson <John.Ericson@Obsidian.Systems>
This commit is contained in:
david feurle
2016-12-03 13:18:05 +01:00
committed by John Ericson
parent f8621b633a
commit 51cf74ce10
7 changed files with 112 additions and 21 deletions

2
.gitignore vendored
View File

@@ -18,6 +18,8 @@ Makefile
.deps
*.o
CMakeLists.txt.user
/tests/*.log
/tests/*.trs
/tests/no-rpath

31
CMakeLists.txt Normal file
View File

@@ -0,0 +1,31 @@
cmake_minimum_required(VERSION 3.5)
project(patchelf)
include(GNUInstallDirs)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_EXTENSIONS OFF)
set(PAGESIZE 4096)
set(ADDITIONAL_HEADERS src/elf.h)
set(SOURCES src/patchelf.cc)
file(READ version VERSION)
add_executable(${PROJECT_NAME} ${SOURCES} ${ADDITIONAL_HEADERS})
target_compile_definitions(
patchelf PRIVATE PAGESIZE=${PAGESIZE}
PACKAGE_STRING="patchelf ${VERSION_STRING}")
install(TARGETS patchelf RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install(FILES patchelf.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
install(FILES README.md DESTINATION ${CMAKE_INSTALL_DOCDIR})
install(FILES completions/zsh/_patchelf
DESTINATION ${CMAKE_INSTALL_DATADIR}/zsh/site-functions)

View File

@@ -72,7 +72,7 @@ libraries. In particular, it can do the following:
## Compiling and Testing
### Via Autotools
### Via [GNU Autotools](https://www.gnu.org/software/automake/manual/html_node/Autotools-Introduction.html)
```console
./bootstrap.sh
./configure
@@ -81,6 +81,16 @@ make check
sudo make install
```
## Via [CMake](https://cmake.org/) (and [Ninja](https://ninja-build.org/))
```console
mkdir build
cd build
cmake .. -GNinja
ninja all
sudo ninja install
```
### Via Nix
You can build with Nix in several ways.

View File

@@ -30,27 +30,37 @@
version = lib.removeSuffix "\n" (builtins.readFile ./version);
pkgs = nixpkgs.legacyPackages.x86_64-linux;
src = lib.fileset.toSource {
baseSrcFiles = [
./COPYING
./README.md
./completions
./patchelf.1
./patchelf.spec.in
./src
./tests
./version
];
autotoolsSrcFiles = [
./Makefile.am
./configure.ac
./m4
];
cmakeSrcFiles = [
./CMakeLists.txt
];
autotoolsSrc = lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions [
./COPYING
./Makefile.am
./README.md
./completions
./configure.ac
./m4
./patchelf.1
./patchelf.spec.in
./src
./tests
./version
];
fileset = lib.fileset.unions (baseSrcFiles ++ autotoolsSrcFiles);
};
patchelfFor =
pkgs:
pkgs.callPackage ./package.nix {
inherit version src;
pkgs.callPackage ./package-autotools.nix {
inherit version;
src = autotoolsSrc;
};
# We don't apply flake-parts to the whole flake so that non-development attributes
@@ -76,7 +86,11 @@
hydraJobs = {
tarball = pkgs.releaseTools.sourceTarball rec {
name = "patchelf-tarball";
inherit version src;
inherit version;
src = lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions (baseSrcFiles ++ autotoolsSrcFiles ++ cmakeSrcFiles);
};
versionSuffix = ""; # obsolete
preAutoconf = "echo ${version} > version";
@@ -117,6 +131,8 @@
})
);
build-cmake = forAllSystems (system: self.packages.${system}.patchelf-cmake);
# x86_64-linux seems to be only working clangStdenv at the moment
build-sanitized-clang = lib.genAttrs [ "x86_64-linux" ] (
system:
@@ -134,6 +150,7 @@
self.hydraJobs.tarball
self.hydraJobs.build.x86_64-linux
self.hydraJobs.build.i686-linux
self.hydraJobs.build-cmake.x86_64-linux
# FIXME: add aarch64 emulation to our github action...
#self.hydraJobs.build.aarch64-linux
self.hydraJobs.build-sanitized.x86_64-linux
@@ -172,8 +189,10 @@
}";
};
nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [
#pkgs.buildPackages.cmake
#pkgs.buildPackages.ninja
modular.pre-commit.settings.package
(pkgs.writeScriptBin "pre-commit-hooks-install" modular.pre-commit.settings.installationScript)
(pkgs.buildPackages.writeScriptBin "pre-commit-hooks-install" modular.pre-commit.settings.installationScript)
];
}
);
@@ -194,8 +213,9 @@
patchelfForWindowsStatic =
pkgs:
(pkgs.callPackage ./package.nix {
inherit version src;
(pkgs.callPackage ./package-autotools.nix {
inherit version;
src = autotoolsSrc;
# On windows we use win32 threads to get a static binary,
# otherwise `-static` below doesn't work.
stdenv = pkgs.stdenv.override (old: {
@@ -217,6 +237,14 @@
patchelf = patchelfFor pkgs;
default = self.packages.${system}.patchelf;
patchelf-cmake = pkgs.callPackage ./package-cmake.nix {
inherit version;
src = lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions (baseSrcFiles ++ cmakeSrcFiles);
};
};
# This is a good test to see if packages can be cross-compiled. It also
# tests if our testsuite uses target-prefixed executable names.
patchelf-musl-cross = patchelfFor pkgs.pkgsCross.musl64;

View File

@@ -37,6 +37,9 @@
fi
''}";
};
cmake-format = {
enable = true;
};
nixfmt-rfc-style = {
enable = true;
};

17
package-cmake.nix Normal file
View File

@@ -0,0 +1,17 @@
{
stdenv,
cmake,
ninja,
version,
src,
}:
stdenv.mkDerivation {
pname = "patchelf";
inherit version src;
nativeBuildInputs = [
cmake
ninja
];
doCheck = true;
}