0

Consider the following: I have a project which depends on libwebsockets which is itself dependends on mbedtls. I pull everything in from github using FetchContent, which establishes the dependencies in the build folder (_deps).

folder structure of said project

As I want to build everything statically, I thought I might do libwebsockets a favor and setup CMAKE_PREFIX_PATH so that its find_path() calls will find mbedtls, so libwebsockets knows the path to mbedtls and can see its include files. At the same time I have set cache variables that libwebsockets uses in its find_library() calls variables to the targets in mbedtls, so they are always found even at configure time. More specifically, this is what libwebsocket does:

find_path(LWS_MBEDTLS_INCLUDE_DIRS mbedtls/ssl.h)
        
find_library(MBEDTLS_LIBRARY mbedtls)
find_library(MBEDX509_LIBRARY mbedx509)
find_library(MBEDCRYPTO_LIBRARY mbedcrypto)

So libwebsockets finds mbedtls in the build directory, everything good so far, but then I get this nasty error still at configure time:

CMake Error in build/_deps/libwebsockets-src/lib/CMakeLists.txt:
  Target "websockets" INTERFACE_INCLUDE_DIRECTORIES property contains path:

    "C:/dev/realtime-cpp/build/_deps/mbedtls-build/include"

  which is prefixed in the build directory.

There are similar errors for the other targets. I understand that the include files are in the build directory. However I don't understand why this is a problem and what I should do instead?

glades
  • 3,778
  • 1
  • 12
  • 34
  • "I understand that the include files are in the build directory. However I don't understand why this is a problem" - The meaning of the error message is already described in [that question](https://stackoverflow.com/questions/25676277). You assign targets to `MBED*_LIBRARY` variables, but what have you assigned to `LWS_MBEDTLS_INCLUDE_DIRS` variable, which should contain the path? Assuming this variable will be used in `target_include_directories` command, you could try to assign expression of BUILD_INTERFACE and INSTALL_INTERFACE, described in the referenced question. – Tsyvarev Nov 18 '22 at 21:36
  • @Tsyvarev Said path is indeed included using include_directories() later. With my approach above I would set CMAKE_PREFIX_PATH to the local mbedtls dependency in my project folder, causing LWS_MBEDTLS_INCLUDE_DIRS to pick up that path via `find_path(LWS_MBEDTLS_INCLUDE_DIRS mbedtls/ssl.h)`. As you said this doesn't work because it doesnt add the necessary differentiation between build and install interface for include_directories(). I tried to set the cache var `LWS_MBEDTLS_INCLUDE_DIRS` myself, but I couldn't figure out how to shove generator expressions in them as they come out empty? – glades Nov 19 '22 at 11:24

0 Answers0