The convention in MSVC-land seems to be to prefix (as well as suffix) static 
libraries with lib. E.g. the static CRT is libcmt.lib, the static VC runtime 
support library is libvcruntime.lib (whereas the import library for the dynamic 
equivalent is vcruntime.lib), and so on. It isn't necessarily the greatest 
scheme, but it does provide some distinction, at least.

From: CMake <cmake-boun...@cmake.org> on behalf of Ray Donnelly 
<mingw.andr...@gmail.com>
Date: Saturday, May 19, 2018 at 6:10 AM
To: Elvis Stansvik <elvis.stans...@orexplore.com>
Cc: CMake MailingList <cmake@cmake.org>
Subject: Re: [CMake] Approach to both shared and static lib (again, sorry)

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.

FWIW mingw-w64 fixed this, and it was far from difficult. Here we use .dll.a 
and .a.

I appeal to the CMake moderators to consider the damage this situation causes 
to the genericness and hygiene of CMakeList.txt files.

On Sat, May 19, 2018, 2:00 PM Elvis Stansvik 
<elvis.stans...@orexplore.com<mailto:elvis.stans...@orexplore.com>> wrote:
I know this has been asked before, but I've never seen a really
authoritative answer.

Say I have a simple single-library project.

The advise I've seen is to not pass SHARED or STATIC to the
add_library(..), but instead let the user pass
-DBUILD_SHARED_LIBS:BOOL=ON/OFF to build the library as either shared
or static.

That's fine, but leads to packagers having to do ugly things like e.g:

    
https://salsa.debian.org/hle/dlib/blob/master/debian/rules<https://urldefense.proofpoint.com/v2/url?u=https-3A__salsa.debian.org_hle_dlib_blob_master_debian_rules&d=DwMFaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=bmBNxLvBJFPYO0Kd1_VsRIXq2zQXfPQBW72q5lBMPlo&s=R7JQmKVI2oxy-AIQVcBC-DX-dqlkBFk5kTCI222ecO8&e=>

That is, do two separate configure/build/install, in order to get both
a shared and static version. Note that the above was just an example.
But many packagers do it like this.

How can I make life easier for the packager?

I could add a -DFOO_BUILD_SHARED_AND_STATIC_LIBS, and use two
add_library(...), one with SHARED and one with STATIC, but the same
input source files. I could give the two libraries different output
filenames, as to not conflict on e.g. Windows (where I think the .lib
import library containing symbols for the .dll would otherwise
conflict with the static library .lib, or..?).

To not have to repeat the list of sources, I could keep them in a
variable. But that's not recommended in modern CMake AFAIK.

I've also seen people add an object library, and then build the shared
+ static lib from that.

What are your thoughts on all this? How do you go about it? Do you use
the recommended way, with a single add_library(..) and just let
packagers put up with having to do two builds?

Thanks in advance!
Elvis
--

Powered by 
www.kitware.com<https://urldefense.proofpoint.com/v2/url?u=http-3A__www.kitware.com&d=DwMFaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=bmBNxLvBJFPYO0Kd1_VsRIXq2zQXfPQBW72q5lBMPlo&s=V3mYr9Flf9Qf-Pq-_OovKbzrwVWhpIOrjcCHuYvbszk&e=>

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ<https://urldefense.proofpoint.com/v2/url?u=http-3A__www.cmake.org_Wiki_CMake-5FFAQ&d=DwMFaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=bmBNxLvBJFPYO0Kd1_VsRIXq2zQXfPQBW72q5lBMPlo&s=sX26SQZVFYfGdhl4S0nVhXQDQ6eq_MhGXOy06ZAW9KQ&e=>

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: 
http://cmake.org/cmake/help/support.html<https://urldefense.proofpoint.com/v2/url?u=http-3A__cmake.org_cmake_help_support.html&d=DwMFaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=bmBNxLvBJFPYO0Kd1_VsRIXq2zQXfPQBW72q5lBMPlo&s=BWvA9Izw2G-XbRvZi9ptVgljjbJtkoRi_P7RuctYyTk&e=>
CMake Consulting: 
http://cmake.org/cmake/help/consulting.html<https://urldefense.proofpoint.com/v2/url?u=http-3A__cmake.org_cmake_help_consulting.html&d=DwMFaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=bmBNxLvBJFPYO0Kd1_VsRIXq2zQXfPQBW72q5lBMPlo&s=ouA_QmMRSZ16piM4G5xCtdJwt7Sz4fx_anknDStubYU&e=>
CMake Training Courses: 
http://cmake.org/cmake/help/training.html<https://urldefense.proofpoint.com/v2/url?u=http-3A__cmake.org_cmake_help_training.html&d=DwMFaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=bmBNxLvBJFPYO0Kd1_VsRIXq2zQXfPQBW72q5lBMPlo&s=qR0yZSqjFyaVr1xJpwSmtk28b-sMXtWDoM_URvLQs7A&e=>

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html<https://urldefense.proofpoint.com/v2/url?u=http-3A__www.kitware.com_opensource_opensource.html&d=DwMFaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=bmBNxLvBJFPYO0Kd1_VsRIXq2zQXfPQBW72q5lBMPlo&s=m2pcWM0TtqESkDz4KmjlV9a1VwfRPD2XaiR3Motzbxg&e=>

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake<https://urldefense.proofpoint.com/v2/url?u=https-3A__cmake.org_mailman_listinfo_cmake&d=DwMFaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=bmBNxLvBJFPYO0Kd1_VsRIXq2zQXfPQBW72q5lBMPlo&s=_fvbzMfoMh-elt7ju2Fetz2OTx7Z4TmCHGf7D6C4htE&e=>
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake

Reply via email to