Skip to content

Commit 7f27ace

Browse files
Add cmake build
Co-Authored-by: John Ericson <John.Ericson@Obsidian.Systems>
1 parent c0c9f3a commit 7f27ace

6 files changed

Lines changed: 55 additions & 3 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Makefile
1818
.deps
1919
*.o
2020

21+
CMakeLists.txt.user
22+
2123
/tests/*.log
2224
/tests/*.trs
2325
/tests/no-rpath

CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
cmake_minimum_required(VERSION 3.5)
2+
3+
project(patchelf)
4+
5+
set(CMAKE_CXX_STANDARD 17)
6+
set(CMAKE_CXX_EXTENSIONS OFF)
7+
8+
set(PAGESIZE 4096)
9+
10+
set(ADDITIONAL_HEADERS src/elf.h)
11+
12+
set(SOURCES src/patchelf.cc)
13+
14+
file(READ version VERSION)
15+
16+
add_executable(${PROJECT_NAME} ${SOURCES} ${ADDITIONAL_HEADERS})
17+
18+
target_compile_definitions(
19+
patchelf PRIVATE PAGESIZE=${PAGESIZE}
20+
PACKAGE_STRING="patchelf ${VERSION_STRING}")

flake.nix

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
src = lib.fileset.toSource {
3434
root = ./.;
3535
fileset = lib.fileset.unions [
36+
./CMakeLists.txt
3637
./COPYING
3738
./Makefile.am
3839
./README.md
@@ -49,7 +50,7 @@
4950

5051
patchelfFor =
5152
pkgs:
52-
pkgs.callPackage ./package.nix {
53+
pkgs.callPackage ./package-autoconf.nix {
5354
inherit version src;
5455
};
5556

@@ -117,6 +118,8 @@
117118
})
118119
);
119120

121+
build-cmake = forAllSystems (system: self.packages.${system}.patchelf-cmake);
122+
120123
# x86_64-linux seems to be only working clangStdenv at the moment
121124
build-sanitized-clang = lib.genAttrs [ "x86_64-linux" ] (
122125
system:
@@ -134,6 +137,7 @@
134137
self.hydraJobs.tarball
135138
self.hydraJobs.build.x86_64-linux
136139
self.hydraJobs.build.i686-linux
140+
self.hydraJobs.build-cmake.x86_64-linux
137141
# FIXME: add aarch64 emulation to our github action...
138142
#self.hydraJobs.build.aarch64-linux
139143
self.hydraJobs.build-sanitized.x86_64-linux
@@ -172,8 +176,10 @@
172176
}";
173177
};
174178
nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [
179+
#pkgs.buildPackages.cmake
180+
#pkgs.buildPackages.ninja
175181
modular.pre-commit.settings.package
176-
(pkgs.writeScriptBin "pre-commit-hooks-install" modular.pre-commit.settings.installationScript)
182+
(pkgs.buildPackages.writeScriptBin "pre-commit-hooks-install" modular.pre-commit.settings.installationScript)
177183
];
178184
}
179185
);
@@ -194,7 +200,7 @@
194200

195201
patchelfForWindowsStatic =
196202
pkgs:
197-
(pkgs.callPackage ./package.nix {
203+
(pkgs.callPackage ./package-autoconf.nix {
198204
inherit version src;
199205
# On windows we use win32 threads to get a static binary,
200206
# otherwise `-static` below doesn't work.
@@ -217,6 +223,10 @@
217223
patchelf = patchelfFor pkgs;
218224
default = self.packages.${system}.patchelf;
219225

226+
patchelf-cmake = pkgs.callPackage ./package-cmake.nix {
227+
inherit version src;
228+
};
229+
220230
# This is a good test to see if packages can be cross-compiled. It also
221231
# tests if our testsuite uses target-prefixed executable names.
222232
patchelf-musl-cross = patchelfFor pkgs.pkgsCross.musl64;

maintainers/flake-module.nix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
fi
3838
''}";
3939
};
40+
cmake-format = {
41+
enable = true;
42+
};
4043
nixfmt-rfc-style = {
4144
enable = true;
4245
};
File renamed without changes.

package-cmake.nix

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
stdenv,
3+
cmake,
4+
ninja,
5+
version,
6+
src,
7+
}:
8+
9+
stdenv.mkDerivation {
10+
pname = "patchelf";
11+
inherit version src;
12+
nativeBuildInputs = [
13+
cmake
14+
ninja
15+
];
16+
doCheck = true;
17+
}

0 commit comments

Comments
 (0)