Azure / azure-storage-cpplite

Lite version of C++ Client Library for Microsoft Azure Storage
MIT License
25 stars 43 forks source link

Fix cross-compilation workflow on Windows host with CMake #100

Closed pablorcum closed 3 years ago

pablorcum commented 3 years ago

I am cross-compiling the project on Windows, and had to make some changes in the main CMakeLists file, so that it works and also go around PkgConfig. Please find my fix proposal below.

Original

if (UNIX)
  option(USE_OPENSSL "Use OpenSSL instead of GnuTLS" ON)
  if(USE_OPENSSL)
    target_compile_definitions(azure-storage-lite PRIVATE -DUSE_OPENSSL)
    set(OPENSSL_ROOT_DIR ${OPENSSL_ROOT_DIR} /usr/local/opt/openssl)
    find_package(OpenSSL REQUIRED)
    list(APPEND EXTRA_LIBRARIES OpenSSL::SSL OpenSSL::Crypto)
  else()
    find_package(GnuTLS REQUIRED)
    list(APPEND EXTRA_INCLUDE_DIRS ${GNUTLS_INCLUDE_DIR})
    list(APPEND EXTRA_LIBRARIES ${GNUTLS_LIBRARIES})
  endif()

  if(NOT APPLE)
    find_package(PkgConfig REQUIRED)
    pkg_check_modules(uuid REQUIRED IMPORTED_TARGET uuid)
    list(APPEND EXTRA_LIBRARIES PkgConfig::uuid)
  endif()
elseif(WIN32)
  list(APPEND EXTRA_LIBRARIES rpcrt4 bcrypt)
  target_compile_definitions(azure-storage-lite PRIVATE azure_storage_lite_EXPORTS NOMINMAX)
endif()

Fix

if(WIN32)
  list(APPEND EXTRA_LIBRARIES rpcrt4 bcrypt)
  target_compile_definitions(azure-storage-lite PRIVATE azure_storage_lite_EXPORTS NOMINMAX)
else()
  option(USE_OPENSSL "Use OpenSSL instead of GnuTLS" ON)
  if(USE_OPENSSL)
    target_compile_definitions(azure-storage-lite PRIVATE -DUSE_OPENSSL)
    set(OPENSSL_ROOT_DIR ${OPENSSL_ROOT_DIR} /usr/local/opt/openssl)
    find_package(OpenSSL REQUIRED)
    list(APPEND EXTRA_LIBRARIES OpenSSL::SSL OpenSSL::Crypto)
  else()
    find_package(GnuTLS REQUIRED)
    list(APPEND EXTRA_INCLUDE_DIRS ${GNUTLS_INCLUDE_DIR})
    list(APPEND EXTRA_LIBRARIES ${GNUTLS_LIBRARIES})
  endif()

  if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
    find_package(PkgConfig REQUIRED)
    pkg_check_modules(uuid REQUIRED IMPORTED_TARGET uuid)
    list(APPEND EXTRA_LIBRARIES PkgConfig::uuid)
  endif()
endif()
pablorcum commented 3 years ago

Fixed at #101 .

pablorcum commented 3 years ago

Figured out it is related to this more generic CMake issue. This pull request can be cancelled.