<div dir="ltr">I ended up using this exact approach with addition of one top level Makefile which is used to run cmake in build folder. Top level Makefile takes those arguments and passes them down to the cmake execution, which than makes a decision on which way to go depending on the argument passed in.<div><br></div><div>Here is how that part looks like:</div><div>BUILD_DIR   :=  build</div><div><div><br></div><div>ifneq ($(ENV),)</div><div>DEPLOY=$(ENV)</div><div>endif</div></div><div><br></div><div>ifeq "$(DEPLOY)" "V1"<br></div><div><div><div>NEW_FLAG=-DVERSION_1=ON</div><div>else<br></div><div>ifeq "$(DEPLOY)" "V2"</div><div>NEW_FLAG = -DVERSION_2=ON</div><div>else<br></div><div>ifeq "$(DEPLOY)" "V3"</div><div>NEW_FLAG = -DVERSION_3=ON</div><div>endif<br></div><div>endif</div><div>endif</div></div><div><br></div><div>all: ${BUILD_DIR}/Makefile</div><div><span class="" style="white-space:pre"> </span>$(MAKE) -C ${BUILD_DIR}</div><div><br></div><div>cmake:</div><div><span class="" style="white-space:pre">      </span>touch CMakeLists.txt</div><div><span class="" style="white-space:pre">       </span>$(MAKE) ${BUILD_DIR}/Makefile</div><div><br></div><div>${BUILD_DIR}/Makefile:</div><div><span class="" style="white-space:pre">        </span>@[ -d ${BUILD_DIR} ] || mkdir -p ${BUILD_DIR}</div><div><span class="" style="white-space:pre">      </span>@[ -f ${BUILD_DIR}/Makefile ] || (cd ${BUILD_DIR} && cmake $(NEW_FLAG) ..)</div><div><span class="" style="white-space:pre"> </span>touch $@</div><div><br></div><div><br></div><div>I have also created three options (needed three in my case) that create #defines for each of them and depending on which is initialized at the start, ends up being enabled in the source code.</div><div><br></div><div>The issue that I had at the end was to clean cached values of those since regular clean wasn't clearing #define that was previously set. At the end I am running "make clean"  in build folder, following with delete of build/CMakeCache.txt and build/Makefile. After that new option passed in to the top level Makefile does what I need (initialize proper #define that is).</div><div><br></div><div>Here is how the clean section looks like in the top level Makefile:<br><div>.PHONY : clean</div><div>clean:</div><div><span class="" style="white-space:pre">        </span>@- [ -f ${BUILD_DIR}/Makefile ] && $(MAKE) --silent -C ${BUILD_DIR} clean || true</div><div><span class="" style="white-space:pre">  </span>@- [ -f ${BUILD_DIR}/CMakeCache.txt ] && rm ${BUILD_DIR}/CMakeCache.txt || true</div><div><span class="" style="white-space:pre">    </span>@- [ -f ${BUILD_DIR}/Makefile ] && rm -rf ${BUILD_DIR}/Makefile || true</div></div><div><br></div><div><br></div><div>If there is a better way to clear the cache so I don't have to delete those two files, I would like someone to point it.<br><div><br></div></div><div>Thanks for help and hope this will be useful for someone else in the future!</div></div><div><br></div><div>Any other comments on this are welcome!</div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Apr 5, 2016 at 4:36 AM, Matějů Miroslav, Ing. <span dir="ltr"><<a href="mailto:Mateju.Miroslav@azd.cz" target="_blank">Mateju.Miroslav@azd.cz</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">





<div lang="CS" link="blue" vlink="purple">
<div>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Hi Fedja,<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">As far as I know, the Makefiles generated  from CMake cannot contain decisions. CMake supports several output types aside from Makefiles and some
 of them probably don’t support decisions. However, you could supply these arguments within CMake call using -D option. For example<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11pt;font-family:'Courier New';color:rgb(31,73,125)">    cmake -DENV=VERSION_2 <source_or_binary_directory><u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">creates a CMake variable just like<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11pt;font-family:'Courier New';color:rgb(31,73,125)">    set(ENV "VERSION_2" CACHE)<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">in the CMake source file.<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">As you’ve mentioned already, you can access environment variables using
</span><span lang="EN-US" style="font-size:11pt;font-family:'Courier New';color:rgb(31,73,125)">$ENV{variable}</span><span lang="EN-US" style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"> syntax in CMake.<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Hope this helps.<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Miroslav<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<div style="border-style:none none none solid;border-left-color:blue;border-left-width:1.5pt;padding:0cm 0cm 0cm 4pt">
<div>
<div style="border-style:solid none none;border-top-color:rgb(181,196,223);border-top-width:1pt;padding:3pt 0cm 0cm">
<p class="MsoNormal"><b><span style="font-size:10pt;font-family:Tahoma,sans-serif">From:</span></b><span style="font-size:10pt;font-family:Tahoma,sans-serif"> CMake [mailto:<a href="mailto:cmake-bounces@cmake.org" target="_blank">cmake-bounces@cmake.org</a>]
<b>On Behalf Of </b>Fedja Jeleskovic<br>
<b>Sent:</b> Friday, April 01, 2016 8:08 PM<br>
<b>To:</b> <a href="mailto:cmake@cmake.org" target="_blank">cmake@cmake.org</a><br>
<b>Subject:</b> [CMake] Parsing command line arguments from the make<u></u><u></u></span></p>
</div>
</div><div><div class="h5">
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal">Since I am converting existing makefile project to use cmake instead I need to accept values that come from command line which looks like this:<br>
VARIABLE_NAME="/home/user/project" make ENV=VERSION_2<u></u><u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">First one is used like this:<u></u><u></u></p>
</div>
<div>
<div>
<p class="MsoNormal">include $(VARIABLE_NAME)/Makefile.include<u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Second one has this code that triggers different paths later:<br>
ifneq ($(ENV),)<u></u><u></u></p>
</div>
<div>
<div>
<p class="MsoNormal">DEPLOYMENT_VERSION=$(ENV)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">endif<u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">How do I do this in cmake?<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Thanks!<u></u><u></u></p>
</div>
</div>
</div></div></div>
</div>
</div>

</blockquote></div><br></div></div>