Skip to content

Commit

Permalink
package files for building SDK plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
dvirtz committed Oct 25, 2021
1 parent f09958a commit 0048f07
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 13 deletions.
68 changes: 68 additions & 0 deletions recipes/aws-sdk-cpp/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
import os
import textwrap

class AwsSdkCppConan(ConanFile):
name = "aws-sdk-cpp"
Expand Down Expand Up @@ -379,6 +380,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)):
tools.rename(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()
Expand All @@ -387,6 +447,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"
Expand Down Expand Up @@ -439,3 +501,9 @@ def package_info(self):
lib_stdcpp = tools.stdcpp_library(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"))
4 changes: 3 additions & 1 deletion recipes/aws-sdk-cpp/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

add_subdirectory(aws-sdk-cpp-plugin)

add_executable(example example.cpp)
target_link_libraries(example ${CONAN_LIBS})
target_link_libraries(example PRIVATE aws-sdk-cpp-plugin ${CONAN_LIBS})
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "AwsSdkCppPlugin.h"
#include <aws/core/auth/AWSAuthSigner.h>
#include <aws/core/auth/AWSCredentialsProviderChain.h>
#include <aws/core/client/ClientConfiguration.h>
#include <aws/s3/S3Client.h>

AwsSdkCppPlugin::AwsSdkCppPlugin() {
using namespace Aws;
using namespace Auth;
using namespace Client;
using namespace S3;
ClientConfiguration config;
auto client = MakeShared<S3Client>("pouet",
MakeShared<DefaultAWSCredentialsProviderChain>("pouet"), config,
AWSAuthV4Signer::PayloadSigningPolicy::Never /*signPayloads*/, true /*useVirtualAddressing*/, US_EAST_1_REGIONAL_ENDPOINT_OPTION::LEGACY);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <aws_sdk_cpp_plugin_export.h>

class AWS_SDK_CPP_PLUGIN_EXPORT AwsSdkCppPlugin
{
public:
AwsSdkCppPlugin();
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
add_project(aws-sdk-cpp-plugin "C++ AWS SDK plugin" AWS::aws-sdk-cpp-core)

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 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>)

setup_install()

do_packaging()
14 changes: 2 additions & 12 deletions recipes/aws-sdk-cpp/all/test_package/example.cpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
#include <iostream>
#include <memory>
#include <aws/core/Aws.h>
#include <aws/core/auth/AWSAuthSigner.h>
#include <aws/core/auth/AWSCredentialsProviderChain.h>
#include <aws/core/client/ClientConfiguration.h>
#include <aws/s3/S3Client.h>
#include <AwsSdkCppPlugin.h>


int main() {
using namespace Aws;
using namespace Auth;
using namespace Client;
using namespace S3;
SDKOptions options;
InitAPI(options);
ClientConfiguration config;
auto client = MakeShared<S3Client>("pouet",
MakeShared<DefaultAWSCredentialsProviderChain>("pouet"), config,
AWSAuthV4Signer::PayloadSigningPolicy::Never /*signPayloads*/, true /*useVirtualAddressing*/, US_EAST_1_REGIONAL_ENDPOINT_OPTION::LEGACY);
AwsSdkCppPlugin Plugin;
ShutdownAPI(options);
return 0;
}
Expand Down

0 comments on commit 0048f07

Please sign in to comment.