diff options
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 c6a13309..0c1d803e 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() |