0

I'm trying to use mbedtls in my CMakelists.txt file. I used the vcpkg package manager to install mbedtls: vcpkg install mbedtls

I added my find_package() statement before add_executable() but despite adding -DCMAKE_TOOLCHAIN_FILE=/bin/vcpkg/scripts/buildsystems/vcpkg.cmake to my CLion CMake options, CLion does not find mbedtls.

CMakeLists.txt:

cmake_minimum_required(VERSION 3.22)
project(mbedtls_ssl_server)

set(CMAKE_CXX_STANDARD 20)

find_package(mbedtls REQUIRED)

add_executable(mbedtls_ssl_server
        main.cpp)

target_link_libraries(mbedtls_ssl_server mbedtls::mbedtls)

The error message is:

CMake Error at /bin/vcpkg/scripts/buildsystems/vcpkg.cmake:838 (_find_package):
  By not providing "Findmbedtls.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "mbedtls", but
  CMake did not find one.

  Could not find a package configuration file provided by "mbedtls" with any
  of the following names:

    mbedtlsConfig.cmake
    mbedtls-config.cmake

  Add the installation prefix of "mbedtls" to CMAKE_PREFIX_PATH or set
  "mbedtls_DIR" to a directory containing one of the above files.  If
  "mbedtls" provides a separate development package or SDK, be sure it has
  been installed.

I also tried running sudo apt install libmbedtls-dev on Ubuntu but that didn't help either, the previous error persists.

BullyWiiPlaza
  • 17,329
  • 10
  • 113
  • 185
  • It seems that vcpkg package for mbedtls still doesn't have a CMake configuration file, so the package cannot be searched with `find_package`: https://github.com/microsoft/vcpkg/issues/18356. The [libmbedtls-dev package](https://packages.ubuntu.com/kinetic/amd64/libmbedtls-dev/filelist) in Ubuntu misses that configuration file too (because it is based on 2.28.1 version of mbed TLS, but configuration file has been added only in 3.0). – Tsyvarev Dec 23 '22 at 19:39
  • @Tsyvarev: Thanks, that was insightful but quite unfortunate. Do you have any tips on how I could use this library anyway with `CMake`? I rather don't want to use `Makefiles` or so since that won't have as good of an IDE integration... – BullyWiiPlaza Dec 24 '22 at 09:21
  • You may install mbettls from sources, so that installation will have configuration file, which can be consumed by `find_package`. Alternatively, instead of find_package you could just specify proper include directories, which contains mbedtls header(s), and link with proper libraries. You could easily find these directories and libraries by inspecting which files are contained in your mbedtls installation. – Tsyvarev Dec 24 '22 at 19:28

1 Answers1

0

I had the same error and i had to set the variable MbedTLS_DIR in CMakelists.txt.

Exemple for MacOS:

set(MbedTLS_DIR /opt/homebrew/Cellar/mbedtls/3.3.0/cmake/) # <-- Here 
find_package(MbedTLS REQUIRED )
target_link_libraries(${target_lib} PUBLIC MbedTLS::mbedtls)

This point on folder that contain MbedTLSConfig.cmake

Thisora
  • 51
  • 4