nng: The new findMbedTLS from NNG 1.7.2 fails

Describe the bug The improvements to cmake in NNG 1.7.2 prevent MbedTLS being found.

Actual Behavior The final lines when running cmake do not appear for me on Ubuntu 22.04:

-- Looking for mbedtls_ssl_init
-- Looking for mbedtls_ssl_init - found
Mbed TLS version: 3.5.2
-- Found MbedTLS: MbedTLS::mbedtls  
-- Configuring done

Tested with: (i) apt installed MbedTLS 2.28 in /usr and (ii) MbedTLS 3.5.2 installed in /usr/local Both are not picked up.

This causes the library to be built without TLS support.

To Reproduce However it works again if I simplify this part in src/supplemental/tls/mbedtls/CMakeLists.txt:

    # If Mbed TLS was added by a consuming project, then we should use that
    # instance of it, instead of configuring our own.
    if (TARGET mbedtls)
        nng_link_libraries(mbedtls)
    else()
        # We want to prefer config mode over our local find package.
        # mbedTLS v3 has a config file, which should work better than
        # what we do here.  We do restore the setting though because
        # user applications might not expect this.
        if (NOT CMAKE_FIND_PAKCAGE_PREFER_CONFIG)
            set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE)
            find_package(MbedTLS REQUIRED)
            set(CMAKE_FIND_PACKAGE_PREFER_CONFIG FALSE)
        else()
            find_package(MbedTLS REQUIRED)
        endif()
        nng_link_libraries_public(MbedTLS::mbedtls MbedTLS::mbedcrypto MbedTLS::mbedx509)
    endif()

to this:

    # If Mbed TLS was added by a consuming project, then we should use that
    # instance of it, instead of configuring our own.
    if (TARGET mbedtls)
        nng_link_libraries(mbedtls)
    else()
        find_package(MbedTLS REQUIRED)
        nng_link_libraries_public(MbedTLS::mbedtls MbedTLS::mbedcrypto MbedTLS::mbedx509)
    endif()

I have no idea what CMAKE_FIND_PACKAGE_PREFER_CONFIG is meant for, but perhaps it can be reverted if not important.

Note that there is actually a typo in one of the places where it appears above, but that is not causing this bug.

** Environment Details **

  • NNG version 1.7.2
  • Ubuntu 22.04.3
  • gcc 11.4.0
  • Static lib
  • CMake 3.22.1

About this issue

  • Original URL
  • State: closed
  • Created 5 months ago
  • Comments: 24 (24 by maintainers)

Commits related to this issue

Most upvoted comments

(You can now use -DCMAKE_FIND_PACKAGE_PREFER_CONFIG=ON (or OFF) as you like.