diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-11-25 17:33:56 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-11-25 17:34:10 +0000 |
commit | 83ba6762cc43d9db581b979bb5e3445669e46cc2 (patch) | |
tree | 2e69833b43f791ed253a7a20318b767ebe56cdb8 /packaging/cmake/Modules/NetdataUtil.cmake | |
parent | Releasing debian version 1.47.5-1. (diff) | |
download | netdata-83ba6762cc43d9db581b979bb5e3445669e46cc2.tar.xz netdata-83ba6762cc43d9db581b979bb5e3445669e46cc2.zip |
Merging upstream version 2.0.3+dfsg (Closes: #923993, #1042533, #1045145).
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'packaging/cmake/Modules/NetdataUtil.cmake')
-rw-r--r-- | packaging/cmake/Modules/NetdataUtil.cmake | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/packaging/cmake/Modules/NetdataUtil.cmake b/packaging/cmake/Modules/NetdataUtil.cmake index c6a13309f..0c1d803ea 100644 --- a/packaging/cmake/Modules/NetdataUtil.cmake +++ b/packaging/cmake/Modules/NetdataUtil.cmake @@ -144,3 +144,78 @@ function(netdata_identify_libc _libc_name) set(${_libc_name} ${_ND_DETECTED_LIBC} PARENT_SCOPE) endif() endfunction() + +# Extract a tar archive. +# +# This will use CMake’s native support if available, but will still +# fall back cleanly if CMake is too old. +function(extract_gzipped_tarball tarball target) + if(CMAKE_VERSION VERSION_LESS 3.18) + find_program(TAR NAMES tar bsdtar DOC "TAR archive program") + + if(TAR STREQUAL "TAR-NOTFOUND") + message(FATAL_ERROR "Unable to find tar command") + endif() + + find_program(GZIP NAMES gzip DOC "GZIP compression program") + + if(GZIP STREQUAL "GZIP-NOTFOUND") + message(FATAL_ERROR "Unable to find gzip command") + endif() + + file(MAKE_DIRECTORY "${target}") + execute_process(COMMAND tar -x -z -f "${tarball}" -C "${target}" + RESULT_VARIABLE result) + + if(result) + message(FATAL_ERROR "Failed to extract ${tarball}") + endif() + else() + file(ARCHIVE_EXTRACT + INPUT "${tarball}" + DESTINATION "${target}") + endif() +endfunction() + +# Get a recursive list of all sub-directories of the specified directory, +# relative to that directory. +function(subdirlist result curdir) + file(GLOB_RECURSE children + LIST_DIRECTORIES TRUE + RELATIVE ${curdir} + ${curdir}/*) + + set(dirlist "") + + foreach(child ${children}) + if(IS_DIRECTORY ${curdir}/${child}) + list(APPEND dirlist ${child}) + endif() + endforeach() + + set(${result} ${dirlist} PARENT_SCOPE) +endfunction() + +# Precompile python code in the specified directory relative to the +# CMake install prefix at install time. +# This must be called _after_ the install directive for the python code +# in the specified directory +function(precompile_python dir component) + find_package(Python3) + + if(NOT ${Python3_Interpreter_FOUND}) + message(STATUS "Could not find Python3, skipping precompilation of Python code.") + return() + endif() + + set(prefix [=[${CMAKE_INSTALL_PREFIX}]=]) + + install( + CODE "message(STATUS \"Precompiling Python3 code in ${prefix}/${dir}\")" + COMPONENT ${component} + ) + install( + CODE "execute_process(COMMAND ${Python3_Interpreter} -O -m compileall -j0 -o2 ${prefix}/${dir} WORKING_DIRECTORY ${prefix}/${dir})" + COMPONENT ${component} + ) +endfunction() |