CMake: Read build number from file to set a variable

前端 未结 2 2063
我寻月下人不归
我寻月下人不归 2021-01-04 01:58

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 numb

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-04 02:15

    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.

提交回复
热议问题