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

opentdf-client: migrate to Conan v2 #18832

Merged
merged 7 commits into from
Aug 22, 2023
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
9 changes: 0 additions & 9 deletions recipes/opentdf-client/all/CMakeLists.txt

This file was deleted.

11 changes: 11 additions & 0 deletions recipes/opentdf-client/all/conan_cmake_project_include.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
find_package(Boost REQUIRED)
find_package(OpenSSL REQUIRED)
find_package(Microsoft.GSL REQUIRED)
find_package(nlohmann_json REQUIRED)
find_package(libxml2 REQUIRED)
find_package(jwt-cpp REQUIRED)
find_package(ZLIB REQUIRED)
if(opentdf_VERSION VERSION_GREATER_EQUAL "1.4.0")
find_package(magic_enum REQUIRED)
endif()
link_libraries(Boost::boost OpenSSL::SSL Microsoft.GSL::GSL nlohmann_json::nlohmann_json LibXml2::LibXml2 jwt-cpp::jwt-cpp $<TARGET_NAME_IF_EXISTS:magic_enum::magic_enum> ZLIB::ZLIB)
48 changes: 21 additions & 27 deletions recipes/opentdf-client/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,30 @@ sources:
"1.3.10":
url: "https://github.com/opentdf/client-cpp/archive/1.3.10.tar.gz"
sha256: "539bd5e64bceb86f63b3f7db75de470d5ea1d52ae6436a6a2d6789f7d0710dd4"
"1.3.9":
url: "https://github.com/opentdf/client-cpp/archive/1.3.9.tar.gz"
sha256: "8fdd88d90afe865ca86261c26abd1ca5e9895261490252199b7f9d4910ca0b49"
"1.3.8":
url: "https://github.com/opentdf/client-cpp/archive/1.3.8.tar.gz"
sha256: "0d73bd17f6d211c04136239e1db630e1ab320a6e41bd5c18533c44381519842c"
"1.3.6":
url: "https://github.com/opentdf/client-cpp/archive/1.3.6.tar.gz"
sha256: "e0d4cf1d0b1824d903a2b0ec1da528acb42623e32f3ca36aa28b2e950c3cc7a0"
"1.3.4":
url: "https://github.com/opentdf/client-cpp/archive/1.3.4.tar.gz"
sha256: "4b9836bff368249b709fc40e67c3a8664fed85a5d8247475ca1f741486210409"
"1.3.3":
url: "https://github.com/opentdf/client-cpp/archive/1.3.3.tar.gz"
sha256: "7949e662dc55a425771e5ecf2d96e25295d1e2394e805608aed72d1131896948"
"1.3.2":
url: "https://github.com/opentdf/client-cpp/archive/1.3.2.tar.gz"
sha256: "d9a38d3aa6114159c90e0c254c78ddda921e2d520851e4def57f3cd26c564b16"
"1.2.0":
url: "https://github.com/opentdf/client-cpp/archive/1.2.0.tar.gz"
sha256: "15828038809ed291ff7881206a675abc5162e1175c8b515363b9c584aebb08f7"
"1.1.6":
url: "https://github.com/opentdf/client-cpp/archive/1.1.6.tar.gz"
sha256: "83992c37c9a58ae2152660a4ffbf1784fe63d7a9e7b8466d10ca1074697b3d3a"
"1.1.5":
url: "https://github.com/opentdf/client-cpp/archive/1.1.5.tar.gz"
sha256: "8fd5b22b36b19cd58a18f63cbffe3d538263ef3aecde4802059951c4eb5ce044"
"1.1.3":
url: "https://github.com/opentdf/client-cpp/archive/1.1.3.tar.gz"
sha256: "67855999010f9c1496e170ad885f73b854f91eb1539e3c20d74b162295d5c732"
"1.1.2":
url: "https://github.com/opentdf/client-cpp/archive/1.1.2.tar.gz"
sha256: "4e41a18ef9d47aa9f964beffa78fdd4290a5f50336c6e4dc3c9bf2dd4b075d10"
patches:
"1.1.6":
- patch_file: "patches/1.1.6-0001-cmake-fixes.patch"
patch_description: "CMake build fixes for Conan 2.0-compatible recipe"
patch_type: "conan"
"1.2.0":
- patch_file: "patches/1.1.6-0001-cmake-fixes.patch"
patch_description: "CMake build fixes for Conan 2.0-compatible recipe"
patch_type: "conan"
"1.3.10":
- patch_file: "patches/1.3.10-0001-cmake-fixes.patch"
patch_description: "CMake build fixes for Conan 2.0-compatible recipe"
patch_type: "conan"
"1.4.0":
- patch_file: "patches/1.3.10-0001-cmake-fixes.patch"
patch_description: "CMake build fixes for Conan 2.0-compatible recipe"
patch_type: "conan"
"1.5.0":
- patch_file: "patches/1.3.10-0001-cmake-fixes.patch"
patch_description: "CMake build fixes for Conan 2.0-compatible recipe"
patch_type: "conan"
154 changes: 94 additions & 60 deletions recipes/opentdf-client/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
from conans import CMake
import os

