<div dir="auto">And the situation is *far* worse on Windows where the extension for a dll import library is the same as for a static library because cmake refuses to try to move the needle on this awful 'defacto' decision with respect to msvc when it is exactly the sort of thing cmake should strive to take the lead on creating this new standard here, in cooperation and discussion with Microsoft (though for pure cmake based things it can be done without that). .dll.lib vs .lib being the obvious extensions here.<div dir="auto"><br></div><div dir="auto">FWIW mingw-w64 fixed this, and it was far from difficult. Here we use .dll.a and .a.</div><div dir="auto"><br></div><div dir="auto">I appeal to the CMake moderators to consider the damage this situation causes to the genericness and hygiene of CMakeList.txt files.</div></div><br><div class="gmail_quote"><div dir="ltr">On Sat, May 19, 2018, 2:00 PM Elvis Stansvik <<a href="mailto:elvis.stansvik@orexplore.com">elvis.stansvik@orexplore.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I know this has been asked before, but I've never seen a really<br>
authoritative answer.<br>
<br>
Say I have a simple single-library project.<br>
<br>
The advise I've seen is to not pass SHARED or STATIC to the<br>
add_library(..), but instead let the user pass<br>
-DBUILD_SHARED_LIBS:BOOL=ON/OFF to build the library as either shared<br>
or static.<br>
<br>
That's fine, but leads to packagers having to do ugly things like e.g:<br>
<br>
    <a href="https://salsa.debian.org/hle/dlib/blob/master/debian/rules" rel="noreferrer noreferrer" target="_blank">https://salsa.debian.org/hle/dlib/blob/master/debian/rules</a><br>
<br>
That is, do two separate configure/build/install, in order to get both<br>
a shared and static version. Note that the above was just an example.<br>
But many packagers do it like this.<br>
<br>
How can I make life easier for the packager?<br>
<br>
I could add a -DFOO_BUILD_SHARED_AND_STATIC_LIBS, and use two<br>
add_library(...), one with SHARED and one with STATIC, but the same<br>
input source files. I could give the two libraries different output<br>
filenames, as to not conflict on e.g. Windows (where I think the .lib<br>
import library containing symbols for the .dll would otherwise<br>
conflict with the static library .lib, or..?).<br>
<br>
To not have to repeat the list of sources, I could keep them in a<br>
variable. But that's not recommended in modern CMake AFAIK.<br>
<br>
I've also seen people add an object library, and then build the shared<br>
+ static lib from that.<br>
<br>
What are your thoughts on all this? How do you go about it? Do you use<br>
the recommended way, with a single add_library(..) and just let<br>
packagers put up with having to do two builds?<br>
<br>
Thanks in advance!<br>
Elvis<br>
-- <br>
<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer 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 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 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 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 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 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 noreferrer" target="_blank">https://cmake.org/mailman/listinfo/cmake</a><br>
</blockquote></div>