使用qmake检查可执行文件是否在PATH中

时间:2015-05-11 08:17:10

标签: qt qt5 doxygen qmake

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

docs.commands = doxygen $$PWD/../docs/Doxyfile

QMAKE_EXTRA_TARGETS += docs
POST_TARGETDEPS += docs

Doxygen作为后期构建事件运行。问题是,如果有人构建项目但尚未安装doxygen,则构建失败。是否可以检查构建项目的计算机上是否安装了doxygen,以便仅在doxygen安装并添加到系统{{1}时才运行doxygen命令}}?

3 个答案:

答案 0 :(得分:5)

使用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")
}

顺便说一下,如果您使用的是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

答案 1 :(得分:2)

在你的.pro文件上试试这个:

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

<强>更新

使用@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)
    }
}

答案 2 :(得分:1)

Qt docs说:

  

要在运行qmake时获取环境值的内容,请使用$$(...)运算符...

即:

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