0

I want to create a .dll library with all its dependencies packed inside the .dll.

However, there seems to be no easy way to achieve that with Cmake. My setup:

cmake_minimum_required(VERSION 3.0.0)
project(Main VERSION 0.1.0)

add_library(Main SHARED Main.cpp)

find_package(libzippp REQUIRED)

target_link_libraries(Main PRIVATE libzippp::libzippp) 

This will produce both Main.dll but also libzippp.dll.

I would like to have libzippp.dll packed (statically linked) into Main.dll.

Ford O.
  • 1,394
  • 8
  • 25
  • 2
    "I would like to have `libzippp.dll` packed (statically linked) into `Main.dll`." - You cannot. It is not restriction of CMake itself, but it is a restriction of `.dll` format which doesn't support merging such files into the one of the same format. See e.g. [that question](https://stackoverflow.com/questions/3595937/combine-multiple-dlls-into-1). – Tsyvarev Sep 16 '22 at 13:52

1 Answers1

1

Of course you can't pack one DLL into another. You have to make libzippp a static library in the first place. To do this, build libzippp with BUILD_SHARED_LIBS set to NO at the CMake command line. Then libzippp::libzippp will be a static library when you go to find_package it.

This is easy enough to show steps for:

$ git clone git@github.com:ctabin/libzippp.git
$ cmake -S libzippp -B build -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=NO -DCMAKE_INSTALL_PREFIX=$PWD/local -DLIBZIPPP_BUILD_TESTS=NO
$ cmake --build build --target install
$ tree local
local/
├── include
│   └── libzippp
│       └── libzippp.h
├── lib
│   └── libzippp_static.a
└── share
    └── libzippp
        ├── FindLIBZIP.cmake
        ├── libzipppConfig.cmake
        ├── libzipppConfigVersion.cmake
        ├── libzipppTargets.cmake
        └── libzipppTargets-release.cmake
Alex Reinking
  • 16,724
  • 5
  • 52
  • 86
  • I am using `vcpkg.json` to manage the packages. Is there a way to make it download / build static packages on its own? – Ford O. Sep 16 '22 at 14:55
  • 1
    @FordO. Use a `static` target triple like `x64-windows-static`. If you're using the toolchain file in manifest mode, it should be enough to set `-DVCPKG_TARGET_TRIPLET=x64-windows-static` at the CMake command line. – Alex Reinking Sep 16 '22 at 14:56
  • Nice. I have added `set(VCPKG_TARGET_TRIPLET x86-windows-static)` at the top of my cmake. – Ford O. Sep 17 '22 at 07:24