Use of Visual C++ /WHOLEARCHIVE linker option

We build ~30 DLL & EXE files with Visual C++. They use a number of static libraries in turn. I thought of temporarily using the linker option /WHOLEARCHIVE to get an extra check that all dependencies among CMake targets are correctly setup (our code can contain just now “unused” files with incorrect dependencies, that are normally not triggered, or detected). So I want to (temporarily) pretend that all our code is used from the point of the linker.

My problem is with the option /WHOLEARCHIVE:

  • if given without argument it applies to all libraries (even Miscrosofts own “system libraries”). This always give errors in those libraries, not related to our code.
  • if given with several arguments like /WHOLEARCHIVE:libname , then each link command line seem to require specifying the exact set of our libraries used for that linking. And that list of libraries only CMake knowns (often via transitive dependencies).

I can’t find any simple solution to this. And wonder if I miss some way of doing this in CMake.