Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have an option to install either static or dynamic library #685

Closed
Marwan-imverse opened this issue Jul 20, 2022 · 11 comments · Fixed by #1287
Closed

Have an option to install either static or dynamic library #685

Marwan-imverse opened this issue Jul 20, 2022 · 11 comments · Fixed by #1287
Labels
enhancement New feature or request

Comments

@Marwan-imverse
Copy link

It would be great to have the option to install either the static or the dynamic library version.

Since there are two different CMake targets, it's already possible to build either one, but the install target automatically builds both, we have no choice.

@paullouisageneau
Copy link
Owner

The install target should only build and install the dynamic library, not the static ones. Are you sure it builds both for you?

@Marwan-imverse
Copy link
Author

I misspoke at the end of my first comment. If I choose to "install" after I built the static library, it builds and installs the dynamic library, which is not what I'd like. The install target should either install the dynamic or the static library, depending on how the project was generated with CMake.

@paullouisageneau
Copy link
Owner

OK I see. I think a preliminary step for this would be to bundle the static libraries of submodules into the static library of libdatachannel.

@paullouisageneau paullouisageneau added the enhancement New feature or request label Jul 26, 2022
@Marwan-imverse
Copy link
Author

Great, thanks! I'll keep an eye on this

@ClayJay3
Copy link

@paullouisageneau I think this is still an issue, has any development been made? I'm currently able to build the static library just fine with make datachannel-static, but then running either make install or make install datachannel-static doesn't install the library statically, but instead dynamically.

I suppose I could manually copy everything needed for the static install, but I wanted to check if there's an 'official' way to do this.

@ClayJay3
Copy link

ClayJay3 commented Nov 12, 2024

I got the library to statically install with

cmake \
    -D USE_GNUTLS=0 -D USE_NICE=0 \
    -D BUILD_SHARED_LIBS=OFF \
    -D CMAKE_BUILD_TYPE=Release ..

Then, the normal make install will work.

However, it still seems stuff is broken, when I try to include the library in my project with find_package() I get this:
image

@paullouisageneau
Copy link
Owner

@ClayJay3 The libraries are installed but I guess that for CMake to find installed dependencies, you also need to add them to the CMake export set. It should be fixed with #1287

@ClayJay3
Copy link

I checked out to cmake-add-install-deps-export and it seems to have fixed the issue with the make install command ignore that I want it to install the static libs, and I can go manually check /usr/local/lib/libdatachannel.a and it exists. however it seems like the install library is still broken :(

When I add the library to my project with find_package() like this:
image
image
It gives me this:
image
Switching the link library to LibDataChannel instead of LibDataChannelStatic seems to find the library (is LibDataChannelStatic still relavant?), but complains about OpenSSL for some reason:
image

For reference, this is how I'm building and installing libdatachannel:

# Download LibDataChannel
    git clone --recurse-submodules --depth 1 --branch cmake-add-install-deps-export https://github.com/paullouisageneau/libdatachannel.git libdatachannel
    mkdir libdatachannel/build
    cd libdatachannel/build

    # Build LibDataChannel
    cmake \
    -D USE_GNUTLS=0 -D USE_NICE=0 \
    -D BUILD_SHARED_LIBS=OFF \
    -D CMAKE_BUILD_TYPE=Release ..

    # Install LibDataChannel
    make datachannel-static
    make install datachannel-static

@ClayJay3
Copy link

Forgot to mention that trying

## Find LibDataChannel
find_package(LibDataChannel-Static REQUIRED)

Does not find anything either.

@paullouisageneau
Copy link
Owner

The change introduced in #1274 makes the LibDataChannel default target obey the CMake flag BUILD_SHARED_LIBS, so you can now build it statically and install it.

The LibDataChannelStatic target is still not installable, because CMake doesn't support optionally installing a configured target. Don't try to install it.

You simply have to run:

$ mkdir libdatachannel/build
$ cd libdatachannel/build
$ cmake -D USE_GNUTLS=0 -D BUILD_SHARED_LIBS=OFF -D CMAKE_BUILD_TYPE=Release ..
$ make
$ make install

Then you can import it with:

find_package(OpenSSL REQUIRED)
find_package(LibDataChannel REQUIRED)
[...]
target_link_libraries(${EXE_NAME} PRIVATE LibDataChannel::LibDataChannel)

You have to provide the same OpenSSL version as during the build since static libraries are linked only when linking the executable.

@ClayJay3
Copy link

#1287 seems to have fixed my issue with the static build. I think this issue can be closed once that PR is merged.

@paullouisageneau paullouisageneau linked a pull request Nov 17, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants