Alex Rivera | Logout

CMake: Read build number from file to set a variable

Asked 2011-04-20T22:34:39.903
21

I'm working on a project where the build number is stored in a file called 'BuildNumber.txt' at the root of the project. What I'd like to do is have CMake read the number from this file and set a variable that can be applied to a header file.

setup.h.in

#define build_number "@BUILD_NUMBER@";

Using configure_file, it's possible to replace placeholders in an .in file like above with a CMake variable. Is it possible to get CMake to read in the number from BuildNumber.txt into a variable?

Edit
Report

1 Answer

3

I don't know your OS, but I assune that you are using Windows or Linux.

if (UNIX)
  set (show_contents_prog cat)
elseif (WIN32)
  set (show_contents_prog type)
endif (WIN32)

execute_process(COMMAND ${show_contents_prog} input.txt OUTPUT_VARIABLE file_contents)

I think this may help.

answered 2011-04-21T04:23:26.800

Your Answer