from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.files import get, copy, patch
from conan.tools.build import check_min_cppstd
from conan.tools.scm import Version
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, export_conandata_patches, replace_in_file, get, copy
from conan.tools.microsoft import is_msvc_static_runtime
import functools
import os
from conan.tools.scm import Version

required_conan_version = ">=1.51.3"
required_conan_version = ">=1.53.0"


class OpenTDFConan(ConanFile):
name = "opentdf-client"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://www.virtru.com"
topics = ("opentdf", "opentdf-client", "tdf", "virtru")
description = "openTDF core c++ client library for creating and accessing TDF protected data"
license = "BSD-3-Clause-Clear"
generators = "cmake", "cmake_find_package"
settings = "os", "arch", "compiler", "build_type"
options = {"fPIC": [True, False]}
default_options = {"fPIC": True}
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://www.virtru.com"
topics = ("opentdf", "tdf", "virtru")

@property
def _source_subfolder(self):
return "source_subfolder"
package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
}

@property
def _build_subfolder(self):
return "build_subfolder"
def export_sources(self):
copy(self, "conan_cmake_project_include.cmake", self.recipe_folder, os.path.join(self.export_sources_folder, "src"))
export_conandata_patches(self)

@property
def _minimum_cpp_standard(self):
Expand All @@ -45,25 +48,16 @@ def _minimum_compilers_version(self):
"apple-clang": "12.0.0",
}

def export_sources(self):
self.copy("CMakeLists.txt")
for data in self.conan_data.get("patches", {}).get(self.version, []):
self.copy(data["patch_file"])
def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def validate(self):
# check minimum cpp standard supported by compiler
if self.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, self._minimum_cpp_standard)
# check minimum version of compiler
min_version = self._minimum_compilers_version.get(str(self.settings.compiler))
if not min_version:
self.output.warn(f'{self.name} recipe lacks information about the {self.settings.compiler} compiler support.')
else:
if Version(self.settings.compiler.version) < min_version:
raise ConanInvalidConfiguration(f'{self.name} requires {self.settings.compiler} {self.settings.compiler.version} but found {min_version}')
# Disallow MT and MTd
if is_msvc_static_runtime(self):
raise ConanInvalidConfiguration(f'{self.name} can not be built with MT or MTd at this time')
def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")

def layout(self):
cmake_layout(self, src_folder="src")

def requirements(self):
# Uses openssl 3.x for 1.5.0 and newer
Expand All @@ -77,55 +71,95 @@ def requirements(self):
self.requires("ms-gsl/2.1.0")
self.requires("nlohmann_json/3.11.1")
self.requires("jwt-cpp/0.4.0")
self.requires("zlib/1.2.13")
# Use newer boost+libxml2 after 1.3.6
if Version(self.version) <= "1.3.6":
self.requires("boost/1.79.0")
self.requires("libxml2/2.9.14")
else:
self.requires("boost/1.81.0")
self.requires("libxml2/2.10.3")
self.requires("boost/1.82.0")
self.requires("libxml2/2.11.4")

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
def validate(self):
if self.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, self._minimum_cpp_standard)
# check minimum version of compiler
min_version = self._minimum_compilers_version.get(str(self.settings.compiler))
if not min_version:
self.output.warning(
f"{self.name} recipe lacks information about the {self.settings.compiler} compiler support."
)
else:
if Version(self.settings.compiler.version) < min_version:
raise ConanInvalidConfiguration(
f"{self.name} requires {self.settings.compiler} {self.settings.compiler.version} "
f"but found {min_version}"
)
# Disallow MT and MTd
if is_msvc_static_runtime(self):
raise ConanInvalidConfiguration(f"{self.name} can not be built with MT or MTd at this time")

if self.options.shared and self.settings.os == "Windows":
raise ConanInvalidConfiguration(f"{self.name} does not currently support shared library on Windows")

