summaryrefslogtreecommitdiff
path: root/cmake/aws_sdk.cmake
blob: 975a3fa68883cac45ed4114520304141d3077451 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
MACRO (SKIP_AWS_SDK MSG)
  SET(${RETVAL} OFF PARENT_SCOPE)
  SET(${REASON} ${MSG} PARENT_SCOPE)
  RETURN()
ENDMACRO()

FUNCTION (CHECK_AWS_SDK RETVAL REASON)
  # AWS_SDK_EXTERNAL_PROJECT must be ON
  IF(NOT AWS_SDK_EXTERNAL_PROJECT)
    SKIP_AWS_SDK("AWS_SDK_EXTERNAL_PROJECT is not ON")
  ENDIF()
  # Check compiler support
  IF(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
    EXECUTE_PROCESS(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
    IF (GCC_VERSION VERSION_LESS 4.8)
      SKIP_AWS_SDK("GCC VERSION too old (${GCC_VERSION}, required is 4.8 or later")
    ENDIF()
  ELSEIF (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
    IF ((CMAKE_CXX_COMPILER_VERSION AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS  3.3) OR
        (CLANG_VERSION_STRING AND CLANG_VERSION_STRING VERSION_LESS  3.3))
      SKIP_AWS_SDK("Clang version too old, required is 3.3 or later")
    ENDIF()
  ELSEIF(MSVC)
    IF (MSVC_VERSION LESS 1800)
      SKIP_AWS_SDK("MSVC version too old, required is VS2015 or later")
    ENDIF()
  ELSE()
    SKIP_AWS_SDK("Unsupported compiler")
  ENDIF()

  # Check OS support
  IF (NOT(WIN32 OR APPLE  OR (CMAKE_SYSTEM_NAME MATCHES "Linux")))
    SKIP_AWS_SDK("OS unsupported by AWS SDK")
  ENDIF()
  
  # Build from source, using ExternalProject_Add
  # AWS C++ SDK requires cmake 2.8.12
  IF(CMAKE_VERSION VERSION_LESS "2.8.12")
    SKIP_AWS_SDK("CMake is too old")
  ENDIF()

  IF(UNIX)
    # Check librairies required for building SDK
    FIND_PACKAGE(CURL)
    IF(NOT CURL_FOUND)
      SKIP_AWS_SDK("AWS C++ SDK requires libcurl development package")
    ENDIF()
    FIND_PATH(UUID_INCLUDE_DIR uuid/uuid.h)
    IF(NOT UUID_INCLUDE_DIR)
      SKIP_AWS_SDK("AWS C++ SDK requires uuid development package")
    ENDIF()
    IF(NOT APPLE)
      FIND_LIBRARY(UUID_LIBRARIES uuid)
      IF(NOT UUID_LIBRARIES)
        SKIP_AWS_SDK("AWS C++ SDK requires uuid development package")
      ENDIF()
      FIND_PACKAGE(OpenSSL)
      IF(NOT OPENSSL_FOUND)
        SKIP_AWS_SDK("AWS C++ SDK requires openssl development package")
      ENDIF()
    ENDIF()
  ENDIF()
  SET(${RETVAL} ON PARENT_SCOPE)
ENDFUNCTION()


# USE_AWS_SDK_LIBS(target sdk_component1 ... sdk_component_N)
# Example usage
# USE_AWS_SDK_LIBS(aws_key_management kms s3)
FUNCTION(USE_AWS_SDK_LIBS)
  SET(SDK_COMPONENTS ${ARGN})
  LIST(GET SDK_COMPONENTS 0 target)
  IF(NOT TARGET ${target})
    MESSAGE(FATAL_ERROR "${target} is not a valid target")
  ENDIF()
  LIST(REMOVE_AT SDK_COMPONENTS 0)
  FOREACH(comp ${SDK_COMPONENTS})
    SET_PROPERTY(GLOBAL PROPERTY AWS_SDK_LIBS ${comp} APPEND)
    TARGET_LINK_LIBRARIES(${target} aws-cpp-sdk-${comp})
  ENDFOREACH()
  TARGET_LINK_LIBRARIES(${target} aws-cpp-sdk-core)
  TARGET_INCLUDE_DIRECTORIES(${target} PRIVATE ${PROJECT_BINARY_DIR}/aws_sdk/aws_sdk_cpp/include)
  # Link OS libraries that AWS SDK depends on
  IF(WIN32)
    TARGET_LINK_LIBRARIES(${target} bcrypt winhttp wininet userenv version)
  ELSE()
    FIND_PACKAGE(CURL REQUIRED)
    FIND_PACKAGE(OpenSSL REQUIRED)
    TARGET_LINK_LIBRARIES(${target} ${OPENSSL_LIBRARIES} ${CURL_LIBRARIES} ${UUID_LIBRARIES})
  ENDIF()
ENDFUNCTION()