0

I want to build my project using libwebsockets with mbedtls. I have used FetchContent_Declare() and FetchContent_GetProperties() along with add_subdirectory() to pull in the repos and now I'm stuck in the configuration phase with the following errors:

CMake Error in build/_deps/libwebsockets-src/CMakeLists.txt:
  export called with target "websockets" which requires target "mbedtls" that
  is not in any export set.


CMake Error in build/_deps/libwebsockets-src/CMakeLists.txt:
  export called with target "websockets" which requires target "mbedcrypto"
  that is not in any export set.


CMake Error in build/_deps/libwebsockets-src/CMakeLists.txt:
  export called with target "websockets" which requires target "mbedx509"
  that is not in any export set.

I've had a look at the mbedtls code and confirmed that they in fact ARE in the MbedTLSTargets export set:

set(target_libraries ${mbedcrypto_target} ${mbedx509_target} ${mbedtls_target})
# ...
foreach(target IN LISTS target_libraries)
    # ...
    install(
        TARGETS ${target}
        EXPORT MbedTLSTargets
        ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
        LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
        RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
        PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
endforeach(target)

I don't understand how those export informations are not propagated to the upstream consumer (libwebsockets). Do I specifically have to redeclare the export rules for those targets in my main project?

glades
  • 3,778
  • 1
  • 12
  • 34
  • By default, mbedtls project disables installation if it is built as a subproject: https://github.com/Mbed-TLS/mbedtls/blob/development/CMakeLists.txt#L65. You may try to set option `DISABLE_PACKAGE_CONFIG_AND_INSTALL` to `ON` before you add this subproject with `add_subdirectory`. – Tsyvarev Nov 18 '22 at 10:04
  • @Tsyvarev I see. But why would anyone do that (as installing is optional anyway)? Is this good practice? – glades Nov 18 '22 at 12:50
  • Installing is optional but CMake generates `install` **rule unconditionally**: CMake doesn't know in advance, whether a user will run `make install` or not. See [recent question](https://stackoverflow.com/questions/74486677/cmake-failed-when-my-project-depends-on-both-gflags-and-glog) about the error which could be observed if installation of the subproject is not disabled when needed. – Tsyvarev Nov 18 '22 at 12:56
  • @Tsyvarev Interesting that looks like the exact problem that I'm having. So basically, if I use FetchContent to pull in mbedtls as non-IMPORTED target, I should create the export set for mbedtls myself? – glades Nov 18 '22 at 13:05
  • My example about the possible problems wasn't so good. Actually, CMake allows two dependent libraries to be installed via different export sets. So no, you don't need to create export set for mbedtls by yourself: all you need is to enable installation of `mbedtls` which was automatically disabled because of subproject. I am not sure whether `find_package(libwebsockets)` will correctly work from the installation of your project. But if you don't intend to use it in such way, you don't need to worry. Or you may disable installation of `websockets` project too (and do not enable it for mbedtls). – Tsyvarev Nov 18 '22 at 14:25
  • @Tsyvarev Thanks a lot. I just saw things are complicated even more as just now only the development branch of mbedtls does have export sets, whereas I want to use an LTS branch (2.19) which doesn't yet export. So libwebsockets pulling in the targets actually indirectly blocks configuration as it defines an export set only for its own targets. Maybe it's best to just disable the export in general like you said :/ – glades Nov 18 '22 at 14:39

0 Answers0