Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help! Using MbedTLS as a CMake library in my CMake project #7967

Open
JeremyTubongbanua opened this issue Jul 20, 2023 · 2 comments
Open

Help! Using MbedTLS as a CMake library in my CMake project #7967

JeremyTubongbanua opened this issue Jul 20, 2023 · 2 comments
Labels
component-platform Portability layer and build scripts help-wanted This issue is not being actively worked on, but PRs welcome. priority-low Low priority - this may not receive review soon

Comments

@JeremyTubongbanua
Copy link

Summary

Not sure if this is a bug, but I can't get this to work:

set(MbedTLS_DIR ${CMAKE_SOURCE_DIR}/deps/mbedtls/cmake)
find_package(MbedTLS REQUIRED)
target_link_libraries(main PUBLIC MbedTLS::mbedcrypto MbedTLS::mbedtls MbedTLS::mbedx509)
target_include_directories(main PUBLIC ${CMAKE_SOURCE_DIR}/deps/mbedtls/include)

I currently have the mbedtls repo as a git submodule in deps/mbedtls

This is what I run and the error I get:

jeremytubongbanua@Jeremys-M2-Air my_c_sockets % sudo cmake -S . -B build
Password:
CMake Error at CMakeLists.txt:14 (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.


-- Configuring incomplete, errors occurred!
See also "/Users/jeremytubongbanua/GitHub/my_c_sockets/build/CMakeFiles/CMakeOutput.log".
See also "/Users/jeremytubongbanua/GitHub/my_c_sockets/build/CMakeFiles/CMakeError.log".

Am I doing this right?

System information

Mbed TLS version (number or commit id):
Operating system and version: Mac Sanoma 14.0 - M2 Air (Apple Silicon)
Configuration (if not default, please attach mbedtls_config.h):
Compiler and options (if you used a pre-built binary, please indicate how you obtained it):
Additional environment information:

Expected behavior

Actual behavior

Steps to reproduce

Additional information

My full CMakeLists.txt

cmake_minimum_required(VERSION 3.19)

project(my_c_sockets)

add_executable(main src/main.c)

target_include_directories(main PUBLIC ${CMAKE_SOURCE_DIR}/include)

# add_subdirectory(${CMAKE_SOURCE_DIR}/deps/mbedtls)
# target_include_directories(main PUBLIC ${CMAKE_SOURCE_DIR}/deps/mbedtls/include)
# target_link_libraries(main PUBLIC mbedcrypto mbedtls mbedx509)

set(MbedTLS_DIR ${CMAKE_SOURCE_DIR}/deps/mbedtls/cmake)
find_package(MbedTLS REQUIRED)
target_link_libraries(main PUBLIC MbedTLS::mbedcrypto MbedTLS::mbedtls MbedTLS::mbedx509)
target_include_directories(main PUBLIC ${CMAKE_SOURCE_DIR}/deps/mbedtls/include)

install(
    TARGETS main
    DESTINATION ${CMAKE_SOURCE_DIR}/bin
)

This works, however:

add_subdirectory(${CMAKE_SOURCE_DIR}/deps/mbedtls)
target_include_directories(main PUBLIC ${CMAKE_SOURCE_DIR}/deps/mbedtls/include)
target_link_libraries(main PUBLIC mbedcrypto mbedtls mbedx509)
@JeremyTubongbanua JeremyTubongbanua changed the title Using MbedTLS as a CMake library in my CMake project Help! Using MbedTLS as a CMake library in my CMake project Jul 20, 2023
@paul-elliott-arm
Copy link
Member

paul-elliott-arm commented Jul 21, 2023

Hi!

What is your issue with the working version at the end?

We don't currently support the use of find_package(), and this is not something we are currently likely to add, however would welcome a patch that did.

@paul-elliott-arm paul-elliott-arm added component-platform Portability layer and build scripts needs-info An issue or PR which needs further info from the reporter / author labels Jul 25, 2023
@JeremyTubongbanua
Copy link
Author

Hi!

What is your issue with the working version at the end?

We don't currently support the use of find_package(), and this is not something we are currently likely to add, however would welcome a patch that did.

Thank you.. my current solution achieves what I need (using MbedTLS as a dependency in my project).

Just putting this ticket out there in case somebody else is trying to use find_package. It's in the root README but it doesn't work. Would you like a PR removing that documentation @paul-elliott-arm ?

Otherwise, feel free to do what you want with this ticket :)

@gilles-peskine-arm gilles-peskine-arm added help-wanted This issue is not being actively worked on, but PRs welcome. priority-low Low priority - this may not receive review soon and removed needs-info An issue or PR which needs further info from the reporter / author labels Jul 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component-platform Portability layer and build scripts help-wanted This issue is not being actively worked on, but PRs welcome. priority-low Low priority - this may not receive review soon
Projects
Status: No status
Development

No branches or pull requests

3 participants