From 6b192354e28ff975ff14c2b505d6a05f38ed8fc0 Mon Sep 17 00:00:00 2001 From: dvirtz Date: Tue, 19 Oct 2021 22:59:08 +0300 Subject: [PATCH] package files for building SDK plugins --- recipes/aws-sdk-cpp/all/conanfile.py | 74 ++++++++++++++++++- .../all/test_package/CMakeLists.txt | 4 +- .../aws-sdk-cpp-plugin/AwsSdkCppPlugin.cpp | 16 ++++ .../aws-sdk-cpp-plugin/AwsSdkCppPlugin.h | 7 ++ .../aws-sdk-cpp-plugin/CMakeLists.txt | 14 ++++ .../aws-sdk-cpp/all/test_package/example.cpp | 14 +--- 6 files changed, 114 insertions(+), 15 deletions(-) create mode 100644 recipes/aws-sdk-cpp/all/test_package/aws-sdk-cpp-plugin/AwsSdkCppPlugin.cpp create mode 100644 recipes/aws-sdk-cpp/all/test_package/aws-sdk-cpp-plugin/AwsSdkCppPlugin.h create mode 100644 recipes/aws-sdk-cpp/all/test_package/aws-sdk-cpp-plugin/CMakeLists.txt diff --git a/recipes/aws-sdk-cpp/all/conanfile.py b/recipes/aws-sdk-cpp/all/conanfile.py index 70e0ba662dac2a..7e8c15f6278bec 100644 --- a/recipes/aws-sdk-cpp/all/conanfile.py +++ b/recipes/aws-sdk-cpp/all/conanfile.py @@ -1,6 +1,10 @@ -from conans import ConanFile, CMake, tools -from conans.errors import ConanInvalidConfiguration import os +import textwrap + +from conan.tools.files import rename +from conans import CMake, ConanFile, tools +from conans.errors import ConanInvalidConfiguration + class AwsSdkCppConan(ConanFile): name = "aws-sdk-cpp" @@ -398,6 +402,65 @@ def build(self): cmake = self._configure_cmake() cmake.build() + @property + def _res_folder(self): + return "res" + + def _create_project_cmake_module(self): + # package files needed to build other components (e.g. aws-cdi-sdk) with this SDK + for file in [ + "cmake/compiler_settings.cmake", + "cmake/initialize_project_version.cmake", + "cmake/utilities.cmake", + "toolchains/cmakeProjectConfig.cmake", + "toolchains/pkg-config.pc.in", + "aws-cpp-sdk-core/include/aws/core/VersionConfig.h" + ]: + self.copy(file, src=self._source_subfolder, dst=self._res_folder) + tools.replace_in_file(os.path.join(self.package_folder, self._res_folder, file), "CMAKE_CURRENT_SOURCE_DIR", "AWS_NATIVE_SDK_ROOT", strict=False) + + # avoid getting error from hook + with tools.chdir(os.path.join(self.package_folder, self._res_folder)): + rename(self, os.path.join("toolchains", "cmakeProjectConfig.cmake"), os.path.join("toolchains", "cmakeProjectConf.cmake")) + tools.replace_in_file(os.path.join("cmake", "utilities.cmake"), "cmakeProjectConfig.cmake", "cmakeProjectConf.cmake") + + # create a cmake module to load the files above + contents = textwrap.dedent(""" + get_filename_component(AWS_NATIVE_SDK_ROOT ${CMAKE_CURRENT_LIST_DIR} DIRECTORY) + set(SIMPLE_INSTALL TRUE) + + if (CMAKE_INSTALL_BINDIR) + set(BINARY_DIRECTORY "${CMAKE_INSTALL_BINDIR}") + endif() + + if (CMAKE_INSTALL_LIBDIR) + set(LIBRARY_DIRECTORY "${CMAKE_INSTALL_LIBDIR}") + endif() + + if (CMAKE_INSTALL_INCLUDEDIR) + set(INCLUDE_DIRECTORY "${CMAKE_INSTALL_INCLUDEDIR}") + endif() + + if(BUILD_SHARED_LIBS) + set(ARCHIVE_DIRECTORY "${BINARY_DIRECTORY}") + else() + set(ARCHIVE_DIRECTORY "${LIBRARY_DIRECTORY}") + endif() + + if(DEFINED CMAKE_CXX_STANDARD) + set(STANDARD_DEFAULT ${CMAKE_CXX_STANDARD}) + else() + set(STANDARD_DEFAULT "11") + endif() + set(CPP_STANDARD ${STANDARD_DEFAULT} CACHE STRING "Flag to upgrade the C++ standard used. The default is 11. The minimum is 11.") + + include(CMakePackageConfigHelpers) + include(initialize_project_version) + include(utilities) + include(compiler_settings) + """) + tools.save(os.path.join(self.package_folder, self._res_folder, "cmake", "add_project.cmake"), content=contents) + def package(self): self.copy("LICENSE", dst="licenses", src=self._source_subfolder) cmake = self._configure_cmake() @@ -409,6 +472,8 @@ def package(self): tools.rmdir(os.path.join(self.package_folder, "lib", "cmake")) tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig")) + self._create_project_cmake_module() + def package_info(self): self.cpp_info.filenames["cmake_find_package"] = "AWSSDK" self.cpp_info.filenames["cmake_find_package_multi"] = "AWSSDK" @@ -470,3 +535,8 @@ def package_info(self): if lib_stdcpp: self.cpp_info.components["core"].system_libs.append(lib_stdcpp) + self.cpp_info.components["plugin_scripts"].requires = ["core"] + self.cpp_info.components["plugin_scripts"].builddirs.extend([ + os.path.join(self._res_folder, "cmake"), + os.path.join(self._res_folder, "toolchains")]) + self.cpp_info.components["plugin_scripts"].build_modules.append(os.path.join(self._res_folder, "cmake", "add_project.cmake")) diff --git a/recipes/aws-sdk-cpp/all/test_package/CMakeLists.txt b/recipes/aws-sdk-cpp/all/test_package/CMakeLists.txt index 248a21375c4303..bdb8fcd85b5cd0 100644 --- a/recipes/aws-sdk-cpp/all/test_package/CMakeLists.txt +++ b/recipes/aws-sdk-cpp/all/test_package/CMakeLists.txt @@ -9,5 +9,7 @@ conan_basic_setup(TARGETS) find_package(AWSSDK REQUIRED CONFIG) +add_subdirectory(aws-sdk-cpp-plugin) + add_executable(example example.cpp) -target_link_libraries(example AWS::aws-sdk-cpp-s3) +target_link_libraries(example PRIVATE aws-sdk-cpp-plugin) diff --git a/recipes/aws-sdk-cpp/all/test_package/aws-sdk-cpp-plugin/AwsSdkCppPlugin.cpp b/recipes/aws-sdk-cpp/all/test_package/aws-sdk-cpp-plugin/AwsSdkCppPlugin.cpp new file mode 100644 index 00000000000000..6171e1633708ec --- /dev/null +++ b/recipes/aws-sdk-cpp/all/test_package/aws-sdk-cpp-plugin/AwsSdkCppPlugin.cpp @@ -0,0 +1,16 @@ +#include "AwsSdkCppPlugin.h" +#include +#include +#include +#include + +AwsSdkCppPlugin::AwsSdkCppPlugin() { + using namespace Aws; + using namespace Auth; + using namespace Client; + using namespace S3; + ClientConfiguration config; + auto client = MakeShared("S3Client", + MakeShared("S3Client"), config, + AWSAuthV4Signer::PayloadSigningPolicy::Never /*signPayloads*/, true /*useVirtualAddressing*/, US_EAST_1_REGIONAL_ENDPOINT_OPTION::LEGACY); +} diff --git a/recipes/aws-sdk-cpp/all/test_package/aws-sdk-cpp-plugin/AwsSdkCppPlugin.h b/recipes/aws-sdk-cpp/all/test_package/aws-sdk-cpp-plugin/AwsSdkCppPlugin.h new file mode 100644 index 00000000000000..e05192e7255234 --- /dev/null +++ b/recipes/aws-sdk-cpp/all/test_package/aws-sdk-cpp-plugin/AwsSdkCppPlugin.h @@ -0,0 +1,7 @@ +#include + +class AWS_SDK_CPP_PLUGIN_EXPORT AwsSdkCppPlugin +{ +public: + AwsSdkCppPlugin(); +}; diff --git a/recipes/aws-sdk-cpp/all/test_package/aws-sdk-cpp-plugin/CMakeLists.txt b/recipes/aws-sdk-cpp/all/test_package/aws-sdk-cpp-plugin/CMakeLists.txt new file mode 100644 index 00000000000000..c30b7c60110b37 --- /dev/null +++ b/recipes/aws-sdk-cpp/all/test_package/aws-sdk-cpp-plugin/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.1) + +add_project(aws-sdk-cpp-plugin "C++ AWS SDK plugin" AWS::aws-sdk-cpp-s3) + +add_library(${PROJECT_NAME} AwsSdkCppPlugin.cpp) + +include(GenerateExportHeader) +generate_export_header(${PROJECT_NAME} BASE_NAME aws_sdk_cpp_plugin) +target_include_directories(${PROJECT_NAME} PUBLIC $ $) +target_link_libraries(${PROJECT_NAME} PUBLIC ${PROJECT_LIBS}) + +setup_install() + +do_packaging() diff --git a/recipes/aws-sdk-cpp/all/test_package/example.cpp b/recipes/aws-sdk-cpp/all/test_package/example.cpp index 295a0fe6c09540..f66fb046b91dc3 100644 --- a/recipes/aws-sdk-cpp/all/test_package/example.cpp +++ b/recipes/aws-sdk-cpp/all/test_package/example.cpp @@ -1,23 +1,13 @@ -#include #include #include -#include -#include -#include -#include +#include int main() { using namespace Aws; - using namespace Auth; - using namespace Client; - using namespace S3; SDKOptions options; InitAPI(options); - ClientConfiguration config; - auto client = MakeShared("S3Client", - MakeShared("S3Client"), config, - AWSAuthV4Signer::PayloadSigningPolicy::Never /*signPayloads*/, true /*useVirtualAddressing*/, US_EAST_1_REGIONAL_ENDPOINT_OPTION::LEGACY); + AwsSdkCppPlugin Plugin; ShutdownAPI(options); return 0; }