Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws-lambda-cpp: add cmake module for packaging function #23429

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions recipes/aws-lambda-cpp/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.files import get, copy, rmdir
from conan.errors import ConanInvalidConfiguration, ConanException
from conan.tools.files import get, copy, rmdir, load, save, rename
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.scm import Version
Expand Down Expand Up @@ -72,16 +72,29 @@ def build(self):
cmake.configure()
cmake.build()

def _extract_cmake_module(self):
cmake_module = load(self, os.path.join(self.source_folder, "cmake", "aws-lambda-runtime-config.cmake"))
start = "set(AWS_LAMBDA_PACKAGING_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/packager)"
start_index = cmake_module.find(start)
if start_index == -1:
raise ConanException("Could not extract aws_lambda_package_target from aws-lambda-runtime-config.cmake file.")
return cmake_module[start_index:]

def package(self):
copy(self, pattern="LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
cmake = CMake(self)
cmake.install()

save(self, os.path.join(self.package_folder, "lib", "cmake", "aws_lambda_package_target.cmake"), self._extract_cmake_module())
rename(self, os.path.join(self.package_folder, "lib", "aws-lambda-runtime", "cmake", "packager"), os.path.join(self.package_folder, "lib", "cmake", "packager"))
rmdir(self, os.path.join(self.package_folder, "lib", "aws-lambda-runtime"))

def package_info(self):
self.cpp_info.libs = ["aws-lambda-runtime"]
self.cpp_info.builddirs.append(os.path.join("lib", "cmake"))

self.cpp_info.set_property("cmake_file_name", "aws-lambda-runtime")
self.cpp_info.set_property("cmake_target_name", "AWS::aws-lambda-runtime")
self.cpp_info.set_property("cmake_build_modules", [os.path.join("lib", "cmake", "aws_lambda_package_target.cmake")])

self.cpp_info.system_libs.append("m")
4 changes: 4 additions & 0 deletions recipes/aws-lambda-cpp/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ find_package(aws-lambda-runtime REQUIRED CONFIG)
add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE AWS::aws-lambda-runtime)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)

if(NOT COMMAND aws_lambda_package_target)
message(FATAL_ERROR "aws_lambda_package_target should have been defined as part of find_package(aws-lambda-runtime)")
endif()
Loading