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

Create and install libcoap-3.pc when building with cmake #748

Open
franzhollerer opened this issue Sep 15, 2021 · 5 comments
Open

Create and install libcoap-3.pc when building with cmake #748

franzhollerer opened this issue Sep 15, 2021 · 5 comments

Comments

@franzhollerer
Copy link

I built and installed libcoap v4.3.0 with cmake. Then I tried to compile libcoap-minimal. I found that the Makefile in libcoap-minimal uses pkg-config to locate the library. Unfortunately, this failed because the cmake based build did not install the necessary .pc file.

It seems that libcoap-3.pc is only provided when building with autoconf.

Feature request: Please also create and install libcoap-3.pc when building with cmake.

Used versions:

  • libcoap, tag v4.3.0
  • libcoap-minimal, commit hash: 4d9c992
@obgm
Copy link
Owner

obgm commented Sep 16, 2021

Can you please check if this patch works for you?

@franzhollerer
Copy link
Author

The patch works partly. Now cmake installs a libcoap-3.pc into /usr/local/lib/pkgconfig, and its content basically looks fine. But when I compile libcoap-minimum I get several errors.

g++ -std=c++14 -Wall -Wextra -I/usr/local/include   client.o common.o  -L/usr/local/lib -lcoap-3 -o client
/usr/bin/ld: /usr/local/lib/libcoap-3.a(coap_openssl.c.o): in function `sk_SSL_CIPHER_num':
/usr/include/openssl/ssl.h:958: undefined reference to `OPENSSL_sk_num'
/usr/bin/ld: /usr/local/lib/libcoap-3.a(coap_openssl.c.o): in function `sk_SSL_CIPHER_value':
.
.

Here is difference between libcoap-3.pc generated with autoconf, and that one generated with cmake.

$ diff libcoap-3.pc.autoconf libcoap-3.pc.cmake 
3,4c3,4
< libdir=${exec_prefix}/lib
< includedir=${prefix}/include
---
> libdir=/usr/local/lib
> includedir=/usr/local/include
10,12c10,12
< Libs: -L${libdir} -lcoap-3-openssl
< Libs.private: -lssl -lcrypto
< Cflags: -I${includedir}
---
> Libs: -L/usr/local/lib -lcoap-3
> Libs.private: 
> Cflags: -I/usr/local/include

I think the reason that the libcaop-minimum build fails is because that out-of-the box the cmake based build only generates the static library libcoap-3.a (at least in my setup), while the autoconf also generates libcoap-3-openssl.a and shared libraries.

Anyway, its absolutely not a show stopper for me. I think its just a feature which would be nice to have.

@franzhollerer
Copy link
Author

Just to be noted. I found an open feature request in the cmake community addressing this topic.

https://gitlab.kitware.com/cmake/cmake/-/issues/22621

Eventually, future versions of cmake will have a built in support for pkg-config file generation.

@obgm
Copy link
Owner

obgm commented Sep 17, 2021

Thanks for the feedback. There are several reasons to think of why this has failed in your tests. I will try to track this down.

(The main issue here is not generating the .pc file but populating it properly—the CMakeLists.txt as it is is more like "get it to compile somehow" but less than optimal for proper packaging.)

@mrdeep1
Copy link
Collaborator

mrdeep1 commented Sep 19, 2021

There are several things at play here. With this libcoap-3.pc fix and cmake -DBUILD_SHARED_LIBS=ON , everything works as expected for libcoap-minimal. Then for autoconf with ./configure --disable-shared, libcoap-minimal builds also fail. A built library .so file works fine (the needed TLS libraries are somehow automatically found), but a library .a file does not as the libcoap-3.pc does not contain enough information.

Fixing the built libcoap-3.pc to include the required TLS libraries on the Libs: line (not the Libs.private: line) works fine for me in my initial tests for autoconf and cmake.

However, with tinydtls TLS library and cmake there still are issues as cmake does not install the libtinydtls.{so|a}, but autoconf does, so libcoap-minimal still cannot link when using cmake.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants