Commit 678fa45b60202f64ad0fbc674d37ca56388981ae

Patrick Steinhardt 2018-06-15T11:34:04

Merge pull request #4678 from staticfloat/sf/mbedtls_linkage Link `mbedTLS` libraries in when `SHA1_BACKEND` == "mbedTLS"

diff --git a/.travis.yml b/.travis.yml
index 686041b..61edba1 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -58,12 +58,12 @@ matrix:
    - compiler: gcc
      env:
          MBEDTLS=1
-         OPTIONS="-DTHREADSAFE=ON -DCMAKE_BUILD_TYPE=Release -DUSE_HTTPS=mbedTLS -DMBEDTLS_ROOT_DIR=../deps/mbedtls"
+         OPTIONS="-DTHREADSAFE=ON -DCMAKE_BUILD_TYPE=Release -DUSE_HTTPS=mbedTLS -DSHA1_BACKEND=mbedTLS -DMBEDTLS_ROOT_DIR=../deps/mbedtls"
      os: linux
    - compiler: gcc
      env:
          MBEDTLS=1
-         OPTIONS="-DTHREADSAFE=OFF -DBUILD_EXAMPLES=ON -DUSE_HTTPS=mbedTLS -DMBEDTLS_ROOT_DIR=../deps/mbedtls"
+         OPTIONS="-DTHREADSAFE=OFF -DBUILD_EXAMPLES=ON -DUSE_HTTPS=mbedTLS -DSHA1_BACKEND=mbedTLS -DMBEDTLS_ROOT_DIR=../deps/mbedtls"
      os: linux
  allow_failures:
    - env: COVERITY=1
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 2b82bb3..2deed5f 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -284,8 +284,13 @@ ELSEIF(SHA1_BACKEND STREQUAL "CommonCrypto")
 ELSEIF (SHA1_BACKEND STREQUAL "mbedTLS")
 	ADD_FEATURE_INFO(SHA ON "using mbedTLS")
 	SET(GIT_SHA1_MBEDTLS 1)
-	FILE(GLOB SRC_SHA1 src/hash/hash_mbedtls.c)
-	LIST(APPEND LIBGIT2_PC_REQUIRES "mbedtls")
+	FILE(GLOB SRC_SHA1 hash/hash_mbedtls.c)
+	LIST(APPEND LIBGIT2_INCLUDES ${MBEDTLS_INCLUDE_DIR})
+	LIST(APPEND LIBGIT2_LIBS ${MBEDTLS_LIBRARIES})
+	# mbedTLS has no pkgconfig file, hence we can't require it
+	# https://github.com/ARMmbed/mbedtls/issues/228
+	# For now, pass its link flags as our own
+	LIST(APPEND LIBGIT2_PC_LIBS ${MBEDTLS_LIBRARIES})
 ELSE()
 	MESSAGE(FATAL_ERROR "Asked for unknown SHA1 backend ${SHA1_BACKEND}")
 ENDIF()