From 51cf74ce103b921950aa4bdacc68476add930641 Mon Sep 17 00:00:00 2001 From: david feurle Date: Sat, 3 Dec 2016 13:18:05 +0100 Subject: [PATCH] Add CMake build Co-Authored-by: John Ericson --- .gitignore | 2 + CMakeLists.txt | 31 +++++++++++++ README.md | 12 ++++- flake.nix | 68 ++++++++++++++++++++-------- maintainers/flake-module.nix | 3 ++ package.nix => package-autotools.nix | 0 package-cmake.nix | 17 +++++++ 7 files changed, 112 insertions(+), 21 deletions(-) create mode 100644 CMakeLists.txt rename package.nix => package-autotools.nix (100%) create mode 100644 package-cmake.nix diff --git a/.gitignore b/.gitignore index 423e8eec..df440b64 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,8 @@ Makefile .deps *.o +CMakeLists.txt.user + /tests/*.log /tests/*.trs /tests/no-rpath diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..1df5c097 --- /dev/null +++ b/CMakeLists.txt @@ -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) diff --git a/README.md b/README.md index 69e80dc9..59afd8f9 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/flake.nix b/flake.nix index 701aa109..e3ed58a3 100644 --- a/flake.nix +++ b/flake.nix @@ -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; diff --git a/maintainers/flake-module.nix b/maintainers/flake-module.nix index ebfd6ba1..4b9b4023 100644 --- a/maintainers/flake-module.nix +++ b/maintainers/flake-module.nix @@ -37,6 +37,9 @@ fi ''}"; }; + cmake-format = { + enable = true; + }; nixfmt-rfc-style = { enable = true; }; diff --git a/package.nix b/package-autotools.nix similarity index 100% rename from package.nix rename to package-autotools.nix diff --git a/package-cmake.nix b/package-cmake.nix new file mode 100644 index 00000000..de8efe20 --- /dev/null +++ b/package-cmake.nix @@ -0,0 +1,17 @@ +{ + stdenv, + cmake, + ninja, + version, + src, +}: + +stdenv.mkDerivation { + pname = "patchelf"; + inherit version src; + nativeBuildInputs = [ + cmake + ninja + ]; + doCheck = true; +}