Hi,<br><br>I've been working on adding <Project>Config.cmake support to my CMake based projects, and just had a quick question regarding 'best practice' in writing<br>these when the project builds both dynamic and (optionally) static libraries, with clients of the project wishing to choose one or the other. <br>
<br>Thanks to the ProjectConfig tutorial on the Wiki :-), I've got the basic files for a test project 'mlvl' working nicely from the build and install trees. <br>By default, mlvl builds a dynamic library with a user option to additionally build a static version, hence the mlvlLibraryDepends.cmake files<br>
have the imported targets<br><br>mlvl<br>mlvl-static<br><br>though the mlvl-static target will only be present if the build static option was enabled. The relevant section of my <a href="http://mlvlConfig.cmake.in" target="_blank">mlvlConfig.cmake.in</a> file <br>
then contains<br>
<br><br>include("@mlvl_CMAKE_DIR@/mlvlLibraryDepends.cmake")<br><br>set(mlvl_LIBRARY mlvl)<br><br>set(mlvl_LIBRARY_STATIC "mlvl_LIBRARY_STATIC-NOTFOUND")<br>
if(TARGET mlvl-static)<br> set(mlvl_LIBRARY_STATIC mlvl-static)<br>endif()<br><br>if(mlvl_USE_STATIC)<br> if(mlvl_LIBRARY_STATIC)<br> set(mlvl_LIBRARIES ${mlvl_LIBRARY_STATIC})<br> else()<br> message(WARNING "no static build of mlvl available, falling back to use dynamic library")<br>
set(mlvl_LIBRARIES ${mlvl_LIBRARY})<br> endif()<br>else()<br> set(mlvl_LIBRARIES ${mlvl_LIBRARY})<br>endif()<br><br><br>where mlvl_USE_STATIC is a variable clients of mlvl can set before calling find_package. This seems to work o.k., but I'm a<br>
little unsure about:<br><br>a) if it looks reasonable, and within the scope of what a <NAME>Config.cmake script is supposed to do (my impression from reading the lists<br>is that they're supposed to be very simple...).<br>
<br>b) If a FATAL_ERROR could/should be issued if the client has requested use of the static library but the install of mlvl that's been found doesn't have it.<br><br>
Replacing message(WARNING ...) with message(FATAL_ERROR ...) does work, and I'm not sure if this should be done within the config script or<br>whether I should just leave it up to the client to decide what to do post the find_package call - it would seem within the spirit of module mode<br>
find_package to emit a FATAL_ERROR if both mlvl_USE_STATIC is set and find_package was called with REQUIRED...?<br><br>I realize I could make my life much easier by always building both libraries ;-), but I'm interested in the limits of what should be done in a ProjectConfig.cmake<br>
file versus how much responsibility to pass onto the user.. This seems to relate to previous discussions on this list about how to write config files for <br>projects with components or/and using external third-party packages, though I didn't find a definitive answer (apologies if I missed an obvious posting...).<br>
<br>Thanks,<br><br>Ben.<br><br>