def source(self):
get(self, **self.conan_data["sources"][self.version], destination=self._source_subfolder, strip_root=True)
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def _patch_sources(self):
for data in self.conan_data.get("patches", {}).get(self.version, []):
patch(self, **data)
def generate(self):
tc = CMakeToolchain(self)
if not self.settings.get_safe("compiler.cppstd"):
tc.variables["CMAKE_CXX_STANDARD"] = 17
tc.cache_variables["CMAKE_PROJECT_opentdf_INCLUDE"] = os.path.join(self.source_folder, "conan_cmake_project_include.cmake")
tc.generate()
tc = CMakeDeps(self)
tc.generate()

@functools.lru_cache(1)
def _configure_cmake(self):
cmake = CMake(self)
cmake.configure(build_folder=self._build_subfolder)
return cmake
def _patch_sources(self):
apply_conandata_patches(self)

def build(self):
self._patch_sources()
cmake = self._configure_cmake()
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
cmake = self._configure_cmake()
cmake = CMake(self)
cmake.install()
copy(self, "*", dst=os.path.join(self.package_folder, "lib"), src=os.path.join(os.path.join(self._source_subfolder,"tdf-lib-cpp"), "lib"), keep_path=False)
copy(self, "*", dst=os.path.join(self.package_folder, "include"), src=os.path.join(os.path.join(self._source_subfolder,"tdf-lib-cpp"), "include"), keep_path=False)
copy(self, "LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self._source_subfolder, ignore_case=True, keep_path=False)
copy(self, "*",
dst=os.path.join(self.package_folder, "lib"),
src=os.path.join(os.path.join(self.source_folder, "tdf-lib-cpp"), "lib"),
keep_path=False)
copy(self, "*",
dst=os.path.join(self.package_folder, "include"),
src=os.path.join(os.path.join(self.source_folder, "tdf-lib-cpp"), "include"),
keep_path=False)
copy(self, "LICENSE",
dst=os.path.join(self.package_folder, "licenses"),
src=self.source_folder,
ignore_case=True,
keep_path=False)

# TODO - this only advertises the static lib, add dynamic lib also
def package_info(self):
self.cpp_info.set_property("cmake_file_name", "opentdf-client")
self.cpp_info.set_property("cmake_target_name", "opentdf-client::opentdf-client")
self.cpp_info.set_property("pkg_config_name", "opentdf-client")

self.cpp_info.components["libopentdf"].libs = ["opentdf_static"]
self.cpp_info.components["libopentdf"].libs = ["opentdf_static"] if not self.options.shared else ["opentdf"]
self.cpp_info.components["libopentdf"].set_property("cmake_target_name", "copentdf-client::opentdf-client")
self.cpp_info.components["libopentdf"].names["cmake_find_package"] = "opentdf-client"
self.cpp_info.components["libopentdf"].names["cmake_find_package_multi"] = "opentdf-client"
self.cpp_info.components["libopentdf"].names["pkg_config"] = "opentdf-client"
self.cpp_info.components["libopentdf"].requires = ["openssl::openssl", "boost::boost", "ms-gsl::ms-gsl", "libxml2::libxml2", "jwt-cpp::jwt-cpp", "nlohmann_json::nlohmann_json"]
self.cpp_info.components["libopentdf"].requires = [
"openssl::openssl",
"boost::boost",
"ms-gsl::ms-gsl",
"libxml2::libxml2",
"jwt-cpp::jwt-cpp",
"nlohmann_json::nlohmann_json",
"zlib::zlib"
]
if Version(self.version) >= "1.4.0":
self.cpp_info.components["libopentdf"].requires.append("magic_enum::magic_enum")
if Version(self.version) < "1.1.0":
self.cpp_info.components["libopentdf"].requires.append("libarchive::libarchive")
if Version(self.version) >= "1.4.0":
Expand Down
51 changes: 51 additions & 0 deletions recipes/opentdf-client/all/patches/1.1.6-0001-cmake-fixes.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt
index f1ef646..2414ffc 100644
--- a/src/lib/CMakeLists.txt
+++ b/src/lib/CMakeLists.txt
@@ -99,7 +99,9 @@ set(TDF_COMBINED_LIB_FULL_PATH ${TDF_LIB_DIR}/${TDF_COMBINED_LIB_FILENAME})
message(STATUS "Combined full path: ${TDF_COMBINED_LIB_FULL_PATH}")

#TODO: Also need to handle iOS and Android(arm64).
-if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
+if(TRUE)
+ message(STATUS "Skipping generation of combined static library")
+elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")

FOREACH (LDIR ${CONAN_LIB_DIRS})
set(V_COMBINED_LIB_DIRS ${V_COMBINED_LIB_DIRS} -L${LDIR})
@@ -154,8 +156,6 @@ elseif (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
lib -out:${TDF_LIB_DIR}/${TDF_COMBINED_LIB_FILENAME} ${TDF_LIB_DIR}/${TDF_STATIC_LIB_FILENAME} ${V_COMBINED_LIB_DIRS} ${V_COMBINED_LIB_NAMES}
)
)
-else()
- message(STATUS "${CMAKE_SYSTEM_NAME} - unknown system FIXME........")
endif()

