Skip to content

Commit

Permalink
fix: added workaround mbedtls and clang-cl incomatibility (#441)
Browse files Browse the repository at this point in the history
* fix: added workaround by replacing CMAKE_C_COMPILER_ID with CMAKE_C_SIMULATE_ID when configuring mbedtls

* chore: reworked comment and removed references to xwin
  • Loading branch information
daantimmer authored Oct 23, 2023
1 parent 2c87dfb commit 063b595
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions external/crypto/mbedtls/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,28 @@ set(ENABLE_TESTING Off CACHE INTERNAL "")
set(ENABLE_PROGRAMS Off CACHE INTERNAL "")
set(GEN_FILES Off CACHE INTERNAL "")

# mbedtls uses CMAKE_C_COMPILER_ID to determine the type of compiler used.
# When compiling with clang-cl, mbedtls thinks the clang compiler
# is used, and sets flags according to what clang expects as arguments.
# However, clang-cl expects MSVC like arguments. Therefore we have to trick mbedtls
# in to thinking MSVC is being used as a compiler.
# After making mbedtls available the original COMPILER_ID will be restored
set(ORIGINAL_C_COMPILER_ID ${CMAKE_C_COMPILER_ID})
set(ORIGINAL_CXX_COMPILER_ID ${CMAKE_CXX_COMPILER_ID})

if (CMAKE_C_SIMULATE_ID)
set(CMAKE_C_COMPILER_ID ${CMAKE_C_SIMULATE_ID})
endif()

if (CMAKE_CXX_SIMULATE_ID)
set(CMAKE_CXX_COMPILER_ID ${CMAKE_CXX_SIMULATE_ID})
endif()

FetchContent_MakeAvailable(mbedtls)

set(CMAKE_C_COMPILER_ID ${ORIGINAL_C_COMPILER_ID})
set(CMAKE_CXX_COMPILER_ID ${ORIGINAL_CXX_COMPILER_ID})

function(add_mbedtls_target_properties)
foreach(target ${ARGN})
target_compile_options(${target} PUBLIC
Expand Down

0 comments on commit 063b595

Please sign in to comment.