Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Keep Cmake from generating or at least from installing the import library when building a shared library

The title pretty much already sums up my problem:
When creating a library with add_library(SHARED), cmake creates two files, the actual library (.so/.dll) and the import library (.a/.lib)

That, by itself, is not a problem.

But when I call install(TARGETS ${PROJECT_NAME} DESTINATION ${DeploymentFolder}), it also installs both files, the shared library and its import.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I only want the shared library to be installed, because they’re only being used as runtime libraries. They’re not supposed to be linked to anything but the executable also in the deployment folder.

Any ideas aside from using FILES to specify the name explicitly?

FWIW, the environment is a Qt installation on Windows.

>Solution :

CMake supports several kinds of artifacts which can be installed. By default, for a SHARED library on Windows both RUNTIME (.dll) and ARCHIVE (.lib) are selected (documentation). But you may explicitly specify which artifacts you need:

install(TARGETS ${PROJECT_NAME}
  RUNTIME # Installs only '.dll' part of the library
  DESTINATION ${DeploymentFolder})

If you want to support both Windows and Linux, you may specify RUNTIME and LIBRARY kinds: the latter one is for installing .so:

install(TARGETS ${PROJECT_NAME}
  RUNTIME # Installs only '.dll' part of the shared library on Windows
          # Does nothing for libraries on Linux
    DESTINATION ${DeploymentFolder}
  LIBRARY # Installs shared library on Linux
          # Does nothing for shared libraries on Windows
    DESTINATION ${DeploymentFolder})
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading