使用QMake检查可执行文件是否在路径中



我在*.pro文件中有一个自定义构建目标:

docs.commands = doxygen $$PWD/../docs/Doxyfile
QMAKE_EXTRA_TARGETS += docs
POST_TARGETDEPS += docs

作为后构建事件运行Doxygen。问题是,如果某人构建项目并且尚未安装doxygen,则构建失败。是否可以检查是否在构建项目的计算机上安装了doxygen,以便仅在安装doxygen并添加到系统PATH

时才能运行doxygen命令。

使用qmake,您可以尝试以下方法:

DOXYGEN_BIN = $$system(which doxygen)
isEmpty(DOXYGEN_BIN) {
        message("Doxygen not found")
}

另一个选项可能是以下一个:

DOXYGEN_BIN = $$system( echo $$(PATH) | grep doxygen )
isEmpty(DOXYGEN_BIN) {
        message("Doxygen not found")
}

btw,如果您使用的是cmake

您可以使用

实现这一目标
find_package(Doxygen)

示例:

FIND_PACKAGE(Doxygen)
if (NOT DOXYGEN_FOUND)
    message(FATAL_ERROR "Doxygen is needed to build the documentation.")
endif()

您在此网站中有更多信息:

http://www.cmake.org/cmake/help/v3.0/module/finddoxygen.html

在您的.pro文件上尝试一下:

# Check if Doxygen is installed on the default Windows location
win32 {
    exists( "C:Program Filesdoxygenbindoxygen.exe" ) {
        message( "Doxygen exists")
        # execute your logic here
    }
}
# same idea for Mac
macx {
    exists( "/Applications/doxygen.app/ ... " ) {
        message( "Doxygen exists")
    }
}

update

使用@tarod答案您可以使其与以下

兼容
# Check if Doxygen is installed on Windows (tested on Win7)
win32 {
    DOXYGEN_BIN = $$system(where doxygen)
    isEmpty(DOXYGEN_BIN) {
        message("Doxygen not found")
        # execute your logic here
    } else {
        message("Doxygen exists in " $$DOXYGEN_BIN)
    }
}
# Check if Doxygen is installed on Linux or Mac (tested on Ubuntu, not yet on the Mac)
unix|max {
    DOXYGEN_BIN = $$system(which doxygen)
    isEmpty(DOXYGEN_BIN) {
        message("Doxygen not found")
        # execute your logic here
    } else {
        message("Doxygen exists in " $$DOXYGEN_BIN)
    }
}

qt文档说:

在运行QMAKE时获得环境价值的内容,请使用$$(...)操作员...

即:

PATH_VAR = $$(PATH)
DOXYGEN = "doxygen"
contains(PATH_VAR, DOXYGEN) {
    message("Doxygen found")
}

相关内容

  • 没有找到相关文章

最新更新