Hi,<br><br>I&#39;ve been working on adding &lt;Project&gt;Config.cmake support to my CMake based projects, and just had a quick question regarding &#39;best practice&#39; 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&#39;ve got the basic files for a test project &#39;mlvl&#39; 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(&quot;@mlvl_CMAKE_DIR@/mlvlLibraryDepends.cmake&quot;)<br><br>set(mlvl_LIBRARY mlvl)<br><br>set(mlvl_LIBRARY_STATIC &quot;mlvl_LIBRARY_STATIC-NOTFOUND&quot;)<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 &quot;no static build of mlvl available, falling back to use dynamic library&quot;)<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&#39;m a<br>

little unsure about:<br><br>a) if it looks reasonable, and within the scope of what a &lt;NAME&gt;Config.cmake script is supposed to do (my impression from reading the lists<br>is that they&#39;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&#39;s been found doesn&#39;t have it.<br><br>
Replacing message(WARNING ...) with message(FATAL_ERROR ...) does work, and I&#39;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&#39;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&#39;t find a definitive answer (apologies if I missed an obvious posting...).<br>
<br>Thanks,<br><br>Ben.<br><br>