<div dir="ltr">Hi Saad:<div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 31, 2018 at 6:47 PM, Saad Khattak <span dir="ltr"><<a href="mailto:saadrustam@gmail.com" target="_blank">saadrustam@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Thanks J. I could use that to add preprocessor definitions. <div><br></div><div>However, my question was how I could forward 'all' the command line options that the user uses to generate the SuperBuild project. Suppose I somehow managed to capture all the command line arguments which can include variables specific to CMake and/or projects (i.e. nothing to do with preprocessor definitions) in a variable called CL_CMAKE_ARGS. </div></div></blockquote><div><br></div><div>The example you are using is close, but not quite correct.  </div><div><br></div><div>You need to harvest the comandline arguments before calling `project()`, just note that it won't work if CMakeCache.txt already exists.</div><div><br></div><div>Some CMAKE variables will still have HELPSTRINGS, even if passed via the command line, and users can also set a random or blank HELPSTRING if they use a cache file.  To overcome these issues, just harvest all cache variables and exclude the invariant ones, e.g., CMAKE_COMMAND, etc., e.g.:</div><div><br></div><div><div>$ cat ../CMakeLists.txt</div><div>cmake_minimum_required(VERSION 3.5)</div><div><br></div><div>message(STATUS "*** All CACHE_VARIABLES ***")</div><div>get_cmake_property(vars CACHE_VARIABLES)</div><div>foreach(var ${vars})</div><div>  get_property(currentHelpString CACHE "${var}" PROPERTY HELPSTRING)</div><div>        message("${var} = [${${var}}]  --  ${currentHelpString}")</div><div>endforeach()</div><div><br></div><div>project(xxx)</div><div>message(STATUS "project() called.")</div><div><br></div><div>message(STATUS "*** Only CACHE_VARIABLES with HELPSTRING empty or matching \"No help,...\" ***")</div><div>get_cmake_property(vars CACHE_VARIABLES)</div><div>foreach(var ${vars})</div><div>  get_property(currentHelpString CACHE "${var}" PROPERTY HELPSTRING)</div><div>        if("${currentHelpString}" MATCHES "No help, variable specified on the command line." OR "${currentHelpString}" STREQUAL "")</div><div>                message("${var} = [${${var}}]  --  ${currentHelpString}")</div><div>        endif()</div><div>endforeach()</div><div><br></div><div>$ rm -rf * && cmake -DFOO=1 -DCMAKE_BUILD_TYPE=Release -GNinja ..</div><div>-- *** All CACHE_VARIABLES ***</div><div>CMAKE_BUILD_TYPE = [Release]  --  No help, variable specified on the command line.</div><div>CMAKE_COMMAND = [/opt/local/bin/cmake]  --  Path to CMake executable.</div><div>CMAKE_CPACK_COMMAND = [/opt/local/bin/cpack]  --  Path to cpack program executable.</div><div>CMAKE_CTEST_COMMAND = [/opt/local/bin/ctest]  --  Path to ctest program executable.</div><div>CMAKE_EXTRA_GENERATOR = []  --  Name of external makefile project generator.</div><div>CMAKE_GENERATOR = [Ninja]  --  Name of generator.</div><div>CMAKE_GENERATOR_PLATFORM = []  --  Name of generator platform.</div><div>CMAKE_GENERATOR_TOOLSET = []  --  Name of generator toolset.</div><div>CMAKE_HOME_DIRECTORY = [/Users/dhinton/cmake_test]  --  Source directory with the top level CMakeLists.txt file for this project</div><div>CMAKE_ROOT = [/opt/local/share/cmake-3.10]  --  Path to CMake installation.</div><div>FOO = [1]  --  No help, variable specified on the command line.</div><div>-- The C compiler identification is AppleClang 9.0.0.9000039</div><div>-- The CXX compiler identification is AppleClang 9.0.0.9000039</div><div>-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc</div><div>-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -- works</div><div>-- Detecting C compiler ABI info</div><div>-- Detecting C compiler ABI info - done</div><div>-- Detecting C compile features</div><div>-- Detecting C compile features - done</div><div>-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++</div><div>-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -- works</div><div>-- Detecting CXX compiler ABI info</div><div>-- Detecting CXX compiler ABI info - done</div><div>-- Detecting CXX compile features</div><div>-- Detecting CXX compile features - done</div><div>-- project() called.</div><div>-- *** Only CACHE_VARIABLES with HELPSTRING empty or matching "No help,..." ***</div><div>FOO = [1]  --  No help, variable specified on the command line.</div><div>-- Configuring done</div><div>-- Generating done</div><div>-- Build files have been written to: /Users/dhinton/cmake_test/build</div></div><div><br></div><div>hth...</div><div>don</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><br></div><div>If I do message(${CL_CMAKE_ARGS}) I get:</div><div><br></div><div> -DMY_OPTION_ONE=ON -DMY_OPTION_TWO=OFF -DSOME_VAR_1="Foo"</div><div><br></div><div>Now, when I try something like this:</div><div><br></div><div>ExternalProject_Add(target</div><div>...</div><div>CMAKE_ARGS ${CL_CMAKE_ARGS}</div><div>...</div><div>)</div><div><br></div><div>One would expect CL_CMAKE_ARGS to be expanded and the arguments passed to the ExternalProject_Add function, but that is not the case. I also tried:</div><div><br></div><div><div>ExternalProject_Add(target</div><div>...</div><div>CMAKE_ARGS "${CL_CMAKE_ARGS}"</div><div>...</div><div>)</div></div><div><br></div><div>Neither works. It seems like a bug in CMake but I wanted to confirm that I am not missing something.</div><div><div class="gmail-h5"><div><br><div class="gmail_quote"><div dir="ltr">On Wed, Jan 31, 2018 at 3:27 PM J Decker <<a href="mailto:d3ck0r@gmail.com" target="_blank">d3ck0r@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><br></div><div>(platfrom defines is a variable suitable for like ADD_DEFINITIONS( ${PLATFORM_DEFINES} ) </div><div><br></div><div><br></div><div>  string( REPLACE ";" " " PLATFORM_DEFINES_ARG "${PLATFORM_DEFINES}" )</div><div><div>  ExternalProject_Add( target</div></div><div>    ....</div><div><div><span style="white-space:pre-wrap">    </span>CMAKE_ARGS -DPLATFORM_DEFINES=${PLATFORM_<wbr>DEFINES_ARG}</div></div><div>    ......</div><div> )</div><div><br></div><div><br></div><div>and in the target cmakelists to use the argument</div><div><br></div><div><br></div><div><div>STRING( REPLACE " " ";" PLATFORM_DEFINES ${PLATFORM_DEFINES} )</div><div><br></div><div>add_definitions( ${PLATFORM_DEFINES} )</div></div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote"></div></div><div class="gmail_extra"><div class="gmail_quote">On Wed, Jan 31, 2018 at 9:36 AM, Saad Khattak <span dir="ltr"><<a href="mailto:saadrustam@gmail.com" target="_blank">saadrustam@gmail.com</a>></span> wrote:<br></div></div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">I have the following setup:<div>Superbuild</div><div>   - ExternalProject_Add(a...)<br>   - ExternalProject_Add(b...)</div><div>   - ExternalProject_Add(c...) </div><div>   - ExternalProject_Add(d...)<br><br>The SuperBuild is built from command line with some options e.g. -DMY_OPTION=TRUE. I would like all these options to be passed to each of the ExternalProject_Add CMAKE_ARGS.</div><div><br></div><div>I tried to capture the arguments using the solution posted here: <a href="https://stackoverflow.com/a/10218582/368599" target="_blank">https://stackoverflow.<wbr>com/a/10218582/368599</a></div><div><br></div><div>The arguments are captured properly (i.e. I printed them out to make sure they are correct) but relaying them to ExternalProject_Add appears to be problematic. I tried the following ways to forward the arguments (as outlined in the stackoverflow solution):<br><br>ExternalProject_Add(...<br>  CMAKE_ARGS ${CMAKE_ARGS}<br>  )<br><br>ExternalProject_Add(...<br>  CMAKE_ARGS "${CMAKE_ARGS}" # quotes<br>  )</div><div><br></div><div>ExternalProject_Add(...<br>  CMAKE_ARGS "${MY_CMAKE_ARGS}" # changed the variable name in case it conflicts<br>  )  <br><br>None of that seems to work. CMake appears to ignore the commands forwarded.</div><div><br></div><div>Is there something I am missing?</div><div><br></div><div>Thanks,</div><div>Saad<br><br></div></div>
<br></blockquote></div></div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">--<br>
<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" rel="noreferrer" target="_blank">http://www.cmake.org/Wiki/<wbr>CMake_FAQ</a><br>
<br>
Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br>
<br>
CMake Support: <a href="http://cmake.org/cmake/help/support.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/<wbr>support.html</a><br>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/<wbr>consulting.html</a><br>
CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/<wbr>training.html</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/<wbr>opensource/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="https://cmake.org/mailman/listinfo/cmake" rel="noreferrer" target="_blank">https://cmake.org/mailman/<wbr>listinfo/cmake</a><br>
<br></blockquote></div><br></div>
</blockquote></div></div></div></div></div>
<br>--<br>
<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" rel="noreferrer" target="_blank">http://www.cmake.org/Wiki/<wbr>CMake_FAQ</a><br>
<br>
Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br>
<br>
CMake Support: <a href="http://cmake.org/cmake/help/support.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/<wbr>support.html</a><br>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/<wbr>consulting.html</a><br>
CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/<wbr>training.html</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/<wbr>opensource/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="https://cmake.org/mailman/listinfo/cmake" rel="noreferrer" target="_blank">https://cmake.org/mailman/<wbr>listinfo/cmake</a><br>
<br></blockquote></div><br></div></div>