Santz
Santz

Reputation: 7

How to check the Software version invoked by cmake

I am invoking a software from CMAKE to generate required files for build.Is it possible to print the version of software invoked in the build window..?

Upvotes: 0

Views: 1176

Answers (1)

Leherenn
Leherenn

Reputation: 540

As said in the comments, the exact way to output the version will depend on the executable itself.
Lets assume it is <executable> --version.

Then it CMake it will look like:

find_program(EXECUTABLE_RUNTIME <executable>)
if ("${EXECUTABLE_RUNTIME}" STREQUAL "EXECUTABLE_RUNTIME-NOTFOUND")
  message(FATAL_ERROR "<executable> runtime could not be found!")
else()
  execute_process(COMMAND "${EXECUTABLE_RUNTIME}" --version
                  OUTPUT_VARIABLE EXECUTABLE_VERSION
                  OUTPUT_STRIP_TRAILING_WHITESPACE)
  message(STATUS "Found <executable> runtime at ${EXECUTABLE_VERSION}, version ${EXECUTABLE_VERSION}")
endif()

A possible footgun is to include the command arguments in the quotes (e.g. "${EXECUTABLE_RUNTIME} --version", if you do this the output variable will be empty.
OUTPUT_STRIP_TRAILING_WHITESPACE will remove the new line which is very often present after the version.

Upvotes: 1

Related Questions