<div dir="ltr">To customize the build and install, I would suggest to use an install(TRAGET) wrapper for each target. It allows to define an option for each of them. <div><br></div><div>* The list of targets must be recorded in a global property.</div><div>* The install option is constructed using the target name</div><div>* call generate_install_config() after all targets to get a template that you can customize and use as cmake initial cache</div><div><br></div><div>You might be able to adapt this to your needs.</div><div><br></div><div>Cheers,</div><div><br></div><div>====</div><div><br></div><div><div>set_property(GLOBAL PROPERTY target_list)</div><div><br></div><div># add_install_option must be a macro, if put in a function, the option does</div><div># not exists right after being declared.</div><div>macro(add_install_option target)</div><div> string(TOUPPER ${target} TGT)</div><div> option(CONFIG_INSTALL_${TGT} "Install ${TGT}" ON)</div><div> get_property(tmp GLOBAL PROPERTY target_list)</div><div> list(APPEND tmp CONFIG_INSTALL_${TGT})</div><div> set_property(GLOBAL PROPERTY target_list ${tmp})</div><div>endmacro()</div><div><br></div><div>function(install_target_wrapper target)</div><div> add_install_option(${target})</div><div> if(CONFIG_INSTALL_${TGT})</div><div> # message("CONFIG_INSTALL_${TGT}=${CONFIG_INSTALL_${TGT}}")</div><div> install(TARGETS ${target}</div><div> RUNTIME DESTINATION bin</div><div> LIBRARY DESTINATION lib</div><div> COMPONENT application</div><div> )</div><div> endif()</div><div>endfunction()</div><div><br></div><div>function(generate_install_config)</div><div> set(CONF "${CMAKE_BINARY_DIR}/InstallConfig.cmake")</div><div> file(WRITE "${CONF}" "# Automatically generated install config file. Copy this file and edit to customize the installation.\n")</div><div> file(APPEND "${CONF}" "# Use to populate the initial cmake cache: cmake -C InstallConfigForCustomer.cmake\n")</div><div> file(APPEND "${CONF}" "# EDIT VARIABLES BELOW\n")</div><div> get_property(tmp GLOBAL PROPERTY target_list)</div><div> list(SORT tmp)</div><div> foreach(ITEM ${tmp})</div><div> file(APPEND ${CONF} "set(${ITEM}_VALUE ${${ITEM}})\n")</div><div> endforeach()</div><div> file(APPEND "${CONF}" "#\n# DO NOT EDIT BELOW\n#\n")</div><div> foreach(ITEM ${tmp})</div><div> file(APPEND ${CONF} "set(${ITEM} \${${ITEM}_VALUE} CACHE BOOL \"Install ${ITEM}\" FORCE)\n")</div><div> endforeach()</div><div> list(LENGTH tmp tmp_len)</div><div> message("-- Number of targets: ${tmp_len}")</div><div>endfunction()</div></div><div><br></div><div><br><div class="gmail_quote"><div dir="ltr">Le mer. 25 juil. 2018 à 02:09, Jason Heeris <<a href="mailto:jason.heeris@gmail.com">jason.heeris@gmail.com</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>My project consists of a lot of "module" style targets (static libraries, more or less), but only a few top-level targets that a user would actually want to build. The "all" target is empty, that is, every target has "EXCLUDE_FROM_ALL" set. The user will, at compile time, decide to build whichever target they need. A single target may depend on a couple of others, so the end result of a single target being built might be eg. an exe file plus a dll plus a couple of other things.<br></div><div><br></div><div>But I also want to provide installation capabilities, so users don't have to hunt down exes and libs scattered throughout CMake's build tree. I might want to create installers using CPack at some point too.</div><div><br></div><div>How do I do this if all of my targets are EXCLUDE_FROM_ALL? According to the documentation, even if I use the OPTIONAL flag in install(), the behaviour is undefined. Better not do that.</div><div><br></div><div>The only other option I see is to create custom commands (POST_BUILD style) for every target that copies it to some designated output directory. But then I can't take advantage of CMake's other installation capabilities, and I think that would be invisible to CPack.</div><div><br></div><div>Is there some other way?</div><div><br></div><div>I'm using CMake 3.12 on Windows 10/Ubuntu 18.04, if that's relevant.</div><div><br></div><div>Cheers,</div><div>Jason</div></div>
-- <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/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/support.html</a><br>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/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/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/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/listinfo/cmake</a><br>
</blockquote></div></div></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">Francis Giraldeau</div></div>