|
Panu Matilainen |
033b63 |
From bbb289e303d8c72b9e35410e593b8d92b006bec1 Mon Sep 17 00:00:00 2001
|
|
Panu Matilainen |
033b63 |
Message-ID: <bbb289e303d8c72b9e35410e593b8d92b006bec1.1692703597.git.pmatilai@redhat.com>
|
|
Panu Matilainen |
033b63 |
From: Panu Matilainen <pmatilai@redhat.com>
|
|
Panu Matilainen |
033b63 |
Date: Mon, 14 Aug 2023 12:29:11 +0300
|
|
Panu Matilainen |
033b63 |
Subject: [PATCH 1/3] Unroll the utility finding loop in cmake for flexibility
|
|
Panu Matilainen |
033b63 |
+ readability
|
|
Panu Matilainen |
033b63 |
|
|
Panu Matilainen |
033b63 |
We need more flexibility than a simple array can provide, and with
|
|
Panu Matilainen |
033b63 |
all the name munging, it's not particularly obvious as to what
|
|
Panu Matilainen |
033b63 |
values are set and how. Supposedly no functional changes here.
|
|
Panu Matilainen |
033b63 |
---
|
|
Panu Matilainen |
033b63 |
CMakeLists.txt | 79 ++++++++++++++++++++++++++++++++++++--------------
|
|
Panu Matilainen |
033b63 |
1 file changed, 57 insertions(+), 22 deletions(-)
|
|
Panu Matilainen |
033b63 |
|
|
Panu Matilainen |
033b63 |
diff --git a/CMakeLists.txt b/CMakeLists.txt
|
|
Panu Matilainen |
033b63 |
index 1de88245c..30f413028 100644
|
|
Panu Matilainen |
033b63 |
--- a/CMakeLists.txt
|
|
Panu Matilainen |
033b63 |
+++ b/CMakeLists.txt
|
|
Panu Matilainen |
033b63 |
@@ -53,6 +53,22 @@ include(GNUInstallDirs)
|
|
Panu Matilainen |
033b63 |
add_compile_definitions(_GNU_SOURCE)
|
|
Panu Matilainen |
033b63 |
add_definitions(-D_FILE_OFFSET_BITS=64)
|
|
Panu Matilainen |
033b63 |
|
|
Panu Matilainen |
033b63 |
+function(findutil UTIL TRY)
|
|
Panu Matilainen |
033b63 |
+ list(GET TRY 0 util)
|
|
Panu Matilainen |
033b63 |
+ find_program(${UTIL}
|
|
Panu Matilainen |
033b63 |
+ NAMES ${TRY}
|
|
Panu Matilainen |
033b63 |
+ PATHS ENV MYPATH
|
|
Panu Matilainen |
033b63 |
+ PATHS /usr/local/bin /usr/bin /bin
|
|
Panu Matilainen |
033b63 |
+ PATHS /usr/local/sbin /usr/sbin /sbin
|
|
Panu Matilainen |
033b63 |
+ NO_DEFAULT_PATH
|
|
Panu Matilainen |
033b63 |
+ )
|
|
Panu Matilainen |
033b63 |
+ if (NOT ${UTIL})
|
|
Panu Matilainen |
033b63 |
+ list(GET TRY 0 util)
|
|
Panu Matilainen |
033b63 |
+ message(DEBUG "${util} not found, assuming /usr/bin/${util}")
|
|
Panu Matilainen |
033b63 |
+ set(${UTIL} /usr/bin/${util} PARENT_SCOPE)
|
|
Panu Matilainen |
033b63 |
+ endif()
|
|
Panu Matilainen |
033b63 |
+endfunction()
|
|
Panu Matilainen |
033b63 |
+
|
|
Panu Matilainen |
033b63 |
function(makemacros)
|
|
Panu Matilainen |
033b63 |
set(prefix ${CMAKE_INSTALL_PREFIX})
|
|
Panu Matilainen |
033b63 |
set(exec_prefix "\${prefix}")
|
|
Panu Matilainen |
033b63 |
@@ -72,28 +88,47 @@ function(makemacros)
|
|
Panu Matilainen |
033b63 |
set(rundir /run)
|
|
Panu Matilainen |
033b63 |
set(root_prefix /usr)
|
|
Panu Matilainen |
033b63 |
|
|
Panu Matilainen |
033b63 |
- set(extutils
|
|
Panu Matilainen |
033b63 |
- 7zip bzip2 cat chmod chown cp curl file gpg grep gzip id cc ln
|
|
Panu Matilainen |
033b63 |
- install lrzip lzip xz make mkdir mv patch rm sed tar unzip
|
|
Panu Matilainen |
033b63 |
- zstd gem git hg bzr quilt ld objdump strip systemd-sysusers
|
|
Panu Matilainen |
033b63 |
- awk ar as cpp c++
|
|
Panu Matilainen |
033b63 |
- )
|
|
Panu Matilainen |
033b63 |
- foreach (util ${extutils})
|
|
Panu Matilainen |
033b63 |
- string(TOUPPER ${util} UTIL)
|
|
Panu Matilainen |
033b63 |
- string(REPLACE "-" "_" UTIL ${UTIL})
|
|
Panu Matilainen |
033b63 |
- string(REPLACE "+" "X" UTIL ${UTIL})
|
|
Panu Matilainen |
033b63 |
- find_program(__${UTIL} ${util}
|
|
Panu Matilainen |
033b63 |
- PATHS ENV MYPATH
|
|
Panu Matilainen |
033b63 |
- PATHS /usr/local/bin /usr/bin /bin
|
|
Panu Matilainen |
033b63 |
- PATHS /usr/local/sbin /usr/sbin /sbin
|
|
Panu Matilainen |
033b63 |
- NO_DEFAULT_PATH
|
|
Panu Matilainen |
033b63 |
- )
|
|
Panu Matilainen |
033b63 |
- message(INFO ${util} " got " ${UTIL} ": " ${__${UTIL}})
|
|
Panu Matilainen |
033b63 |
- if (NOT EXISTS ${__${UTIL}})
|
|
Panu Matilainen |
033b63 |
- message(DEBUG "${util} not found, assuming /usr/bin")
|
|
Panu Matilainen |
033b63 |
- set(__${UTIL} /usr/bin/${util})
|
|
Panu Matilainen |
033b63 |
- endif()
|
|
Panu Matilainen |
033b63 |
- endforeach()
|
|
Panu Matilainen |
033b63 |
+ findutil(__7ZIP 7zip)
|
|
Panu Matilainen |
033b63 |
+ findutil(__BZIP2 bzip2)
|
|
Panu Matilainen |
033b63 |
+ findutil(__CAT cat)
|
|
Panu Matilainen |
033b63 |
+ findutil(__CHMOD chmod)
|
|
Panu Matilainen |
033b63 |
+ findutil(__CHOWN chown)
|
|
Panu Matilainen |
033b63 |
+ findutil(__CP cp)
|
|
Panu Matilainen |
033b63 |
+ findutil(__CURL curl)
|
|
Panu Matilainen |
033b63 |
+ findutil(__FILE file)
|
|
Panu Matilainen |
033b63 |
+ findutil(__GPG gpg)
|
|
Panu Matilainen |
033b63 |
+ findutil(__GREP grep)
|
|
Panu Matilainen |
033b63 |
+ findutil(__GZIP gzip)
|
|
Panu Matilainen |
033b63 |
+ findutil(__ID id)
|
|
Panu Matilainen |
033b63 |
+ findutil(__CC cc)
|
|
Panu Matilainen |
033b63 |
+ findutil(__LN ln)
|
|
Panu Matilainen |
033b63 |
+ findutil(__INSTALL install)
|
|
Panu Matilainen |
033b63 |
+ findutil(__LRZIP lrzip)
|
|
Panu Matilainen |
033b63 |
+ findutil(__LZIP lzip)
|
|
Panu Matilainen |
033b63 |
+ findutil(__XZ xz)
|
|
Panu Matilainen |
033b63 |
+ findutil(__MAKE make)
|
|
Panu Matilainen |
033b63 |
+ findutil(__MKDIR mkdir)
|
|
Panu Matilainen |
033b63 |
+ findutil(__MV mv)
|
|
Panu Matilainen |
033b63 |
+ findutil(__PATCH patch)
|
|
Panu Matilainen |
033b63 |
+ findutil(__RM rm)
|
|
Panu Matilainen |
033b63 |
+ findutil(__SED sed)
|
|
Panu Matilainen |
033b63 |
+ findutil(__TAR tar)
|
|
Panu Matilainen |
033b63 |
+ findutil(__UNZIP unzip)
|
|
Panu Matilainen |
033b63 |
+ findutil(__ZSTD zstd)
|
|
Panu Matilainen |
033b63 |
+ findutil(__GEM gem)
|
|
Panu Matilainen |
033b63 |
+ findutil(__GIT git)
|
|
Panu Matilainen |
033b63 |
+ findutil(__HG hg)
|
|
Panu Matilainen |
033b63 |
+ findutil(__BZR bzr)
|
|
Panu Matilainen |
033b63 |
+ findutil(__QUILT quilt)
|
|
Panu Matilainen |
033b63 |
+ findutil(__LD ld)
|
|
Panu Matilainen |
033b63 |
+ findutil(__OBJDUMP objdump)
|
|
Panu Matilainen |
033b63 |
+ findutil(__STRIP strip)
|
|
Panu Matilainen |
033b63 |
+ findutil(__SYSTEMD_SYSUSERS systemd-sysusers)
|
|
Panu Matilainen |
033b63 |
+ findutil(__AWK awk)
|
|
Panu Matilainen |
033b63 |
+ findutil(__AR ar)
|
|
Panu Matilainen |
033b63 |
+ findutil(__AS as)
|
|
Panu Matilainen |
033b63 |
+ findutil(__CPP cpp)
|
|
Panu Matilainen |
033b63 |
+ findutil(__CXX c++)
|
|
Panu Matilainen |
033b63 |
|
|
Panu Matilainen |
033b63 |
list(GET db_backends 0 DB_BACKEND)
|
|
Panu Matilainen |
033b63 |
|
|
Panu Matilainen |
033b63 |
--
|
|
Panu Matilainen |
033b63 |
2.41.0
|
|
Panu Matilainen |
033b63 |
|