diff Aws/CMakeLists.txt @ 26:471eaf5c5d39

USE_VCPKG_PACKAGES to avoid using vcpkg
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 07 Sep 2020 16:00:59 +0200
parents 319d41a22de4
children 318c1442d9bd
line wrap: on
line diff
--- a/Aws/CMakeLists.txt	Mon Sep 07 14:26:50 2020 +0200
+++ b/Aws/CMakeLists.txt	Mon Sep 07 16:00:59 2020 +0200
@@ -10,6 +10,7 @@
 
 set(ORTHANC_FRAMEWORK_SOURCE "hg" CACHE STRING "orthanc source")
 set(ORTHANC_FRAMEWORK_VERSION "1.7.3" CACHE STRING "orthanc framework version")
+set(USE_VCPKG_PACKAGES ON CACHE BOOL "Use vcpkg to link against crypto++ and AWS SDK")
 set(ALLOW_DOWNLOADS ON)
 
 # Download and setup the Orthanc framework
@@ -41,10 +42,60 @@
   )
 
 
-find_package(cryptopp CONFIG REQUIRED)
-find_package(AWSSDK REQUIRED COMPONENTS s3)
+if (USE_VCPKG_PACKAGES)
+  find_package(cryptopp CONFIG REQUIRED)
+  find_package(AWSSDK REQUIRED COMPONENTS s3)
+  include_directories(${WASTORAGE_INCLUDE_DIR})
+  set(CRYPTOPP_LIBRARIES cryptopp-static)
+else()
+  ##
+  ## Inclusion of system-wide crypto++
+  ##
+  check_include_file_cxx(cryptopp/cryptlib.h HAVE_CRYPTOPP_H)
+  if (NOT HAVE_CRYPTOPP_H)
+    message(FATAL_ERROR "Please install the libcrypto++-dev package")
+  endif()
+
+  include(CheckCXXSymbolExists)
+  set(CMAKE_REQUIRED_LIBRARIES cryptopp)
+  check_cxx_symbol_exists("CryptoPP::SHA1::InitState" cryptopp/sha.h HAVE_LIBCRYPTOPP)
+  if (NOT HAVE_LIBCRYPTOPP)
+    message(FATAL_ERROR "Unable to find the cryptopp library")
+  endif()
+
+  set(CRYPTOPP_LIBRARIES cryptopp)
 
-include_directories(${WASTORAGE_INCLUDE_DIR})
+  ##
+  ## Building the C++ SDK for Amazon AWS
+  ## WARNING: This is *not* compatible with Ninja (yet)
+  ##
+  include(ExternalProject)
+  externalproject_add(AwsSdkCpp
+    GIT_REPOSITORY https://github.com/aws/aws-sdk-cpp
+    GIT_TAG 1.8.42
+
+    CMAKE_ARGS
+    -DBUILD_ONLY=s3   #-DBUILD_ONLY=s3;transfer
+    -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
+    -DENABLE_TESTING=OFF
+
+    UPDATE_COMMAND ""    # Don't run "cmake" on AWS each time "make/ninja" is run
+    INSTALL_COMMAND ""   # No install
+    )
+
+  ExternalProject_Get_Property(AwsSdkCpp SOURCE_DIR)
+  include_directories(
+    ${SOURCE_DIR}/aws-cpp-sdk-core/include/
+    ${SOURCE_DIR}/aws-cpp-sdk-s3/include/
+    )
+
+  ExternalProject_Get_Property(AwsSdkCpp BINARY_DIR)
+  set(AWSSDK_LINK_LIBRARIES
+    ${BINARY_DIR}/aws-cpp-sdk-core/libaws-cpp-sdk-core.so
+    ${BINARY_DIR}/aws-cpp-sdk-s3/libaws-cpp-sdk-s3.so
+    )
+endif()
+
 
 set(COMMON_SOURCES
     ${CMAKE_SOURCE_DIR}/../Common/IStoragePlugin.h
@@ -65,7 +116,7 @@
     ${CMAKE_SOURCE_DIR}/../Common/StoragePlugin.cpp
 
     ${COMMON_SOURCES}
-  )
+    )
 
 set_target_properties(OrthancAwsS3Storage PROPERTIES
   VERSION ${PLUGIN_VERSION}
@@ -74,7 +125,7 @@
 
 target_link_libraries(OrthancAwsS3Storage
   PRIVATE
-  cryptopp-static
+  ${CRYPTOPP_LIBRARIES}
   ${AWSSDK_LINK_LIBRARIES}
   )
 
@@ -90,7 +141,13 @@
 
 target_link_libraries(UnitTests
   PRIVATE
-  cryptopp-static
   ${GOOGLE_TEST_LIBRARIES}
+  ${CRYPTOPP_LIBRARIES}
   ${AWSSDK_LINK_LIBRARIES}
   )
+
+
+if (NOT USE_VCPKG_PACKAGES)
+  add_dependencies(OrthancAwsS3Storage AwsSdkCpp)
+  add_dependencies(UnitTests AwsSdkCpp)
+endif()