# generate the shared library from the library sources
@@ -186,16 +186,19 @@ install(DIRECTORY DESTINATION ${TDF_LIB_INSTALL_LOCATION})
# move the headers(to include) and tdf(to lib) directory under tdf-lib-cpp
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/
DESTINATION ${TDF_LIB_INSTALL_LOCATION}/include)
-
-install(FILES ${TDF_STATIC_LIB_FULL_PATH}
- DESTINATION ${TDF_LIB_INSTALL_LOCATION}/lib)

-install(FILES ${TDF_COMBINED_LIB_FULL_PATH}
- DESTINATION ${TDF_LIB_INSTALL_LOCATION}/lib)
+if(NOT BUILD_SHARED_LIBS)
+ install(FILES $<TARGET_FILE:opentdfstatic>
+ DESTINATION ${TDF_LIB_INSTALL_LOCATION}/lib)
+endif()
+
+# Skip combined static library for Conan Center Index package
+# install(FILES ${TDF_COMBINED_LIB_FULL_PATH}
+# DESTINATION ${TDF_LIB_INSTALL_LOCATION}/lib)

if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
message(STATUS "Skipping shared lib on windows")
-else()
- install(FILES ${TDF_SHARED_LIB_FULL_PATH}
+elseif(BUILD_SHARED_LIBS)
+ install(FILES $<TARGET_FILE:opentdfshared>
DESTINATION ${TDF_LIB_INSTALL_LOCATION}/lib)
endif()
51 changes: 51 additions & 0 deletions recipes/opentdf-client/all/patches/1.3.10-0001-cmake-fixes.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt
index d7e1dc1..aeb3b2c 100644
--- a/src/lib/CMakeLists.txt
+++ b/src/lib/CMakeLists.txt
@@ -99,7 +99,9 @@ set(TDF_COMBINED_LIB_FULL_PATH ${TDF_LIB_DIR}/${TDF_COMBINED_LIB_FILENAME})
message(STATUS "Combined full path: ${TDF_COMBINED_LIB_FULL_PATH}")

#TODO: Also need to handle iOS and Android(arm64).
-if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
+if(TRUE)
+ message(STATUS "Skipping generation of combined static library")
+elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")

FOREACH (LDIR ${CONAN_LIB_DIRS})
set(V_COMBINED_LIB_DIRS ${V_COMBINED_LIB_DIRS} -L${LDIR})
@@ -155,8 +157,6 @@ elseif (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
lib -out:${TDF_LIB_DIR}/${TDF_COMBINED_LIB_FILENAME} ${TDF_LIB_DIR}/${TDF_STATIC_LIB_FILENAME} ${V_COMBINED_LIB_DIRS} ${V_COMBINED_LIB_NAMES}
)
)
-else()
- message(STATUS "${CMAKE_SYSTEM_NAME} - unknown system FIXME........")
endif()

# generate the shared library from the library sources
@@ -187,16 +187,19 @@ install(DIRECTORY DESTINATION ${TDF_LIB_INSTALL_LOCATION})
# move the headers(to include) and tdf(to lib) directory under tdf-lib-cpp
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/
DESTINATION ${TDF_LIB_INSTALL_LOCATION}/include)
-
-install(FILES ${TDF_STATIC_LIB_FULL_PATH}
- DESTINATION ${TDF_LIB_INSTALL_LOCATION}/lib)

-install(FILES ${TDF_COMBINED_LIB_FULL_PATH}
- DESTINATION ${TDF_LIB_INSTALL_LOCATION}/lib)
+if(NOT BUILD_SHARED_LIBS)
+ install(FILES $<TARGET_FILE:opentdfstatic>
+ DESTINATION ${TDF_LIB_INSTALL_LOCATION}/lib)
+endif()
+
+# Skip combined static library for Conan Center Index package
+# install(FILES ${TDF_COMBINED_LIB_FULL_PATH}
+# DESTINATION ${TDF_LIB_INSTALL_LOCATION}/lib)

if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
message(STATUS "Skipping shared lib on windows")
-else()
- install(FILES ${TDF_SHARED_LIB_FULL_PATH}
+elseif(BUILD_SHARED_LIBS)
+ install(FILES $<TARGET_FILE:opentdfshared>
DESTINATION ${TDF_LIB_INSTALL_LOCATION}/lib)
endif()
Loading