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

[openssl 3.x.x] fix "official" OpenSSL vars for CMakeDeps gen #14426

Closed
wants to merge 9 commits into from
24 changes: 18 additions & 6 deletions recipes/openssl/3.x.x/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,20 +660,19 @@ def package(self):
if not self.options.no_fips:
provdir = os.path.join(self._source_subfolder, "providers")
if self.settings.os == "Macos":
self.copy("fips.dylib", src=provdir,dst="lib/ossl-modules")
self.copy("fips.dylib", src=provdir, dst="lib/ossl-modules")
elif self.settings.os == "Windows":
self.copy("fips.dll", src=provdir,dst="lib/ossl-modules")
self.copy("fips.dll", src=provdir, dst="lib/ossl-modules")
else:
self.copy("fips.so", src=provdir,dst="lib/ossl-modules")
self.copy("fips.so", src=provdir, dst="lib/ossl-modules")

rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))

self._create_cmake_module_variables(
os.path.join(self.package_folder, self._module_file_rel_path)
)

@staticmethod
def _create_cmake_module_variables(module_file):
def _create_cmake_module_variables(self, module_file):
content = textwrap.dedent("""\
set(OPENSSL_FOUND TRUE)
if(DEFINED OpenSSL_INCLUDE_DIR)
Expand All @@ -685,21 +684,33 @@ def _create_cmake_module_variables(module_file):
${OpenSSL_Crypto_DEPENDENCIES}
${OpenSSL_Crypto_FRAMEWORKS}
${OpenSSL_Crypto_SYSTEM_LIBS})
elseif(DEFINED openssl_OpenSSL_Crypto_LIBS_%(config)s)
set(OPENSSL_CRYPTO_LIBRARY ${openssl_OpenSSL_Crypto_LIBS_%(config)s})
set(OPENSSL_CRYPTO_LIBRARIES ${openssl_OpenSSL_Crypto_LIBS_%(config)s}
${openssl_OpenSSL_Crypto_DEPENDENCIES_%(config)s}
${openssl_OpenSSL_Crypto_FRAMEWORKS_%(config)s}
${openssl_OpenSSL_Crypto_SYSTEM_LIBS_%(config)s})
endif()
if(DEFINED OpenSSL_SSL_LIBS)
set(OPENSSL_SSL_LIBRARY ${OpenSSL_SSL_LIBS})
set(OPENSSL_SSL_LIBRARIES ${OpenSSL_SSL_LIBS}
${OpenSSL_SSL_DEPENDENCIES}
${OpenSSL_SSL_FRAMEWORKS}
${OpenSSL_SSL_SYSTEM_LIBS})
elseif(DEFINED openssl_OpenSSL_SSL_LIBS_%(config)s)
set(OPENSSL_SSL_LIBRARY ${openssl_OpenSSL_SSL_LIBS_%(config)s})
set(OPENSSL_SSL_LIBRARIES ${openssl_OpenSSL_SSL_LIBS_%(config)s}
${openssl_OpenSSL_SSL_DEPENDENCIES_%(config)s}
${openssl_OpenSSL_SSL_FRAMEWORKS_%(config)s}
${openssl_OpenSSL_SSL_SYSTEM_LIBS_%(config)s})
endif()
if(DEFINED OpenSSL_LIBRARIES)
set(OPENSSL_LIBRARIES ${OpenSSL_LIBRARIES})
endif()
if(DEFINED OpenSSL_VERSION)
set(OPENSSL_VERSION ${OpenSSL_VERSION})
endif()
""")
""" % {"config":str(self.settings.build_type).upper()})
tools.save(module_file, content)

@property
Expand All @@ -714,6 +725,7 @@ def _module_file_rel_path(self):
def package_info(self):
self.cpp_info.set_property("cmake_file_name", "OpenSSL")
self.cpp_info.set_property("cmake_find_mode", "both")
self.cpp_info.set_property("cmake_build_modules", [self._module_file_rel_path])
self.cpp_info.set_property("pkg_config_name", "openssl")
self.cpp_info.names["cmake_find_package"] = "OpenSSL"
self.cpp_info.names["cmake_find_package_multi"] = "OpenSSL"
Expand Down
30 changes: 19 additions & 11 deletions recipes/openssl/3.x.x/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
cmake_minimum_required(VERSION 3.1)
project(test_package C)

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

option(OPENSSL_WITH_ZLIB "OpenSSL with zlib support" ON)
option(OPENSSL_WITH_LEGACY "OpenSSL with support for the legacy provider" ON)
option(OPENSSL_WITH_MD4 "OpenSSL with MD4 support (needs legacy provider)" ON)
Expand All @@ -12,14 +9,25 @@ option(OPENSSL_WITH_RIPEMD160 "OpenSSL with RIPEMD16 support (needs legacy provi
set(OpenSSL_DEBUG 1)
find_package(OpenSSL REQUIRED)

message("OPENSSL_FOUND: ${OPENSSL_FOUND}")
message("OPENSSL_INCLUDE_DIR: ${OPENSSL_INCLUDE_DIR}")
message("OPENSSL_CRYPTO_LIBRARY: ${OPENSSL_CRYPTO_LIBRARY}")
message("OPENSSL_CRYPTO_LIBRARIES: ${OPENSSL_CRYPTO_LIBRARIES}")
message("OPENSSL_SSL_LIBRARY: ${OPENSSL_SSL_LIBRARY}")
message("OPENSSL_SSL_LIBRARIES: ${OPENSSL_SSL_LIBRARIES}")
message("OPENSSL_LIBRARIES: ${OPENSSL_LIBRARIES}")
message("OPENSSL_VERSION: ${OPENSSL_VERSION}")
# Test whether variables from https://cmake.org/cmake/help/latest/module/FindOpenSSL.html
# are properly defined in conan generators
set(_custom_vars
OPENSSL_FOUND
OPENSSL_INCLUDE_DIR
OPENSSL_CRYPTO_LIBRARY
OPENSSL_CRYPTO_LIBRARIES
OPENSSL_SSL_LIBRARY
OPENSSL_SSL_LIBRARIES
OPENSSL_LIBRARIES
OPENSSL_VERSION
)
foreach(_custom_var ${_custom_vars})
if(DEFINED ${_custom_var} AND NOT "${${_custom_var}}" STREQUAL "" )
message(STATUS "${_custom_var}: ${${_custom_var}}")
else()
message(FATAL_ERROR "${_custom_var} not defined")
endif()
endforeach()

add_executable(digest digest.c)
if(OPENSSL_WITH_ZLIB)
Expand Down
55 changes: 35 additions & 20 deletions recipes/openssl/3.x.x/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,55 @@
from conans import CMake, tools, ConanFile
from conan.tools.build import cross_building
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake, CMakeToolchain
import os

required_conan_version = ">=1.50.2 <1.51.0 || >=1.51.2"


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

@property
def _with_legacy(self):
return (not self.options["openssl"].no_legacy and
((not self.options["openssl"].no_md4) or
(not self.options["openssl"].no_rmd160)))
openssl = self.dependencies["openssl"]
return (not openssl.options.no_legacy and
((not openssl.options.no_md4) or
(not openssl.options.no_rmd160)))

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

def layout(self):
cmake_layout(self)

def generate(self):
tc = CMakeToolchain(self)
openssl = self.dependencies["openssl"]
tc.cache_variables["OPENSSL_WITH_ZLIB"] = not openssl.options.no_zlib
tc.cache_variables["OPENSSL_WITH_LEGACY"] = self._with_legacy
tc.cache_variables["OPENSSL_WITH_MD4"] = not openssl.options.no_md4
tc.cache_variables["OPENSSL_WITH_RIPEMD160"] = not openssl.options.no_rmd160
if self.settings.os == "Android":
tc.cache_variables["CONAN_LIBCXX"] = ""
tc.generate()


def build(self):
cmake = CMake(self)
cmake.definitions["OPENSSL_WITH_ZLIB"] = not self.options["openssl"].no_zlib
cmake.definitions["OPENSSL_WITH_LEGACY"] = self._with_legacy()
cmake.definitions["OPENSSL_WITH_MD4"] = not self.options["openssl"].no_md4
cmake.definitions["OPENSSL_WITH_RIPEMD160"] = not self.options["openssl"].no_rmd160
if self.settings.os == "Android":
cmake.definitions["CONAN_LIBCXX"] = ""
cmake.configure()
cmake.build()

def test(self):
if not cross_building(self):
bin_path = os.path.join("bin", "digest")
self.run(bin_path, run_environment=True)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "digest")
self.run(bin_path, env="conanrun")

if not self.options["openssl"].no_legacy:
bin_legacy_path = os.path.join("bin", "digest_legacy")
bin_legacy_path = os.path.join(self.cpp.build.bindirs[0], "digest_legacy")
self.run(bin_legacy_path, run_environment=True)

if not self.options["openssl"].no_stdio:
self.run("openssl version", run_environment=True)
jngrb marked this conversation as resolved.
Show resolved Hide resolved
assert os.path.exists(os.path.join(self.deps_cpp_info["openssl"].rootpath, "licenses", "LICENSE.txt"))

for fn in ("libcrypto.pc", "libssl.pc", "openssl.pc",):
assert os.path.isfile(os.path.join(self.build_folder, fn))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you delete this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because these files are no lot generated for the CMakeDeps generator.

I would need the cmake, cmake_find_package, and pkg_config generators as for the test_v1_package test package (where this check is included).

Also compare that the *.pc files are also only checked for the 1.x.x test_v1_package, not for the 1.x.x test_package.

8 changes: 8 additions & 0 deletions recipes/openssl/3.x.x/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package C)

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

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/
${CMAKE_CURRENT_BINARY_DIR}/test_package/)
40 changes: 40 additions & 0 deletions recipes/openssl/3.x.x/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from conans import CMake, tools, ConanFile
import os


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

def _with_legacy(self):
return (not self.options["openssl"].no_legacy and
((not self.options["openssl"].no_md4) or
(not self.options["openssl"].no_rmd160)))

def build(self):
cmake = CMake(self)
cmake.definitions["OPENSSL_WITH_ZLIB"] = not self.options["openssl"].no_zlib
cmake.definitions["OPENSSL_WITH_LEGACY"] = self._with_legacy()
cmake.definitions["OPENSSL_WITH_MD4"] = not self.options["openssl"].no_md4
cmake.definitions["OPENSSL_WITH_RIPEMD160"] = not self.options["openssl"].no_rmd160
if self.settings.os == "Android":
cmake.definitions["CONAN_LIBCXX"] = ""
cmake.configure()
cmake.build()

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

if not self.options["openssl"].no_legacy:
bin_legacy_path = os.path.join("bin", "digest_legacy")
self.run(bin_legacy_path, run_environment=True)

if not self.options["openssl"].no_stdio:
self.run("openssl version", run_environment=True)
assert os.path.exists(os.path.join(self.deps_cpp_info["openssl"].rootpath, "licenses", "LICENSE.txt"))

# check for pkg_config files in build folder of this test package
for fn in ("libcrypto.pc", "libssl.pc", "openssl.pc",):
assert os.path.isfile(os.path.join(self.build_folder, fn))