Skip to content

Commit

Permalink
improve test package
Browse files Browse the repository at this point in the history
Signed-off-by: Uilian Ries <[email protected]>
  • Loading branch information
uilianries committed Feb 7, 2023
1 parent 05b856e commit 5df1128
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 46 deletions.
10 changes: 4 additions & 6 deletions recipes/openssl/1.x.x/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ project(test_package C)
option(OPENSSL_WITH_ZLIB "OpenSSL with zlib support" ON)

set(OpenSSL_DEBUG 1)
find_package(OpenSSL REQUIRED)
find_package(OpenSSL REQUIRED CONFIG)

# Test whether variables from https://cmake.org/cmake/help/latest/module/FindOpenSSL.html
# are properly defined in conan generators
Expand All @@ -26,8 +26,6 @@ foreach(_custom_var ${_custom_vars})
endif()
endforeach()

add_executable(digest digest.c)
target_link_libraries(digest OpenSSL::SSL)
if(OPENSSL_WITH_ZLIB)
target_compile_definitions(digest PRIVATE WITH_ZLIB)
endif()
add_executable(${PROJECT_NAME} digest.c)
target_link_libraries(${PROJECT_NAME} PRIVATE OpenSSL::SSL)
target_compile_definitions(${PROJECT_NAME} PRIVATE $<$<BOOL:${OPENSSL_WITH_ZLIB}>:WITH_ZLIB>)
8 changes: 3 additions & 5 deletions recipes/openssl/1.x.x/test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import os
import json

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


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
Expand All @@ -28,7 +26,7 @@ def _generate_skip_test_file(self):
# see https://github.com/conan-io/conan/pull/9839
dict_test = {"skip_test": self.settings.os == "Macos" and \
self.settings.arch == "armv8" and \
bool(self.dependencies["openssl"].options.shared)}
bool(self.dependencies[self.tested_reference_str].options.shared)}
save(self, self._skip_test_filename, json.dumps(dict_test))

@property
Expand All @@ -45,7 +43,7 @@ def generate(self):
tc = CMakeToolchain(self)
if self.settings.os == "Android":
tc.cache_variables["CONAN_LIBCXX"] = ""
openssl = self.dependencies["openssl"]
openssl = self.dependencies[self.tested_reference_str]
openssl_version = Version(openssl.ref.version)
if openssl_version.major == "1" and openssl_version.minor == "1":
tc.cache_variables["OPENSSL_WITH_ZLIB"] = False
Expand All @@ -63,5 +61,5 @@ def build(self):

def test(self):
if not self._skip_test and can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "digest")
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
32 changes: 2 additions & 30 deletions recipes/openssl/1.x.x/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,5 @@ project(test_package C)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

option(OPENSSL_WITH_ZLIB "OpenSSL with zlib support" ON)

set(OpenSSL_DEBUG 1)
find_package(OpenSSL REQUIRED)

# 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)
message(STATUS "${_custom_var}: ${${_custom_var}}")
else()
message(FATAL_ERROR "${_custom_var} not defined")
endif()
endforeach()

add_executable(digest ../test_package/digest.c)
target_link_libraries(digest OpenSSL::SSL)
if(OPENSSL_WITH_ZLIB)
target_compile_definitions(digest PRIVATE WITH_ZLIB)
endif()
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/
${CMAKE_CURRENT_BINARY_DIR}/test_package/)
7 changes: 2 additions & 5 deletions recipes/openssl/1.x.x/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
from conan.tools.build import cross_building
import os

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


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

@property
def _skip_test(self):
Expand Down Expand Up @@ -37,6 +35,5 @@ def build(self):

def test(self):
if not self._skip_test and not cross_building(self):
bin_path = os.path.join("bin", "digest")
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
assert os.path.exists(os.path.join(self.deps_cpp_info["openssl"].rootpath, "licenses", "LICENSE"))

0 comments on commit 5df1128

Please sign in to comment.