[CMake] How can I compile and link modular code into a single DLL with MSVC?

Innokentiy Alaytsev alaitsev at gmail.com
Wed Jun 27 01:00:04 EDT 2018


Hello!

First of all, a side note:


Jason Heeris wrote
> (Not shown: the macros to create the declspec declaration that MSVC needs
> to know what to export in the DLL. It's a type in moduleN and some
> functions in common.)

Do you create declspec declaration by hand? It may worth looking at the 
GenerateExportHeader
<https://cmake.org/cmake/help/v3.7/module/GenerateExportHeader.html>   CMake
module that provides the function generate_export_header(). If you need to
generate some additional macros you can use CUSTOM_CONTENT_FROM_VARIABLE
argument that is supported since CMake 3.7.

Now, let me clarify something:



Jason Heeris wrote
> This is already possible with existing build scripts, but these are
> becoming unmaintainable. The existing scripts compile each individual
> module into an .obj file and finally link them all into a DLL, as in:
> 
> cl.exe [args] common\common.c (creates common.obj)
> cl.exe [args] modules\module1\module1.c (creates module1.obj)
> ...
> cl.exe [args] modules\moduleN\ moduleN.c (creates moduleN.obj)
> 
> link.exe [args] common.obj module1.obj [...] moduleN.obj (creates
> moduleN.dll)

Is it the code that you use in your CMake build script or just a
representation of the general idea?

Best regards,
Innokentiy Alaytsev




--
Sent from: http://cmake.3232098.n2.nabble.com/


More information about the CMake mailing list