From 23bfd43a16b56d881b1d236c285993a1eadd766e Mon Sep 17 00:00:00 2001 From: Jan Osusky Date: Fri, 3 Nov 2017 19:35:47 +0100 Subject: [PATCH] Fix cross-compilation and MSVC build with OpenSSL When building for multiple platforms I encountered several issues. Fist of all MSVC (Windows) build with TLS support through OpenSSL requires additional library "crypt32". Secondly, detection of pthread library failed when a cross-compiler was used (target platform is not identical to source/build platform). The "FIND_PACKAGE(Threads)" works fine but "FIND_LIBRARY(...)" either fails or finds pthread library for the wrong platform. It seems to methat presence of "CMAKE_THREAD_LIBS_INIT" which is set by the "FIND_PACKAGE(Threads)" test is a sufficiently reliable to use it to set "VMIME_HAVE_PTHREAD" but I must admit that this is not really my cup of coffee :-) --- CMakeLists.txt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 18f5f7ac..d2d75fc0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -678,6 +678,10 @@ IF(VMIME_HAVE_TLS_SUPPORT) ) ENDIF() + IF(WIN32) + SET(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CXX_STANDARD_LIBRARIES} crypt32.lib") + ENDIF() + SET(VMIME_PKGCONFIG_REQUIRES "${VMIME_PKGCONFIG_REQUIRES} openssl") SET(VMIME_TLS_SUPPORT_LIB_IS_GNUTLS "OFF") @@ -958,9 +962,9 @@ IF(VMIME_BUILD_SHARED_LIBRARY) ) ENDIF() -FIND_LIBRARY(PTHREAD_LIB pthread) +#FIND_LIBRARY(PTHREAD_LIB pthread) -IF(PTHREAD_LIB) +IF(CMAKE_THREAD_LIBS_INIT) SET(VMIME_HAVE_PTHREAD 1) IF(VMIME_BUILD_SHARED_LIBRARY) @@ -1007,6 +1011,9 @@ IF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") #SET(CMAKE_EXE_LINKER_FLAGS "-s") ELSE() + IF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /EHsc") + ENDIF() IF(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)