Files
sunhpc-soft/cmake/DnfInstall.cmake
2026-06-14 23:45:57 +08:00

48 lines
1.3 KiB
CMake
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#
# dnf/yum 系统包安装通用模块
#
# 函数DNF 安装系统包
# 参数PKG_NAME - 包名
function(DnfInstall PKG_NAME)
CHECK_ROOT()
DEPLOY_MSG ("Start install system package: ${PKG_NAME}")
if(ENABLE_DEBUG)
execute_process(
COMMAND dnf install -y ${PKG_NAME}
RESULT_VARIABLE DNF_RET
OUTPUT_VARIABLE DNF_OUT
ERROR_VARIABLE DNF_ERR
)
message(STATUS "[Debug] Output: ${DNF_OUT}")
message(STATUS "[Debug] Errors: ${DNF_ERR}")
else()
execute_process(
COMMAND dnf install -y ${PKG_NAME}
RESULT_VARIABLE DNF_RET
OUTPUT_VARIABLE DNF_OUT
ERROR_VARIABLE DNF_ERR
)
set(DNF_ERR "")
endif()
if(NOT DNF_RET EQUAL 0)
message(FATAL_ERROR "Install ${PKG_NAME} failed: ${DNF_ERR}")
endif()
DEPLOY_MSG ("Install ${PKG_NAME} success")
endfunction()
# 函数DNF 卸载系统包
function(DnfRemove PKG_NAME)
CHECK_ROOT()
DEPLOY_MSG ("Start remove system package: ${PKG_NAME}")
execute_process(
COMMAND dnf remove -y ${PKG_NAME}
RESULT_VARIABLE DNF_RET
)
if(NOT DNF_RET EQUAL 0)
message(WARNING "Remove ${PKG_NAME} failed")
endif()
endfunction()