From 1319796c911e785c90e4417ad6c8ab19e365ab29 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Tue, 12 Aug 2025 13:22:40 -0400 Subject: [PATCH 1/3] Structure CMake build like the others Do this by separating out a `src/CMakeLists.txt`. --- CMakeLists.txt | 20 +++----------------- flake.nix | 5 +++++ src/CMakeLists.txt | 12 ++++++++++++ 3 files changed, 20 insertions(+), 17 deletions(-) create mode 100644 src/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 1df5c097..4761582c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,26 +2,12 @@ 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}") +include(GNUInstallDirs) -install(TARGETS patchelf RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +add_subdirectory(src) +# add_subdirectory(tests) # TODO install(FILES patchelf.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1) diff --git a/flake.nix b/flake.nix index 6484a571..fb05fc24 100644 --- a/flake.nix +++ b/flake.nix @@ -39,12 +39,14 @@ (lib.fileset.difference ./src ( lib.fileset.unions [ ./src/Makefile.am + ./src/CMakeLists.txt ./src/meson.build ] )) (lib.fileset.difference ./tests ( lib.fileset.unions [ ./tests/Makefile.am + #./tests/CMakeLists.txt #./tests/meson.build ] )) @@ -61,12 +63,15 @@ cmakeSrcFiles = [ ./CMakeLists.txt + ./src/CMakeLists.txt + #./tests/CMakeLists.txt ]; mesonSrcFiles = [ ./meson.build ./meson.options ./src/meson.build + #./tests/meson.build ]; autotoolsSrc = lib.fileset.toSource { diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 00000000..2e6620ed --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,12 @@ +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_EXTENSIONS OFF) + +set(PAGESIZE 4096) + +add_executable(${PROJECT_NAME} patchelf.cc elf.h patchelf.h) + +target_compile_definitions( + patchelf PRIVATE PAGESIZE=${PAGESIZE} + PACKAGE_STRING="patchelf ${VERSION_STRING}") + +install(TARGETS patchelf RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) From c1beef4539acd32fd5eee95c603f17c2f4a64106 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Tue, 12 Aug 2025 13:23:17 -0400 Subject: [PATCH 2/3] Add an `.editorconfig` file Taken from Nix's. --- .editorconfig | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..142250dc --- /dev/null +++ b/.editorconfig @@ -0,0 +1,26 @@ +# EditorConfig configuration for PatchELF +# http://EditorConfig.org + +# Top-most EditorConfig file +root = true + +# Unix-style newlines with a newline ending every file, UTF-8 charset +[*] +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true +charset = utf-8 + +# Match Nix files, set indent to spaces with width of two +[*.nix] +indent_style = space +indent_size = 2 + +# Match C++/C/shell, set indent to spaces with width of four +[*.{hpp,cc,hh,c,h,sh}] +indent_style = space +indent_size = 4 + +# Match diffs, avoid to trim trailing whitespace +[*.{diff,patch}] +trim_trailing_whitespace = false From aed52ef51b4550db0471c5b45ddcf10aeb7913cd Mon Sep 17 00:00:00 2001 From: John Ericson Date: Tue, 12 Aug 2025 13:28:28 -0400 Subject: [PATCH 3/3] Add Meson build instructions Also fix CMake instructions indent level --- README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 59afd8f9..0b433771 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,7 @@ make check sudo make install ``` -## Via [CMake](https://cmake.org/) (and [Ninja](https://ninja-build.org/)) +### Via [CMake](https://cmake.org/) (and [Ninja](https://ninja-build.org/)) ```console mkdir build @@ -91,6 +91,16 @@ ninja all sudo ninja install ``` +### Via [Meson](https://mesonbuild.com/) (and [Ninja](https://ninja-build.org/)) + +```console +mkdir build +meson configure build +cd build +ninja all +sudo ninja install +``` + ### Via Nix You can build with Nix in several ways.