Skip to content

Commit

Permalink
openssl/3.x.x: port conan-io#4597 provide official variables in cmake…
Browse files Browse the repository at this point in the history
…_find_package

Co-Authored-By: SpaceIm <[email protected]>
  • Loading branch information
Croydon and SpaceIm committed Sep 9, 2021
1 parent 435c6e4 commit 1358200
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
49 changes: 49 additions & 0 deletions recipes/openssl/3.x.x/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,10 +586,59 @@ def package(self):

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

self._create_cmake_module_variables(
os.path.join(self.package_folder, self._module_subfolder, self._module_file)
)

@staticmethod
def _create_cmake_module_variables(module_file):
content = """\
if(DEFINED OpenSSL_FOUND)
set(OPENSSL_FOUND ${OpenSSL_FOUND})
endif()
if(DEFINED OpenSSL_INCLUDE_DIR)
set(OPENSSL_INCLUDE_DIR ${OpenSSL_INCLUDE_DIR})
endif()
if(DEFINED OpenSSL_Crypto_LIBS)
set(OPENSSL_CRYPTO_LIBRARY ${OpenSSL_Crypto_LIBS})
set(OPENSSL_CRYPTO_LIBRARIES ${OpenSSL_Crypto_LIBS}
${OpenSSL_Crypto_DEPENDENCIES}
${OpenSSL_Crypto_FRAMEWORKS}
${OpenSSL_Crypto_SYSTEM_LIBS})
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})
endif()
if(DEFINED OpenSSL_LIBRARIES)
set(OPENSSL_LIBRARIES ${OpenSSL_LIBRARIES})
endif()
if(DEFINED OpenSSL_VERSION)
set(OPENSSL_VERSION ${OpenSSL_VERSION})
endif()
"""
content = textwrap.dedent(content)
tools.save(module_file, content)

@property
def _module_subfolder(self):
return os.path.join("lib", "cmake")

@property
def _module_file(self):
return "conan-official-{}-variables.cmake".format(self.name)

def package_info(self):
self.cpp_info.names["cmake_find_package"] = "OpenSSL"
self.cpp_info.names["cmake_find_package_multi"] = "OpenSSL"
self.cpp_info.names["pkg_config"] = "openssl"
self.cpp_info.components["ssl"].builddirs = [self._module_subfolder]
self.cpp_info.components["ssl"].build_modules = [os.path.join(self._module_subfolder, self._module_file)]
self.cpp_info.components["crypto"].builddirs = [self._module_subfolder]
self.cpp_info.components["crypto"].build_modules = [os.path.join(self._module_subfolder, self._module_file)]
if self._use_nmake:
libsuffix = "d" if self.settings.build_type == "Debug" else ""
self.cpp_info.components["ssl"].libs = ["libssl" + libsuffix]
Expand Down
10 changes: 9 additions & 1 deletion recipes/openssl/3.x.x/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ endif()

set(OpenSSL_DEBUG 1)
find_package(OpenSSL REQUIRED)
message("LINK WITH ${OpenSSL_LIBRARIES}")

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}")

target_link_libraries(digest OpenSSL::Crypto)

0 comments on commit 1358200

Please sign in to comment.