0

I'm trying to get different build subfolder using cmake that has the same name as the current branch (on windows 10). I've tried this

set branch=git rev-parse --abbrev-ref HEAD
cmake --build build\%branch% --config Release

but it doesn't evaluate before usage in cmake, it just dumps it there. This makes the whole approach futile because the following is not a valid cmake command:

cmake --build build\git rev-parse --abbrev-ref HEAD --config Release

Error info:

C:\Users\...\repos\proj_name>cmake --build build\%branch% --config Release
Unknown argument rev-parse
Unknown argument --abbrev-ref
Unknown argument HEAD
Usage: cmake --build <dir> [options] [-- [native-options]]

Is there another way to do this? I'm trying to avoid writing a script - which is the proposed solution linked as duplicate - because I need a oneliner. Switch branch and run the build in such a way that the build folder follows this structure build/branch-name/. Maybe cmake can do this internally, detect the git branch name and then specify the build folder?

Daniel
  • 980
  • 9
  • 20
  • Your `branch` variable does not get evaluated, it is simply set to `"git rev-parse --abbrev-ref HEAD"`, which is probably not what you want... – Kevin Nov 05 '19 at 14:15
  • @squareskittles Exactly, but I am not asking here for explicitly batch solution, I need any solution to do this by passing data to cmake or detecting somehow this data inside it. For that reason I wouldn't say this is a duplicate. – Daniel Nov 05 '19 at 20:30
  • "but it doesn't work" is not a useful description. What exactly is wrong (or not desired) with your approach? – Tsyvarev Nov 05 '19 at 21:13
  • 1
    When you say "*any solution*", the most straight-forward solution is to use the windows command line (i.e. batch) as is shown in the answers to the [linked question](https://stackoverflow.com/questions/108439/how-do-i-get-the-result-of-a-command-in-a-variable-in-windows). If you're looking for a more obtuse approach, or a solution for Linux, or a solution excluding the CMake command line tools, please specify (preferably with examples) *exactly* what constraints of the solution should be in your **question post**. – Kevin Nov 05 '19 at 22:53

0 Answers0