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

expat: fix CMAKE_POLICY_DEFAULT_CMP0042 injection + add test_v1_package #12059

Merged
merged 11 commits into from
Aug 6, 2022
4 changes: 2 additions & 2 deletions recipes/expat/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ sources:
sha256: "42241742da97d40557857726cc4f02008cd14f2b44134c6e33af043967cd9d15"
url: "https://github.com/libexpat/libexpat/releases/download/R_2_2_7/expat-2.2.7.tar.gz"
patches:
"2.3.0":
- patch_file: "patches/0001-2.3.0-relax-vs-restriction.patch"
"2.2.7":
- patch_file: "patches/0002-2.2.7-fix-set-cmake-policies.patch"
patch_description: "cmake_minimum_required(VERSION) should be called before project() for cmake policies to work"
patch_type: "conan"
"2.3.0":
- patch_file: "patches/0001-2.3.0-relax-vs-restriction.patch"
31 changes: 17 additions & 14 deletions recipes/expat/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from conan import ConanFile, tools
from conan.tools.cmake import CMake, CMakeToolchain
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, collect_libs, copy, rmdir
from conan.tools.microsoft import msvc_runtime_flag, is_msvc
from conan.tools.microsoft import is_msvc, is_msvc_static_runtime
from conan.tools.scm import Version
import os

required_conan_version = ">=1.47.0"
required_conan_version = ">=1.50.0"


class ExpatConan(ConanFile):
Expand Down Expand Up @@ -44,6 +44,9 @@ def configure(self):
del self.settings.compiler.libcxx
del self.settings.compiler.cppstd

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

def source(self):
tools.files.get(self,
**self.conan_data["sources"][self.version],
Expand All @@ -54,24 +57,24 @@ def source(self):
def generate(self):
tc = CMakeToolchain(self)
if Version(self.version) < "2.2.8":
tc.variables["BUILD_doc"] = "Off"
tc.variables["BUILD_examples"] = "Off"
tc.variables["BUILD_doc"] = False
tc.variables["BUILD_examples"] = False
tc.variables["BUILD_shared"] = self.options.shared
tc.variables["BUILD_tests"] = "Off"
tc.variables["BUILD_tools"] = "Off"
tc.variables["BUILD_tests"] = False
tc.variables["BUILD_tools"] = False
# Generate a relocatable shared lib on Macos
tc.variables["CMAKE_POLICY_DEFAULT_CMP0042"] = "NEW"
tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0042"] = "NEW"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

requires conan 1.50.0: conan-io/conan@a5eab30

else:
# These options were renamed in 2.2.8 to be more consistent
tc.variables["EXPAT_BUILD_DOCS"] = "Off"
tc.variables["EXPAT_BUILD_EXAMPLES"] = "Off"
tc.variables["EXPAT_BUILD_DOCS"] = False
tc.variables["EXPAT_BUILD_EXAMPLES"] = False
tc.variables["EXPAT_SHARED_LIBS"] = self.options.shared
tc.variables["EXPAT_BUILD_TESTS"] = "Off"
tc.variables["EXPAT_BUILD_TOOLS"] = "Off"
tc.variables["EXPAT_BUILD_TESTS"] = False
tc.variables["EXPAT_BUILD_TOOLS"] = False
# EXPAT_CHAR_TYPE was added in 2.2.8
tc.variables["EXPAT_CHAR_TYPE"] = self.options.char_type
if is_msvc(self):
tc.variables["EXPAT_MSVC_STATIC_CRT"] = "MT" in msvc_runtime_flag(self)
tc.variables["EXPAT_MSVC_STATIC_CRT"] = is_msvc_static_runtime(self)
if Version(self.version) >= "2.2.10":
tc.variables["EXPAT_BUILD_PKGCONFIG"] = False
tc.generate()
Expand All @@ -83,7 +86,7 @@ def build(self):
cmake.build()

def package(self):
copy(self, "COPYING", self.build_folder, os.path.join(self.package_folder, "licenses"))
copy(self, "COPYING", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
Expand Down
10 changes: 10 additions & 0 deletions recipes/expat/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.1)
project(test_package LANGUAGES C)

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

find_package(EXPAT REQUIRED)

add_executable(${PROJECT_NAME} ../test_package/test_package.c)
target_link_libraries(${PROJECT_NAME} PRIVATE EXPAT::EXPAT)
18 changes: 18 additions & 0 deletions recipes/expat/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# pylint: skip-file
from conans import ConanFile, CMake, tools
import os


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

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)