[CMake] Emulating --whole-archive with MSVC
Guillaume Dumont
dumont.guillaume at gmail.com
Mon May 2 11:03:52 EDT 2016
Hi,
I have been playing with the WINDOWS_EXPORT_ALL_SYMBOLS recently and found
the feature very useful. I reused part of the this functionality to emulate
the --whole-archive link flag with MSVC. Here is the process I used:
1. Use a POST_BUILD custom command to list the object files linked in the
static library (dumpbin /ARCHIVEMEMBERS mylib.lib and write this to a file.
2. Use a cmake script to call cmake -E __create_def and create a header
file with #pragma comment(linker, /include:"<symbol"> for every symbol in
the generated .def file.
3. Consuming projects including this header file when linking to mylib.lib
It seems that it would not be too hard to add this feature to cmake to that
it can be done via a target property similar to the
WINDOWS_EXPORT_ALL_SYMBOLS. For example:
1. WINDOWS_LINK_WHOLE_ARCHIVE is set on the library
2. CMake catches this and list all the object files into a file and calls
itself via cmake -E __create_whole_archive_rsp_file which creates a
response file containing a list of /INCLUDE:"<symbolname>"
3. CMake adds this response file to the INTERFACE_LINK_LIBRARIES of the
target so that consuming projects automatically link in all the symbols
defined in the library.
4. Then cmake would have the handle the installation of this response file,
etc.
See this for documentation of rsp files:
https://msdn.microsoft.com/en-us/library/9xch38h8.aspx
This would probably have the side effect of solving
https://cmake.org/Bug/view.php?id=13032 which is nice.
Most of this is already possible via cmake code but could be made much
easier if it was just a property to set on a target.
Would it be possible to implement such a feature in CMake?
Do you see any problem with the process mentionned above?
Is it currently possible to add a response file to the link line via
target_link_libraries or via target properties?
Thank you
--
Guillaume Dumont
=========================
dumont.guillaume at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20160502/7b3718d9/attachment-0001.html>
More information about the CMake
mailing list