Search code examples
qtqt5doxygenqmake

Check if executable is in the PATH using qmake


I have a custom build target in my *.pro file:

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

QMAKE_EXTRA_TARGETS += docs
POST_TARGETDEPS += docs

which runs Doxygen as a post build event. The problem is, if someone builds the project and hasn't installed doxygen the build fails. Is it possible to check whether or not doxygen is installed on the machine that builds the project so that I run the doxygen command only if doxygen is installed and added to the system PATH?


Solution

  • With qmake, you can try this:

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

    Another option could be the following one:

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

    BTW, if you are using CMake

    You can achieve that using

    find_package(Doxygen)
    

    Example:

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

    You have more information in this site:

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