CMake: Read build number from file to set a variable

筅森魡賤 提交于 2019-11-30 17:31:59
sakra

You can use the CMake command file (STRINGS ...) for that purpose. Assuming the build number is located in the file BuildNumber.txt in a single line, the following command will read it into the CMake variable BUILD_NUMBER:

file (STRINGS "BuildNumber.txt" BUILD_NUMBER)

Also see the file command reference.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!