Skip to content

Commit

Permalink
Unroll the utility finding loop in cmake for flexibility + readability
Browse files Browse the repository at this point in the history
We need more flexibility than a simple array can provide, and with
all the name munging, it's not particularly obvious as to what
values are set and how. Supposedly no functional changes here.
  • Loading branch information
pmatilai committed Aug 14, 2023
1 parent 194eb10 commit d16dafb
Showing 1 changed file with 57 additions and 22 deletions.
79 changes: 57 additions & 22 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,22 @@ include(GNUInstallDirs)
add_compile_definitions(_GNU_SOURCE)
add_definitions(-D_FILE_OFFSET_BITS=64)

function(findutil UTIL TRY)
list(GET TRY 0 util)
find_program(${UTIL}
NAMES ${TRY}
PATHS ENV MYPATH
PATHS /usr/local/bin /usr/bin /bin
PATHS /usr/local/sbin /usr/sbin /sbin
NO_DEFAULT_PATH
)
if (NOT ${UTIL})
list(GET TRY 0 util)
message(DEBUG "${util} not found, assuming /usr/bin/${util}")
set(${UTIL} /usr/bin/${util} PARENT_SCOPE)
endif()
endfunction()

function(makemacros)
set(prefix ${CMAKE_INSTALL_PREFIX})
set(exec_prefix "\${prefix}")
Expand All @@ -72,28 +88,47 @@ function(makemacros)
set(rundir /run)
set(root_prefix /usr)

set(extutils
7zip bzip2 cat chmod chown cp curl file gpg grep gzip id cc ln
install lrzip lzip xz make mkdir mv patch rm sed tar unzip
zstd gem git hg bzr quilt ld objdump strip systemd-sysusers
awk ar as cpp c++
)
foreach (util ${extutils})
string(TOUPPER ${util} UTIL)
string(REPLACE "-" "_" UTIL ${UTIL})
string(REPLACE "+" "X" UTIL ${UTIL})
find_program(__${UTIL} ${util}
PATHS ENV MYPATH
PATHS /usr/local/bin /usr/bin /bin
PATHS /usr/local/sbin /usr/sbin /sbin
NO_DEFAULT_PATH
)
message(INFO ${util} " got " ${UTIL} ": " ${__${UTIL}})
if (NOT EXISTS ${__${UTIL}})
message(DEBUG "${util} not found, assuming /usr/bin")
set(__${UTIL} /usr/bin/${util})
endif()
endforeach()
findutil(__7ZIP 7zip)
findutil(__BZIP2 bzip2)
findutil(__CAT cat)
findutil(__CHMOD chmod)
findutil(__CHOWN chown)
findutil(__CP cp)
findutil(__CURL curl)
findutil(__FILE file)
findutil(__GPG gpg)
findutil(__GREP grep)
findutil(__GZIP gzip)
findutil(__ID id)
findutil(__CC cc)
findutil(__LN ln)
findutil(__INSTALL install)
findutil(__LRZIP lrzip)
findutil(__LZIP lzip)
findutil(__XZ xz)
findutil(__MAKE make)
findutil(__MKDIR mkdir)
findutil(__MV mv)
findutil(__PATCH patch)
findutil(__RM rm)
findutil(__SED sed)
findutil(__TAR tar)
findutil(__UNZIP unzip)
findutil(__ZSTD zstd)
findutil(__GEM gem)
findutil(__GIT git)
findutil(__HG hg)
findutil(__BZR bzr)
findutil(__QUILT quilt)
findutil(__LD ld)
findutil(__OBJDUMP objdump)
findutil(__STRIP strip)
findutil(__SYSTEMD_SYSUSERS systemd-sysusers)
findutil(__AWK awk)
findutil(__AR ar)
findutil(__AS as)
findutil(__CPP cpp)
findutil(__CXX c++)

list(GET db_backends 0 DB_BACKEND)

Expand Down

0 comments on commit d16dafb

Please sign in to comment.