<div dir="ltr"><div><div>Hi Ryan.<br><br></div>If the only thing you need delay-loaded in this are the target names, you should just get rid of the variables and use the target names directly. The decision whether an argument of `target_link_libraries()` is a target or a library path is done at generate time, when all CMakeLists have been parsed and all target names are known.<br>
<br>However, if your example is just simplified and you need more than the name itself for linking (e.g. if you need to dereference a differnt variable set in the target's CMakeList, or get/set that tartget's properties), then I'm afraid you're out of luck in the general case. I was facing a similar setup at work: hundreds of projects randomly referencing each other, where trying to find an ordering of subdirectory inclusion just wasn't practically possible. In the end, I did something similar to your "master file" approach, but a bit more modular. I require each project to have a "project.cmake" file alongside its "CMakeLists.txt". The "project.cmake" file sets all the variables required by other projects. My master CMakeList then include()-s all these "project.cmake" files before executing any `add_subdirectory()` calls, so that all the variables are already set correctly when subprojects are processed.<br>
<br></div>If someone has a better way to do it, I'd love to hear it as well.<br><br>Petr<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, May 9, 2014 at 8:21 PM, Kawicki, Ryan H <span dir="ltr"><<a href="mailto:Ryan.H.Kawicki@boeing.com" target="_blank">Ryan.H.Kawicki@boeing.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div link="blue" vlink="purple" lang="EN-US">
<div>
<p class="MsoNormal"><span style="font-family:"Courier New"">I wonder if anyone else has come into this kind of situation.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">We are restructuring how some of our libraries are structured on disk to be more modular.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">Previously, we had all of the project names defined in a CMakeList.txt that then would call to add the subdirectories that are needed. This works fine, but with the new structure, we would like to
eliminate the need for this master file and just have the subdirectories define the name itself.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">The thing I was thinking of doing was just adding them to the cache file, but order may be important here.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">Here is a very simple example:<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">Master CMakeList:<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">cmake_minimum_required(VERSION 2.8)<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">project(test)<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">add_subdirectory(lib2)<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">add_subdirectory(lib)<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">add_subdirectory(exe)<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">lib2 CMakeList:<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">cmake_minimum_required(VERSION 2.8)<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">SET(PROJECT_LIB2 lib2 CACHE INTERNAL "lib2 project name")<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">add_library(${PROJECT_LIB2} SHARED file.cpp)<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">target_link_libraries(${PROJECT_LIB2} ${PROJECT_LIB})<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">lib CMakeList:<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">cmake_minimum_required(VERSION 2.8)<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">SET(PROJECT_LIB lib CACHE INTERNAL "lib project name")<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">add_library(${PROJECT_LIB} STATIC file.cpp)<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">exe CMakeList:<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">cmake_minimum_required(VERSION 2.8)<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">SET(PROJECT_EXE exe CACHE INTERNAL "exe project name")<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">add_executable(${PROJECT_EXE} file.cpp)<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">target_link_libraries(${PROJECT_EXE} ${PROJECT_LIB2})<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">In this simple example, lib is never seen by lib2 and added as a dependant because the cache entry has not yet been evaluated.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">I thought that there was first a configuration step to acquire all variables of and stuff them into the cache file and then the generation step would use these values to generate the file output,
but that is not happening as can be seen in the example above. I am using CMake 2.8.11.1 when conducting this test and generating a VS2010 project.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">During our restructuring efforts, we are making a full attempt at trying to not have these kind of situations come up, but we live in the real world and not an ideal world. Outside of using the –C
option or restructuring again, is there anything I can do to accomplish what I am trying to do? Is there a mechanism to delay reading from the cache until the configuration step has finished?<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">Thanks.<span class="HOEnZb"><font color="#888888"><u></u><u></u></font></span></span></p><span class="HOEnZb"><font color="#888888">
<p class="MsoNormal" style="text-autospace:none"><span style="font-family:"Courier New""><u></u> <u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-family:"Courier New"">Ryan H. Kawicki</span><span style="font-size:8.0pt;font-family:"Courier New""><u></u><u></u></span></p>
</font></span></div>
</div>
<br>--<br>
<br>
Powered by <a href="http://www.kitware.com" 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" target="_blank">http://www.cmake.org/Wiki/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" target="_blank">http://cmake.org/cmake/help/support.html</a><br>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" target="_blank">http://cmake.org/cmake/help/consulting.html</a><br>
CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" target="_blank">http://cmake.org/cmake/help/training.html</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.cmake.org/mailman/listinfo/cmake" target="_blank">http://www.cmake.org/mailman/listinfo/cmake</a><br></blockquote></div><br></div>