Commit 32202277 authored by Vladislav Vaintroub's avatar Vladislav Vaintroub

MDEV-18578 build aws sdk for all plugins to use

parent 3be9982f
......@@ -431,6 +431,7 @@ INCLUDE(cmake/tags.cmake)
INCLUDE(for_clients)
ADD_SUBDIRECTORY(scripts)
ADD_SUBDIRECTORY(support-files)
ADD_SUBDIRECTORY(aws_sdk)
IF(NOT CMAKE_CROSSCOMPILING)
SET(EXPORTED comp_err comp_sql factorial)
......
OPTION(AWS_SDK_EXTERNAL_PROJECT "Allow to download and build AWS C++ SDK" OFF)
INCLUDE(aws_sdk)
INCLUDE(ExternalProject)
GET_PROPERTY(SDK_LIBS GLOBAL PROPERTY AWS_SDK_LIBS)
LIST(LENGTH SDK_LIBS SDK_LIBS_COUNT)
IF(SDK_LIBS_COUNT EQUAL 0)
RETURN()
ENDIF()
CHECK_AWS_SDK(RETVAL REASON)
IF(NOT RETVAL)
MESSAGE(FATAL_ERROR
"AWS C++ will not be built (${REASON}), but dependency on following components is found ${SDK_LIBS}.
Use CHECK_AWS_SDK() function before trying to build with SDK components")
ENDIF()
SET(byproducts)
FOREACH(lib ${SDK_LIBS} core)
SET(lib aws-cpp-sdk-${lib})
ADD_LIBRARY(${lib} STATIC IMPORTED GLOBAL)
ADD_DEPENDENCIES(${lib} aws_sdk_cpp)
SET (loc "${CMAKE_CURRENT_BINARY_DIR}/aws_sdk_cpp/lib/${CMAKE_STATIC_LIBRARY_PREFIX}${lib}${CMAKE_STATIC_LIBRARY_SUFFIX}")
IF(CMAKE_VERSION VERSION_GREATER "3.1")
SET(byproducts ${byproducts} BUILD_BYPRODUCTS ${loc})
ENDIF()
SET_TARGET_PROPERTIES(${lib} PROPERTIES IMPORTED_LOCATION ${loc})
ENDFOREACH()
# To be compatible with older cmake, we use older version of the SDK
IF(CMAKE_VERSION LESS "3.0")
SET(GIT_TAG "1.0.8")
ELSE()
SET(GIT_TAG "1.2.11")
ENDIF()
IF(MSVC_CRT_TYPE MATCHES "/MD")
SET(FORCE_SHARED_CRT ON)
ELSE()
SET(FORCE_SHARED_CRT OFF)
ENDIF()
LIST(REMOVE_DUPLICATES SDK_LIBS)
STRING( REPLACE ";" "!" SDK_LIBS_STR "${SDK_LIBS}")
#MESSAGE("SDK_LIBS_STR=${SDK_LIBS_STR}")
ExternalProject_Add(
aws_sdk_cpp
GIT_REPOSITORY "https://github.com/awslabs/aws-sdk-cpp.git"
GIT_TAG ${GIT_TAG}
UPDATE_COMMAND ""
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/aws-sdk-cpp"
LIST_SEPARATOR !
${byproducts}
CMAKE_ARGS
-DBUILD_ONLY=${SDK_LIBS_STR}
-DBUILD_SHARED_LIBS=OFF
-DFORCE_SHARED_CRT=${FORCE_SHARED_CRT}
-DENABLE_TESTING=OFF
"-DCMAKE_CXX_FLAGS_DEBUG=${CMAKE_CXX_FLAGS_DEBUG} ${PIC_FLAG}"
"-DCMAKE_CXX_FLAGS_RELWITHDEBINFO=${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${PIC_FLAG}"
"-DCMAKE_CXX_FLAGS_RELEASE=${CMAKE_CXX_FLAGS_RELEASE} ${PIC_FLAG}"
"-DCMAKE_CXX_FLAGS_MINSIZEREL=${CMAKE_CXX_FLAGS_MINSIZEREL} ${PIC_FLAG}"
"-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}"
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
${EXTRA_SDK_CMAKE_FLAGS}
-DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/aws_sdk_cpp
-DCMAKE_INSTALL_LIBDIR=lib
TEST_COMMAND ""
)
SET_TARGET_PROPERTIES(aws_sdk_cpp PROPERTIES EXCLUDE_FROM_ALL TRUE)
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()
# We build parts of AWS C++ SDK as CMake external project
# The restrictions of the SDK (https://github.com/awslabs/aws-sdk-cpp/blob/master/README.md)
# are
# - OS : Windows,Linux or OSX
# - C++11 compiler : VS2013+, gcc 4.8+, clang 3.3+
# - libcurl development package needs to be present on Unixes
#
# If we build SDK outselves, we'll need require GIT to be present on the build machine
# Give message why the building this plugin is skipped (only if -DVERBOSE is defined)
# or if plugin is explicitly requested to build. Then bail out.
MACRO(SKIP_AWS_PLUGIN msg)
MESSAGE_ONCE(SKIP_AWS_PLUGIN "Skip aws_key_management - ${msg}")
INCLUDE(aws_sdk)
CHECK_AWS_SDK(HAVE_AWS_SDK REASON)
IF(NOT HAVE_AWS_SDK)
MESSAGE_ONCE(AWS_KEY_MANAGEMENT_NO_AWS_SDK "Can't build aws_key_management - AWS SDK not available (${REASON})")
RETURN()
ENDMACRO()
SET(CMAKE_CXX_STANDARD 11)
# This plugin needs recent C++ compilers (AWS C++ SDK header files are using C++11 features)
SET(CXX11_FLAGS)
SET(OLD_COMPILER_MSG "AWS SDK requires c++11 -capable compiler (minimal supported versions are g++ 4.8, clang 3.3, VS2103)")
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_PLUGIN("${OLD_COMPILER_MSG}")
ENDIF()
SET(CXX11_FLAGS "-std=c++11")
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_PLUGIN("${OLD_COMPILER_MSG}")
ENDIF()
SET(CXX11_FLAGS "-stdlib=libc++")
ELSEIF(MSVC)
IF (MSVC_VERSION LESS 1800)
SKIP_AWS_PLUGIN("${OLD_COMPILER_MSG}")
ENDIF()
ELSE()
SKIP_AWS_PLUGIN("Compiler not supported by AWS C++ SDK")
ENDIF()
IF (NOT(WIN32 OR APPLE OR (CMAKE_SYSTEM_NAME MATCHES "Linux")))
SKIP_AWS_PLUGIN("OS unsupported by AWS SDK")
ENDIF()
FIND_LIBRARY(AWS_CPP_SDK_CORE NAMES aws-cpp-sdk-core PATH_SUFFIXES "${SDK_INSTALL_BINARY_PREFIX}")
FIND_LIBRARY(AWS_CPP_SDK_KMS NAMES aws-cpp-sdk-kms PATH_SUFFIXES "${SDK_INSTALL_BINARY_PREFIX}")
FIND_PATH(AWS_CPP_SDK_INCLUDE_DIR NAMES aws/kms/KMSClient.h)
IF(AWS_CPP_SDK_CORE AND AWS_CPP_SDK_KMS AND AWS_CPP_SDK_INCLUDE_DIR)
# AWS C++ SDK installed
INCLUDE_DIRECTORIES(${AWS_CPP_SDK_INCLUDE_DIR})
SET(AWS_SDK_LIBS ${AWS_CPP_SDK_CORE} ${AWS_CPP_SDK_KMS})
ELSE()
OPTION(AWS_SDK_EXTERNAL_PROJECT "Allow download and build AWS C++ SDK" OFF)
IF(NOT AWS_SDK_EXTERNAL_PROJECT)
SKIP_AWS_PLUGIN("AWS_SDK_EXTERNAL_PROJECT is not set")
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_PLUGIN("CMake is too old")
ENDIF()
FIND_PACKAGE(Git)
IF(NOT GIT_FOUND)
SKIP_AWS_PLUGIN("no GIT")
ENDIF()
INCLUDE(ExternalProject)
IF(UNIX)
FIND_PACKAGE(CURL)
IF(NOT CURL_FOUND)
SKIP_AWS_PLUGIN("AWS C++ SDK requires libcurl development package")
ENDIF()
SET(PIC_FLAG -fPIC)
FIND_PATH(UUID_INCLUDE_DIR uuid/uuid.h)
IF(NOT UUID_INCLUDE_DIR)
SKIP_AWS_PLUGIN("AWS C++ SDK requires uuid development package")
ENDIF()
IF(NOT APPLE)
FIND_LIBRARY(UUID_LIBRARIES uuid)
IF(NOT UUID_LIBRARIES)
SKIP_AWS_PLUGIN("AWS C++ SDK requires uuid development package")
ENDIF()
FIND_PACKAGE(OpenSSL)
IF(NOT OPENSSL_FOUND)
SKIP_AWS_PLUGIN("AWS C++ SDK requires openssl development package")
ENDIF()
ENDIF()
ENDIF()
IF(MSVC)
SET(EXTRA_SDK_CMAKE_FLAGS -DCMAKE_CXX_FLAGS_DEBUGOPT="" -DCMAKE_EXE_LINKER_FLAGS_DEBUGOPT="" "-DCMAKE_CXX_FLAGS=/wd4530 /wd4577 /WX-")
ENDIF()
IF(CMAKE_CXX_COMPILER)
SET(EXTRA_SDK_CMAKE_FLAGS ${EXTRA_SDK_CMAKE_FLAGS} -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER})
ENDIF()
SET(byproducts )
# We do not need to build the whole SDK , just 2 of its libs
set(AWS_SDK_LIBS aws-cpp-sdk-core aws-cpp-sdk-kms)
FOREACH(lib ${AWS_SDK_LIBS})
ADD_LIBRARY(${lib} STATIC IMPORTED GLOBAL)
ADD_DEPENDENCIES(${lib} aws_sdk_cpp)
SET(loc "${CMAKE_CURRENT_BINARY_DIR}/aws_sdk_cpp/lib/${CMAKE_STATIC_LIBRARY_PREFIX}${lib}${CMAKE_STATIC_LIBRARY_SUFFIX}")
IF(CMAKE_VERSION VERSION_GREATER "3.1")
SET(byproducts ${byproducts} BUILD_BYPRODUCTS ${loc})
ENDIF()
SET_TARGET_PROPERTIES(${lib} PROPERTIES IMPORTED_LOCATION ${loc})
ENDFOREACH()
# To be compatible with older cmake, we use older version of the SDK
IF(CMAKE_VERSION LESS "3.0")
SET(GIT_TAG "1.0.8")
ELSE()
SET(GIT_TAG "1.2.11")
ENDIF()
IF(MSVC_CRT_TYPE MATCHES "/MD")
SET(FORCE_SHARED_CRT ON)
ELSE()
SET(FORCE_SHARED_CRT OFF)
ENDIF()
SET(AWS_SDK_PATCH_COMMAND )
ExternalProject_Add(
aws_sdk_cpp
GIT_REPOSITORY "https://github.com/awslabs/aws-sdk-cpp.git"
GIT_TAG ${GIT_TAG}
UPDATE_COMMAND ""
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/aws-sdk-cpp"
${byproducts}
CMAKE_ARGS
-DBUILD_ONLY=kms
-DBUILD_SHARED_LIBS=OFF
-DFORCE_SHARED_CRT=${FORCE_SHARED_CRT}
-DENABLE_TESTING=OFF
"-DCMAKE_CXX_FLAGS_DEBUG=${CMAKE_CXX_FLAGS_DEBUG} ${PIC_FLAG}"
"-DCMAKE_CXX_FLAGS_RELWITHDEBINFO=${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${PIC_FLAG}"
"-DCMAKE_CXX_FLAGS_RELEASE=${CMAKE_CXX_FLAGS_RELEASE} ${PIC_FLAG}"
"-DCMAKE_CXX_FLAGS_MINSIZEREL=${CMAKE_CXX_FLAGS_MINSIZEREL} ${PIC_FLAG}"
${EXTRA_SDK_CMAKE_FLAGS}
-DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/aws_sdk_cpp
-DCMAKE_INSTALL_LIBDIR=lib
TEST_COMMAND ""
)
SET_TARGET_PROPERTIES(aws_sdk_cpp PROPERTIES EXCLUDE_FROM_ALL TRUE)
IF(CMAKE_SYSTEM_NAME MATCHES "Linux")
# Need whole-archive , otherwise static libraries are not linked
SET(AWS_SDK_LIBS -Wl,--whole-archive ${AWS_SDK_LIBS} -Wl,--no-whole-archive)
ENDIF()
SET_TARGET_PROPERTIES(aws_sdk_cpp PROPERTIES EXCLUDE_FROM_ALL TRUE)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/aws_sdk_cpp/include)
ENDIF()
ADD_DEFINITIONS(${SSL_DEFINES}) # Need to know whether openssl should be initialized
IF(CMAKE_VERSION GREATER "3.0")
SET(CMAKE_CXX_STANDARD 11)
ELSE()
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX11_FLAGS}")
ENDIF()
IF(WIN32)
SET(AWS_CPP_SDK_DEPENDENCIES bcrypt winhttp wininet userenv version)
ELSE()
SET(AWS_CPP_SDK_DEPENDENCIES ${OPENSSL_LIBRARIES} ${CURL_LIBRARIES} ${UUID_LIBRARIES})
ENDIF()
MYSQL_ADD_PLUGIN(aws_key_management aws_key_management_plugin.cc
LINK_LIBRARIES ${AWS_SDK_LIBS} ${AWS_CPP_SDK_DEPENDENCIES}
COMPONENT aws-key-management)
MYSQL_ADD_PLUGIN(aws_key_management
aws_key_management_plugin.cc
COMPONENT aws-key-management)
IF(TARGET aws_key_management)
USE_AWS_SDK_LIBS(aws_key_management kms)
ENDIF()
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment