|
| 1 | +# We build parts of AWS C++ SDK as CMake external project |
| 2 | +# The restrictions of the SDK (https://github.com/awslabs/aws-sdk-cpp/blob/master/README.md) |
| 3 | +# are |
| 4 | + |
| 5 | +# - OS : Windows,Linux or OSX |
| 6 | +# - C++11 compiler : VS2013+, gcc 4.7+, clang 3.3+ |
| 7 | +# - libcurl development package needs to be present on Unixes |
| 8 | +# |
| 9 | +# If we build SDK outselves, we'll need require GIT to be present on the build machine |
| 10 | + |
| 11 | + |
| 12 | +# Give message why the building this plugin is skipped (only if -DVERBOSE is defined) |
| 13 | +# or if plugin is explicitely requested to build. Then bail out. |
| 14 | +MACRO(SKIP_AWS_PLUGIN msg) |
| 15 | + IF(VERBOSE OR "${PLUGIN_AWS_KEY_MANAGEMENT}" MATCHES "^(STATIC|DYNAMIC)$") |
| 16 | + MESSAGE(STATUS "Skip aws_key_management - ${msg}") |
| 17 | + ENDIF() |
| 18 | + RETURN() |
| 19 | +ENDMACRO() |
| 20 | + |
| 21 | + |
| 22 | +# This plugin needs recent C++ compilers (AWS C++ SDK header files are using C++11 features) |
| 23 | +SET(CXX11_FLAGS) |
| 24 | +SET(OLD_COMPILER_MSG "AWS SDK requires c++11 -capable compiler (minimal supported versions are g++ 4.7, clang 3.3, VS2103)") |
| 25 | + |
| 26 | +IF(CMAKE_CXX_COMPILER_ID MATCHES "GNU") |
| 27 | + EXECUTE_PROCESS(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION) |
| 28 | + IF (GCC_VERSION VERSION_LESS 4.8) |
| 29 | + SKIP_AWS_PLUGIN("${OLD_COMPILER_MSG}") |
| 30 | + ENDIF() |
| 31 | + SET(CXX11_FLAGS "-std=c++11") |
| 32 | +ELSEIF (CMAKE_CXX_COMPILER_ID MATCHES "Clang") |
| 33 | + IF ((CMAKE_CXX_COMPILER_VERSION AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.3) OR |
| 34 | + (CLANG_VERSION_STRING AND CLANG_VERSION_STRING VERSION_LESS 3.3)) |
| 35 | + SKIP_AWS_PLUGIN("${OLD_COMPILER_MSG}") |
| 36 | + ENDIF() |
| 37 | + SET(CXX11_FLAGS "-stdlib=libc++") |
| 38 | +ELSEIF(MSVC) |
| 39 | + IF (MSVC_VERSION LESS 1800) |
| 40 | + SKIP_AWS_PLUGIN("${OLD_COMPILER_MSG}") |
| 41 | + ENDIF() |
| 42 | +ELSE() |
| 43 | + SKIP_AWS_PLUGIN("Compiler not supported by AWS C++ SDK") |
| 44 | +ENDIF() |
| 45 | + |
| 46 | +IF (NOT(WIN32 OR APPLE OR (CMAKE_SYSTEM_NAME MATCHES "Linux"))) |
| 47 | + SKIP_AWS_PLUGIN("OS unsupported by AWS SDK") |
| 48 | +ENDIF() |
| 49 | + |
| 50 | + |
| 51 | +# Figure out where AWS installs SDK libraries |
| 52 | +# The below is defined in AWS SDK's CMakeLists.txt |
| 53 | +# (and their handling is weird, every OS has special install directory) |
| 54 | +IF(WIN32) |
| 55 | + SET(SDK_INSTALL_BINARY_PREFIX "windows") |
| 56 | +ELSEIF(APPLE) |
| 57 | + SET(SDK_INSTALL_BINARY_PREFIX "mac") |
| 58 | +ELSEIF(UNIX) |
| 59 | + SET(SDK_INSTALL_BINARY_PREFIX "linux") |
| 60 | +ENDIF() |
| 61 | +IF(NOT APPLE) |
| 62 | + IF(CMAKE_SIZEOF_VOID_P EQUAL 8) |
| 63 | + SET(SDK_INSTALL_BINARY_PREFIX "${SDK_INSTALL_BINARY_PREFIX}/intel64") |
| 64 | + ELSE() |
| 65 | + SET(SDK_INSTALL_BINARY_PREFIX "${SDK_INSTALL_BINARY_PREFIX}/ia32") |
| 66 | + ENDIF() |
| 67 | +ENDIF() |
| 68 | +IF(CMAKE_CONFIGURATION_TYPES) |
| 69 | + SET(SDK_INSTALL_BINARY_PREFIX "${SDK_INSTALL_BINARY_PREFIX}/${CMAKE_CFG_INTDIR}") |
| 70 | +ENDIF() |
| 71 | + |
| 72 | +FIND_LIBRARY(AWS_CPP_SDK_CORE NAMES aws-cpp-sdk-core PATH_SUFFIXES "${SDK_INSTALL_BINARY_PREFIX}") |
| 73 | +FIND_LIBRARY(AWS_CPP_SDK_KMS NAMES aws-cpp-sdk-core PATH_SUFFIXES "${SDK_INSTALL_BINARY_PREFIX}") |
| 74 | +SET(CMAKE_REQUIRED_FLAGS ${CXX11_FLAGS}) |
| 75 | +CHECK_INCLUDE_FILE_CXX(aws/kms/KMSClient.h HAVE_AWS_HEADERS) |
| 76 | + |
| 77 | +IF(AWS_CPP_SDK_CORE AND AWS_CPP_SDK_KMS AND HAVE_AWS_HEADERS) |
| 78 | + # AWS C++ SDK installed |
| 79 | + SET(AWS_SDK_LIBS ${AWS_CPP_SDK_CORE} ${AWS_CPP_SDK_KMS}) |
| 80 | +ELSE() |
| 81 | + # Build from source, using ExternalProject_Add |
| 82 | + IF(CMAKE_VERSION VERSION_LESS "2.8.8") |
| 83 | + SKIP_AWS_PLUGIN("CMake is too old") |
| 84 | + ENDIF() |
| 85 | + FIND_PACKAGE(Git) |
| 86 | + IF(NOT GIT_FOUND) |
| 87 | + SKIP_AWS_PLUGIN("no GIT") |
| 88 | + ENDIF() |
| 89 | + INCLUDE(ExternalProject) |
| 90 | + IF(UNIX) |
| 91 | + FIND_PACKAGE(CURL) |
| 92 | + IF(NOT CURL_FOUND) |
| 93 | + SKIP_AWS_PLUGIN("AWS C++ SDK requires libcurl development package") |
| 94 | + ENDIF() |
| 95 | + SET(PIC_FLAG -fPIC) |
| 96 | + ENDIF() |
| 97 | + IF(MSVC) |
| 98 | + SET(EXTRA_SDK_CMAKE_FLAGS -DCMAKE_CXX_FLAGS_DEBUGOPT="" -DCMAKE_EXE_LINKER_FLAGS_DEBUGOPT="" -DCMAKE_CXX_FLAGS=/wd4592) |
| 99 | + ENDIF() |
| 100 | + IF(CMAKE_CXX_COMPILER) |
| 101 | + SET(EXTRA_SDK_CMAKE_FLAGS ${EXTRA_SDK_CMAKE_FLAGS} -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}) |
| 102 | + ENDIF() |
| 103 | + |
| 104 | + # Relax AWS C++ SDK unreasonably high requirements for CMake version. Use replace utility (from MariaDB build) |
| 105 | + # to patch their CMakeLists.txt |
| 106 | + SET(AWS_SDK_PATCH_COMMAND ) |
| 107 | + ExternalProject_Add( |
| 108 | + aws_sdk_cpp |
| 109 | + GIT_REPOSITORY "https://github.com/awslabs/aws-sdk-cpp.git" |
| 110 | + GIT_TAG "0.9.6" # single tag |
| 111 | + UPDATE_COMMAND "" |
| 112 | + PATCH_COMMAND replace 3.1.2 2.8 -- ${CMAKE_BINARY_DIR}/aws-sdk-cpp/CMakeLists.txt |
| 113 | + SOURCE_DIR "${CMAKE_BINARY_DIR}/aws-sdk-cpp" |
| 114 | + CMAKE_ARGS |
| 115 | + -DBUILD_ONLY=aws-cpp-sdk-kms -DSTATIC_LINKING=1 |
| 116 | + "-DCMAKE_CXX_FLAGS_DEBUG=${CMAKE_CXX_FLAGS_DEBUG} ${PIC_FLAG}" |
| 117 | + "-DCMAKE_CXX_FLAGS_RELWITHDEBINFO=${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${PIC_FLAG}" |
| 118 | + "-DCMAKE_CXX_FLAGS_RELEASE=${CMAKE_CXX_FLAGS_RELEASE} ${PIC_FLAG}" |
| 119 | + "-DCMAKE_CXX_FLAGS_MINSIZEREL=${CMAKE_CXX_FLAGS_MINSIZEREL} ${PIC_FLAG}" |
| 120 | + ${EXTRA_SDK_CMAKE_FLAGS} |
| 121 | + -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/aws_sdk_cpp |
| 122 | + TEST_COMMAND "" |
| 123 | + ) |
| 124 | + |
| 125 | + # We do not need to build the whole SDK , just 2 of its libs |
| 126 | + set(AWS_SDK_LIBS aws-cpp-sdk-core aws-cpp-sdk-kms) |
| 127 | + FOREACH(lib ${AWS_SDK_LIBS}) |
| 128 | + ADD_LIBRARY(${lib} STATIC IMPORTED GLOBAL) |
| 129 | + ADD_DEPENDENCIES(${lib} aws_sdk_cpp) |
| 130 | + SET(loc "${CMAKE_BINARY_DIR}/aws_sdk_cpp/lib/${SDK_INSTALL_BINARY_PREFIX}/${CMAKE_STATIC_LIBRARY_PREFIX}${lib}${CMAKE_STATIC_LIBRARY_SUFFIX}") |
| 131 | + SET_TARGET_PROPERTIES(${lib} PROPERTIES IMPORTED_LOCATION ${loc}) |
| 132 | + IF(WIN32) |
| 133 | + SET_TARGET_PROPERTIES(${lib} PROPERTIES IMPORTED_LINK_INTERFACE_LIBRARIES "bcrypt;winhttp;wininet;userenv") |
| 134 | + ELSE() |
| 135 | + SET_TARGET_PROPERTIES(${lib} PROPERTIES IMPORTED_LINK_INTERFACE_LIBRARIES "${SSL_LIBRARIES};${CURL_LIBRARIES}") |
| 136 | + ENDIF() |
| 137 | + ENDFOREACH() |
| 138 | + |
| 139 | + IF(CMAKE_SYSTEM_NAME MATCHES "Linux") |
| 140 | + # Need whole-archive , otherwise static libraries are not linked |
| 141 | + SET(AWS_SDK_LIBS -Wl,--whole-archive ${AWS_SDK_LIBS} -Wl,--no-whole-archive) |
| 142 | + ENDIF() |
| 143 | + SET_TARGET_PROPERTIES(aws_sdk_cpp PROPERTIES EXCLUDE_FROM_ALL TRUE) |
| 144 | + INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}/aws_sdk_cpp/include) |
| 145 | +ENDIF() |
| 146 | + |
| 147 | +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX11_FLAGS}") |
| 148 | +MYSQL_ADD_PLUGIN(aws_key_management aws_key_management_plugin.cc |
| 149 | + COMPONENT aws-key-management |
| 150 | + LINK_LIBRARIES ${AWS_SDK_LIBS} |
| 151 | + DISABLED) |
0 commit comments