libcoap icon indicating copy to clipboard operation
libcoap copied to clipboard

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

Open franzhollerer opened this issue 3 years ago • 5 comments

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

franzhollerer avatar Sep 15 '21 13:09 franzhollerer

Can you please check if this patch works for you?

obgm avatar Sep 16 '21 13:09 obgm

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 avatar Sep 17 '21 05:09 franzhollerer

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.

franzhollerer avatar Sep 17 '21 05:09 franzhollerer

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.)

obgm avatar Sep 17 '21 08:09 obgm

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.

mrdeep1 avatar Sep 19 '21 15:09 mrdeep1