Skip to content

Commit

Permalink
(#13505) oatpp-openssl: conan v2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceIm authored Oct 17, 2022
1 parent 3e2db9b commit 126c82e
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 73 deletions.
7 changes: 0 additions & 7 deletions recipes/oatpp-openssl/all/CMakeLists.txt

This file was deleted.

120 changes: 68 additions & 52 deletions recipes/oatpp-openssl/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import copy, get, rmdir
from conan.tools.microsoft import is_msvc
from conan.tools.scm import Version
import os

required_conan_version = ">=1.43.0"
required_conan_version = ">=1.51.1"


class OatppOpenSSLConan(ConanFile):
name = "oatpp-openssl"
Expand All @@ -11,82 +17,92 @@ class OatppOpenSSLConan(ConanFile):
url = "https://github.com/conan-io/conan-center-index"
description = "Oat++ OpenSSL library"
topics = ("oat++", "oatpp", "openssl")
settings = "os", "arch", "compiler", "build_type"
options = {"shared": [True, False], "fPIC": [True, False]}
default_options = {"shared": False, "fPIC": True}
generators = "cmake", "cmake_find_package"
exports_sources = "CMakeLists.txt"

_cmake = None

@property
def _source_subfolder(self):
return "source_subfolder"

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

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.shared:
del self.options.fPIC
try:
del self.options.fPIC
except Exception:
pass

def validate(self):
if self.settings.compiler.cppstd:
tools.check_min_cppstd(self, 11)

if self.settings.os == "Windows" and self.options.shared:
raise ConanInvalidConfiguration("oatpp-openssl can not be built as shared library on Windows")

if self.settings.compiler == "gcc" and tools.Version(self.settings.compiler.version) < "5":
raise ConanInvalidConfiguration("oatpp-openssl requires GCC >=5")
def layout(self):
cmake_layout(self, src_folder="src")

def requirements(self):
self.requires("oatpp/" + self.version)
self.requires("openssl/3.0.1")
self.requires(f"oatpp/{self.version}")
self.requires("openssl/3.0.5")

def source(self):
tools.get(**self.conan_data["sources"][self.version], destination=self._source_subfolder, strip_root=True)
def validate(self):
if self.info.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, 11)

def _configure_cmake(self):
if self._cmake:
return self._cmake
if is_msvc(self) and self.info.options.shared:
raise ConanInvalidConfiguration(f"{self.ref} can not be built as shared library with msvc")

self._cmake = CMake(self)
self._cmake.definitions["OATPP_BUILD_TESTS"] = False
self._cmake.definitions["OATPP_MODULES_LOCATION"] = "INSTALLED"
self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake
if self.info.settings.compiler == "gcc" and Version(self.info.settings.compiler.version) < "5":
raise ConanInvalidConfiguration(f"{self.ref} requires GCC >=5")

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

def generate(self):
tc = CMakeToolchain(self)
tc.variables["OATPP_BUILD_TESTS"] = False
tc.variables["OATPP_MODULES_LOCATION"] = "INSTALLED"
# Honor BUILD_SHARED_LIBS from conan_toolchain (see https://github.com/conan-io/conan/issues/11840)
tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0077"] = "NEW"
tc.generate()
deps = CMakeDeps(self)
deps.generate()

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

def package(self):
self.copy("LICENSE", src=self._source_subfolder, dst="licenses")
cmake = self._configure_cmake()
copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))

def package_info(self):
self.cpp_info.filenames["cmake_find_package"] = "oatpp-openssl"
self.cpp_info.filenames["cmake_find_package_multi"] = "oatpp-openssl"
self.cpp_info.set_property("cmake_file_name", "oatpp-openssl")
self.cpp_info.names["cmake_find_package"] = "oatpp"
self.cpp_info.names["cmake_find_package_multi"] = "oatpp"
self.cpp_info.set_property("cmake_target_name", "oatpp::oatpp-openssl")
self.cpp_info.components["_oatpp-openssl"].names["cmake_find_package"] = "oatpp-openssl"
self.cpp_info.components["_oatpp-openssl"].names["cmake_find_package_multi"] = "oatpp-openssl"
self.cpp_info.components["_oatpp-openssl"].set_property("cmake_target_name", "oatpp::oatpp-openssl")
# TODO: back to global scope in conan v2 once legacy generators removed
self.cpp_info.components["_oatpp-openssl"].includedirs = [
os.path.join("include", "oatpp-{}".format(self.version), "oatpp-openssl")
os.path.join("include", f"oatpp-{self.version}", "oatpp-openssl")
]
self.cpp_info.components["_oatpp-openssl"].libdirs = [os.path.join("lib", "oatpp-{}".format(self.version))]
self.cpp_info.components["_oatpp-openssl"].libdirs = [os.path.join("lib", f"oatpp-{self.version}")]
if self.settings.os == "Windows" and self.options.shared:
self.cpp_info.components["_oatpp-openssl"].bindirs = [os.path.join("bin", f"oatpp-{self.version}")]
else:
self.cpp_info.components["_oatpp-openssl"].bindirs = []
self.cpp_info.components["_oatpp-openssl"].libs = ["oatpp-openssl"]
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.components["_oatpp-openssl"].system_libs = ["pthread"]

# TODO: to remove in conan v2 once legacy generators removed
self.cpp_info.filenames["cmake_find_package"] = "oatpp-openssl"
self.cpp_info.filenames["cmake_find_package_multi"] = "oatpp-openssl"
self.cpp_info.names["cmake_find_package"] = "oatpp"
self.cpp_info.names["cmake_find_package_multi"] = "oatpp"
self.cpp_info.components["_oatpp-openssl"].names["cmake_find_package"] = "oatpp-openssl"
self.cpp_info.components["_oatpp-openssl"].names["cmake_find_package_multi"] = "oatpp-openssl"
self.cpp_info.components["_oatpp-openssl"].set_property("cmake_target_name", "oatpp::oatpp-openssl")
self.cpp_info.components["_oatpp-openssl"].requires = ["oatpp::oatpp", "openssl::openssl"]
13 changes: 4 additions & 9 deletions recipes/oatpp-openssl/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package CXX)
cmake_minimum_required(VERSION 3.8)
project(test_package LANGUAGES CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

find_package(oatpp-openssl REQUIRED)
find_package(oatpp-openssl REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)

set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)

target_link_libraries(${PROJECT_NAME} PRIVATE oatpp::oatpp-openssl)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
20 changes: 15 additions & 5 deletions recipes/oatpp-openssl/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, cmake_layout
import os

from conans import ConanFile, CMake, tools

class OatppOpenSSLTestConan(ConanFile):
class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package"
generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv"
test_type = "explicit"

def layout(self):
cmake_layout(self)

def requirements(self):
self.requires(self.tested_reference_str)

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

def test(self):
if not tools.cross_building(self):
self.run(os.path.join("bin", "test_package"), run_environment=True)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
11 changes: 11 additions & 0 deletions recipes/oatpp-openssl/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.8)
project(test_package LANGUAGES CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

find_package(oatpp-openssl REQUIRED CONFIG)

add_executable(${PROJECT_NAME} ../test_package/test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE oatpp::oatpp-openssl)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
17 changes: 17 additions & 0 deletions recipes/oatpp-openssl/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from conans import ConanFile, CMake, tools
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"

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

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)

0 comments on commit 126c82e

Please sign in to comment.