diff --git a/recipes/re2/all/CMakeLists.txt b/recipes/re2/all/CMakeLists.txt deleted file mode 100644 index b71c882d9d33f..0000000000000 --- a/recipes/re2/all/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -cmake_minimum_required(VERSION 3.1) -project(cmake_wrapper) - -include(conanbuildinfo.cmake) -conan_basic_setup(KEEP_RPATHS) - -add_subdirectory(source_subfolder) diff --git a/recipes/re2/all/conanfile.py b/recipes/re2/all/conanfile.py index d340ff47082d4..fa0b9e1fcd233 100644 --- a/recipes/re2/all/conanfile.py +++ b/recipes/re2/all/conanfile.py @@ -1,7 +1,10 @@ -from conans import ConanFile, CMake, tools +from conan import ConanFile +from conan.tools.build import check_min_cppstd +from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout +from conan.tools.files import copy, get, rmdir import os -required_conan_version = ">=1.43.0" +required_conan_version = ">=1.50.0" class Re2Conan(ConanFile): @@ -22,18 +25,6 @@ class Re2Conan(ConanFile): "fPIC": True } - exports_sources = "CMakeLists.txt" - generators = "cmake" - _cmake = None - - @property - def _source_subfolder(self): - return "source_subfolder" - - @property - def _build_subfolder(self): - return "build_subfolder" - def config_options(self): if self.settings.os == "Windows": del self.options.fPIC @@ -43,38 +34,37 @@ def configure(self): del self.options.fPIC def validate(self): - if self.settings.compiler.get_safe("cppstd"): - tools.check_min_cppstd(self, 11) + if self.info.settings.compiler.cppstd: + check_min_cppstd(self, 11) + + def layout(self): + cmake_layout(self, src_folder="src") def source(self): - tools.get(**self.conan_data["sources"][self.version], - destination=self._source_subfolder, strip_root=True) + get(self, **self.conan_data["sources"][self.version], + destination=self.source_folder, strip_root=True) - def _configure_cmake(self): - if self._cmake: - return self._cmake - self._cmake = CMake(self) - self._cmake.definitions["RE2_BUILD_TESTING"] = False - self._cmake.configure(build_folder=self._build_subfolder) - return self._cmake + def generate(self): + tc = CMakeToolchain(self) + tc.variables["RE2_BUILD_TESTING"] = False + # 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() 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", keep_path=False) - 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.set_property("cmake_file_name", "re2") self.cpp_info.set_property("cmake_target_name", "re2::re2") - - self.cpp_info.names["cmake_find_package"] = "re2" - self.cpp_info.names["cmake_find_package_multi"] = "re2" - self.cpp_info.libs = ["re2"] if self.settings.os in ["Linux", "FreeBSD"]: self.cpp_info.system_libs = ["m", "pthread"] diff --git a/recipes/re2/all/test_package/CMakeLists.txt b/recipes/re2/all/test_package/CMakeLists.txt index a9f47b21aa812..dee70b6be9bd8 100644 --- a/recipes/re2/all/test_package/CMakeLists.txt +++ b/recipes/re2/all/test_package/CMakeLists.txt @@ -1,11 +1,8 @@ -cmake_minimum_required(VERSION 3.1) -project(test_package) - -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup(TARGETS) +cmake_minimum_required(VERSION 3.8) +project(test_package LANGUAGES CXX) find_package(re2 REQUIRED CONFIG) add_executable(${PROJECT_NAME} test_package.cpp) -target_link_libraries(${PROJECT_NAME} re2::re2) -set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11) +target_link_libraries(${PROJECT_NAME} PRIVATE re2::re2) +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) diff --git a/recipes/re2/all/test_package/conanfile.py b/recipes/re2/all/test_package/conanfile.py index 38f4483872d47..3a8c6c5442b33 100644 --- a/recipes/re2/all/test_package/conanfile.py +++ b/recipes/re2/all/test_package/conanfile.py @@ -1,10 +1,18 @@ -from conans import ConanFile, CMake, tools +from conan import ConanFile +from conan.tools.build import cross_building +from conan.tools.cmake import CMake, cmake_layout import os class TestPackageConan(ConanFile): settings = "os", "arch", "compiler", "build_type" - generators = "cmake", "cmake_find_package_multi" + generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv" + + def requirements(self): + self.requires(self.tested_reference_str) + + def layout(self): + cmake_layout(self) def build(self): cmake = CMake(self) @@ -12,6 +20,6 @@ def build(self): 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) + if not cross_building(self): + bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package") + self.run(bin_path, env="conanrun") diff --git a/recipes/re2/all/test_v1_package/CMakeLists.txt b/recipes/re2/all/test_v1_package/CMakeLists.txt new file mode 100644 index 0000000000000..40160fdcc3440 --- /dev/null +++ b/recipes/re2/all/test_v1_package/CMakeLists.txt @@ -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(re2 REQUIRED CONFIG) + +add_executable(${PROJECT_NAME} ../test_package/test_package.cpp) +target_link_libraries(${PROJECT_NAME} PRIVATE re2::re2) +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) diff --git a/recipes/re2/all/test_v1_package/conanfile.py b/recipes/re2/all/test_v1_package/conanfile.py new file mode 100644 index 0000000000000..75c0cd81d2d2f --- /dev/null +++ b/recipes/re2/all/test_v1_package/conanfile.py @@ -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_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)