diff --git a/recipes/antlr4-cppruntime/all/CMakeLists.txt b/recipes/antlr4-cppruntime/all/CMakeLists.txt deleted file mode 100644 index 327601d6d347e..0000000000000 --- a/recipes/antlr4-cppruntime/all/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -cmake_minimum_required(VERSION 3.0) -project(cmake_wrapper) - -include(conanbuildinfo.cmake) -conan_basic_setup(KEEP_RPATHS) - -add_subdirectory(source_subfolder/runtime/Cpp) diff --git a/recipes/antlr4-cppruntime/all/conandata.yml b/recipes/antlr4-cppruntime/all/conandata.yml index 7cbac2212a675..2605966cb79dc 100644 --- a/recipes/antlr4-cppruntime/all/conandata.yml +++ b/recipes/antlr4-cppruntime/all/conandata.yml @@ -2,13 +2,38 @@ sources: "4.9.3": url: "https://github.com/antlr/antlr4/archive/refs/tags/4.9.3.tar.gz" sha256: "efe4057d75ab48145d4683100fec7f77d7f87fa258707330cadd1f8e6f7eecae" - "4.10": - url: "https://github.com/antlr/antlr4/archive/refs/tags/4.10.tar.gz" - sha256: "39b2604fc75fa77323bd7046f2fb750c818cf11fcce2cd6cca06b6697f60ffbb" "4.10.1": url: "https://github.com/antlr/antlr4/archive/refs/tags/4.10.1.tar.gz" sha256: "a320568b738e42735946bebc5d9d333170e14a251c5734e8b852ad1502efa8a2" + "4.11.1": + url: "https://github.com/antlr/antlr4/archive/refs/tags/4.11.1.tar.gz" + sha256: "81f87f03bb83b48da62e4fc8bfdaf447efb9fb3b7f19eb5cbc37f64e171218cf" patches: "4.9.3": - patch_file: "patches/0001-update-cmakelist.patch" - base_path: "source_subfolder" + - patch_file: "patches/0004-update-DropLibuuid-4.9.3-1.patch" + patch_description: "Revise the CMakeLists.txt to remove the dependency on libuuid (#1) which is not used since 4.9." + patch_type: "backport" + patch_source: "https://github.com/antlr/antlr4/pull/3787" + - patch_file: "patches/0004-update-DropLibuuid-4.9.3-2.patch" + patch_description: "Revise the CMakeLists.txt to remove the dependency on libuuid (#2) which is not used since 4.9." + patch_type: "backport" + patch_source: "https://github.com/antlr/antlr4/pull/3787" + "4.10.1": + - patch_file: "patches/0004-update-DropLibuuid-4.10.x-1.patch" + patch_description: "Revise the CMakeLists.txt to remove the dependency on libuuid (#1) which is not used since 4.9." + patch_type: "backport" + patch_source: "https://github.com/antlr/antlr4/pull/3787" + - patch_file: "patches/0004-update-DropLibuuid-4.10.x-2.patch" + patch_description: "Revise the CMakeLists.txt to remove the dependency on libuuid (#2) which is not used since 4.9." + patch_type: "backport" + patch_source: "https://github.com/antlr/antlr4/pull/3787" + "4.11.1": + - patch_file: "patches/0002-update-FlatHashSet.patch" + patch_description: "Fix the compiler errors reported by GCC 7 due to the new type FlatHashSet introduced in 4.11." + patch_type: "portability" + patch_source: "https://github.com/antlr/antlr4/pull/3885" + - patch_file: "patches/0003-update-FlatHashMap.patch" + patch_description: "Fix the compiler errors reported by GCC 7 due to the new type FlatHashMap introduced in 4.11." + patch_type: "portability" + patch_source: "https://github.com/antlr/antlr4/pull/3885" diff --git a/recipes/antlr4-cppruntime/all/conanfile.py b/recipes/antlr4-cppruntime/all/conanfile.py index 5f1d957aa04fd..e47c4f36aca6b 100644 --- a/recipes/antlr4-cppruntime/all/conanfile.py +++ b/recipes/antlr4-cppruntime/all/conanfile.py @@ -1,11 +1,14 @@ -from conan.tools.microsoft import is_msvc, is_msvc_static_runtime -from conans import ConanFile, CMake, tools -from conans.errors import ConanInvalidConfiguration -import functools +from conan import ConanFile +from conan.tools.microsoft import is_msvc, is_msvc_static_runtime, check_min_vs +from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout +from conan.tools.files import export_conandata_patches, apply_conandata_patches, get, copy, rm, rmdir, save +from conan.tools.build import check_min_cppstd +from conan.tools.scm import Version +from conan.errors import ConanInvalidConfiguration import os import textwrap -required_conan_version = ">=1.45.0" +required_conan_version = ">=1.52.0" class Antlr4CppRuntimeConan(ConanFile): @@ -15,6 +18,7 @@ class Antlr4CppRuntimeConan(ConanFile): topics = ("antlr", "parser", "runtime") url = "https://github.com/conan-io/conan-center-index" license = "BSD-3-Clause" + settings = "os", "compiler", "build_type", "arch" options = { "shared": [True, False], "fPIC": [True, False], @@ -23,30 +27,29 @@ class Antlr4CppRuntimeConan(ConanFile): "shared": False, "fPIC": True, } - settings = "os", "compiler", "build_type", "arch" - generators = "cmake", "pkg_config" short_paths = True - compiler_required_cpp17 = { - "Visual Studio": "16", + @property + def _minimum_cpp_standard(self): + # Antlr 4.9.3 requires C++11 while newer versions require C++17 + return 17 if Version(self.version) >= "4.10" else 11 + + @property + def _minimum_compiler_versions_cpp17(self): + return { "gcc": "7", "clang": "5", "apple-clang": "9.1" - } - - - @property - def _source_subfolder(self): - return "source_subfolder" + } - @property - def _build_subfolder(self): - return "build_subfolder" + def _check_minimum_compiler_version_cpp17(self): + compiler = self.info.settings.compiler + min_compiler_version = self._minimum_compiler_versions_cpp17.get(str(compiler), False) + if min_compiler_version and Version(compiler.version) < min_compiler_version: + raise ConanInvalidConfiguration(f"{self.ref} requires C++17, which your compiler does not support.") def export_sources(self): - self.copy("CMakeLists.txt") - for patch in self.conan_data.get("patches", {}).get(self.version, []): - self.copy(patch["patch_file"]) + export_conandata_patches(self) def config_options(self): if self.settings.os == "Windows": @@ -54,93 +57,74 @@ def config_options(self): def configure(self): if self.options.shared: - del self.options.fPIC + try: + del self.options.fPIC + except Exception: + pass + + def layout(self): + cmake_layout(self, src_folder="src") def requirements(self): + # As of 4.11, antlr4-cppruntime no longer requires libuuid. + # Reference: [C++] Remove libuuid dependency (https://github.com/antlr/antlr4/pull/3787) + # Note that the above PR points that libuuid can be removed from 4.9.3, 4.10 and 4.10.1 as well. + # We have patched the CMakeLists.txt to drop the dependency on libuuid from aforementioned antlr versions. self.requires("utfcpp/3.2.1") - if self.settings.os in ("FreeBSD", "Linux"): - self.requires("libuuid/1.0.3") def validate(self): - if str(self.settings.arch).startswith("arm"): - raise ConanInvalidConfiguration("arm architectures are not supported") - # Need to deal with missing libuuid on Arm. - # So far ANTLR delivers macOS binary package. - - compiler = self.settings.compiler - compiler_version = tools.Version(self.settings.compiler.version) - antlr_version = tools.Version(self.version) - - if compiler == "Visual Studio" and compiler_version < "16": - raise ConanInvalidConfiguration("library claims C2668 'Ambiguous call to overloaded function'") - # Compilation of this library on version 15 claims C2668 Error. - # This could be Bogus error or malformed Antl4 libary. - # Version 16 compiles this code correctly. - - if antlr_version >= "4.10": - # Antlr4 for 4.9.3 does not require C++17 - C++11 is enough. - # for newest version we need C++17 compatible compiler here - - if self.settings.get_safe("compiler.cppstd"): - tools.check_min_cppstd(self, "17") - - minimum_version = self.compiler_required_cpp17.get(str(self.settings.compiler), False) - if minimum_version: - if compiler_version < minimum_version: - raise ConanInvalidConfiguration("{} requires C++17, which your compiler does not support.".format(self.name)) - else: - self.output.warn("{} requires C++17. Your compiler is unknown. Assuming it supports C++17.".format(self.name)) - - if is_msvc(self) and antlr_version == "4.10": - raise ConanInvalidConfiguration("{} Antlr4 4.10 version is broken on msvc - Use 4.10.1 or above.".format(self.name)) - - def build_requirements(self): - if self.settings.os in ("FreeBSD", "Linux"): - self.build_requires("pkgconf/1.7.4") + # Compilation of this library on version 15 claims C2668 Error. + # This could be Bogus error or malformed Antlr4 library. + # Guard: The minimum MSVC version is 16 or 1920 (which already supports C++17) + check_min_vs(self, "192") + + # Check the minimum C++ standard + min_cppstd = self._minimum_cpp_standard + if self.info.settings.compiler.cppstd: + check_min_cppstd(self, min_cppstd) + # Check the minimum compiler version + if min_cppstd == 17: + self._check_minimum_compiler_version_cpp17() 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 _patch_sources(self): - for patch in self.conan_data.get("patches", {}).get(self.version, []): - tools.patch(**patch) - - @functools.lru_cache(1) - def _configure_cmake(self): - cmake = CMake(self) - cmake.definitions["ANTLR4_INSTALL"] = True - cmake.definitions["WITH_LIBCXX"] = self.settings.compiler.get_safe("libcxx") == "libc++" - cmake.definitions["ANTLR_BUILD_CPP_TESTS"] = False + def generate(self): + tc = CMakeToolchain(self) + tc.variables["ANTLR4_INSTALL"] = True + tc.variables["WITH_LIBCXX"] = self.settings.compiler.get_safe("libcxx") == "libc++" + tc.variables["ANTLR_BUILD_CPP_TESTS"] = False if is_msvc(self): - cmake.definitions["WITH_STATIC_CRT"] = is_msvc_static_runtime(self) - cmake.definitions["WITH_DEMO"] = False - cmake.configure(build_folder=self._build_subfolder) - return cmake + tc.cache_variables["WITH_STATIC_CRT"] = is_msvc_static_runtime(self) + tc.variables["WITH_DEMO"] = False + tc.generate() + tc = CMakeDeps(self) + tc.generate() def build(self): - self._patch_sources() - cmake = self._configure_cmake() + apply_conandata_patches(self) + cmake = CMake(self) + cmake.configure(build_script_folder="runtime/Cpp") cmake.build() def package(self): - self.copy("LICENSE.txt", src=self._source_subfolder, dst="licenses") - cmake = self._configure_cmake() + copy(self, "LICENSE.txt", src=os.path.join(self.source_folder), dst=os.path.join(self.package_folder, "licenses")) + cmake = CMake(self) cmake.install() if self.options.shared: - tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*antlr4-runtime-static.*") - tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*antlr4-runtime.a") + rm(self, "*antlr4-runtime-static.*", os.path.join(self.package_folder, "lib")) + rm(self, "*antlr4-runtime.a", os.path.join(self.package_folder, "lib")) else: - tools.remove_files_by_mask(os.path.join(self.package_folder, "bin"), "*.dll") - tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "antlr4-runtime.lib") - tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*antlr4-runtime.so*") - tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*antlr4-runtime.dll*") - tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*antlr4-runtime.*dylib") - tools.rmdir(os.path.join(self.package_folder, "share")) + rm(self, "*.dll", os.path.join(self.package_folder, "bin")) + rm(self, "antlr4-runtime.lib", os.path.join(self.package_folder, "lib")) + rm(self, "*antlr4-runtime.so*", os.path.join(self.package_folder, "lib")) + rm(self, "*antlr4-runtime.dll*", os.path.join(self.package_folder, "lib")) + rm(self, "*antlr4-runtime.*dylib", os.path.join(self.package_folder, "lib")) + rmdir(self, os.path.join(self.package_folder, "share")) # FIXME: this also removes lib/cmake/antlr4-generator # This cmake config script is needed to provide the cmake function `antlr4_generate` - tools.rmdir(os.path.join(self.package_folder, "lib", "cmake")) + rmdir(self, os.path.join(self.package_folder, "lib", "cmake")) # TODO: to remove in conan v2 once cmake_find_package* generatores removed self._create_cmake_module_alias_targets( @@ -148,8 +132,7 @@ def package(self): {"antlr4_shared" if self.options.shared else "antlr4_static": "antlr4-cppruntime::antlr4-cppruntime"} ) - @staticmethod - def _create_cmake_module_alias_targets(module_file, targets): + def _create_cmake_module_alias_targets(self, module_file, targets): content = "" for alias, aliased in targets.items(): content += textwrap.dedent(f"""\ @@ -158,7 +141,7 @@ def _create_cmake_module_alias_targets(module_file, targets): set_property(TARGET {alias} PROPERTY INTERFACE_LINK_LIBRARIES {aliased}) endif() """) - tools.save(module_file, content) + save(self, module_file, content) @property def _module_file_rel_path(self): diff --git a/recipes/antlr4-cppruntime/all/patches/0002-update-FlatHashSet.patch b/recipes/antlr4-cppruntime/all/patches/0002-update-FlatHashSet.patch new file mode 100644 index 0000000000000..336271b756971 --- /dev/null +++ b/recipes/antlr4-cppruntime/all/patches/0002-update-FlatHashSet.patch @@ -0,0 +1,15 @@ +--- runtime/Cpp/runtime/src/FlatHashSet.h ++++ runtime/Cpp/runtime/src/FlatHashSet.h +@@ -48,9 +48,9 @@ + using FlatHashSet = absl::flat_hash_set; + #else + template ::hasher, +- typename Equal = typename std::unordered_set::key_equal, +- typename Allocator = typename std::unordered_set::allocator_type> ++ typename Hash = std::hash, ++ typename Equal = std::equal_to, ++ typename Allocator = std::allocator> + using FlatHashSet = std::unordered_set; + #endif + diff --git a/recipes/antlr4-cppruntime/all/patches/0003-update-FlatHashMap.patch b/recipes/antlr4-cppruntime/all/patches/0003-update-FlatHashMap.patch new file mode 100644 index 0000000000000..e841ee8933643 --- /dev/null +++ b/recipes/antlr4-cppruntime/all/patches/0003-update-FlatHashMap.patch @@ -0,0 +1,15 @@ +--- runtime/Cpp/runtime/src/FlatHashMap.h ++++ runtime/Cpp/runtime/src/FlatHashMap.h +@@ -48,9 +48,9 @@ + using FlatHashMap = absl::flat_hash_map; + #else + template ::hasher, +- typename Equal = typename std::unordered_map::key_equal, +- typename Allocator = typename std::unordered_map::allocator_type> ++ typename Hash = std::hash, ++ typename Equal = std::equal_to, ++ typename Allocator = std::allocator>> + using FlatHashMap = std::unordered_map; + #endif + diff --git a/recipes/antlr4-cppruntime/all/patches/0004-update-DropLibuuid-4.10.x-1.patch b/recipes/antlr4-cppruntime/all/patches/0004-update-DropLibuuid-4.10.x-1.patch new file mode 100644 index 0000000000000..52e813be947a8 --- /dev/null +++ b/recipes/antlr4-cppruntime/all/patches/0004-update-DropLibuuid-4.10.x-1.patch @@ -0,0 +1,13 @@ +--- runtime/Cpp/CMakeLists.txt ++++ runtime/Cpp/CMakeLists.txt +@@ -41,10 +41,6 @@ + CMAKE_POLICY(SET CMP0054 OLD) + endif() + +-if(CMAKE_SYSTEM_NAME MATCHES "Linux") +- find_package(PkgConfig REQUIRED) +- pkg_check_modules(UUID REQUIRED uuid) +-endif() + if(APPLE) + find_library(COREFOUNDATION_LIBRARY CoreFoundation) + endif() diff --git a/recipes/antlr4-cppruntime/all/patches/0004-update-DropLibuuid-4.10.x-2.patch b/recipes/antlr4-cppruntime/all/patches/0004-update-DropLibuuid-4.10.x-2.patch new file mode 100644 index 0000000000000..f1fffa5599c8b --- /dev/null +++ b/recipes/antlr4-cppruntime/all/patches/0004-update-DropLibuuid-4.10.x-2.patch @@ -0,0 +1,14 @@ +--- runtime/Cpp/runtime/CMakeLists.txt ++++ runtime/Cpp/runtime/CMakeLists.txt +@@ -69,10 +69,7 @@ + gtest_discover_tests(antlr4_tests) + endif() + +-if(CMAKE_SYSTEM_NAME MATCHES "Linux") +- target_link_libraries(antlr4_shared ${UUID_LIBRARIES}) +- target_link_libraries(antlr4_static ${UUID_LIBRARIES}) +-elseif(APPLE) ++if(APPLE) + target_link_libraries(antlr4_shared ${COREFOUNDATION_LIBRARY}) + target_link_libraries(antlr4_static ${COREFOUNDATION_LIBRARY}) + endif() diff --git a/recipes/antlr4-cppruntime/all/patches/0004-update-DropLibuuid-4.9.3-1.patch b/recipes/antlr4-cppruntime/all/patches/0004-update-DropLibuuid-4.9.3-1.patch new file mode 100644 index 0000000000000..6412c93b3d0b5 --- /dev/null +++ b/recipes/antlr4-cppruntime/all/patches/0004-update-DropLibuuid-4.9.3-1.patch @@ -0,0 +1,13 @@ +--- runtime/Cpp/CMakeLists.txt ++++ runtime/Cpp/CMakeLists.txt +@@ -39,10 +39,6 @@ + CMAKE_POLICY(SET CMP0054 OLD) + endif() + +-if(CMAKE_SYSTEM_NAME MATCHES "Linux") +- find_package(PkgConfig REQUIRED) +- pkg_check_modules(UUID REQUIRED uuid) +-endif() + if(APPLE) + find_library(COREFOUNDATION_LIBRARY CoreFoundation) + endif() diff --git a/recipes/antlr4-cppruntime/all/patches/0004-update-DropLibuuid-4.9.3-2.patch b/recipes/antlr4-cppruntime/all/patches/0004-update-DropLibuuid-4.9.3-2.patch new file mode 100644 index 0000000000000..a9b062d8bea5a --- /dev/null +++ b/recipes/antlr4-cppruntime/all/patches/0004-update-DropLibuuid-4.9.3-2.patch @@ -0,0 +1,14 @@ +--- runtime/Cpp/runtime/CMakeLists.txt ++++ runtime/Cpp/runtime/CMakeLists.txt +@@ -75,10 +75,7 @@ + endif() + endif() + +-if(CMAKE_SYSTEM_NAME MATCHES "Linux") +- target_link_libraries(antlr4_shared ${UUID_LIBRARIES}) +- target_link_libraries(antlr4_static ${UUID_LIBRARIES}) +-elseif(APPLE) ++if(APPLE) + target_link_libraries(antlr4_shared ${COREFOUNDATION_LIBRARY}) + target_link_libraries(antlr4_static ${COREFOUNDATION_LIBRARY}) + endif() diff --git a/recipes/antlr4-cppruntime/all/test_package/CMakeLists.txt b/recipes/antlr4-cppruntime/all/test_package/CMakeLists.txt index 90f183c23127a..e1a9346912d37 100644 --- a/recipes/antlr4-cppruntime/all/test_package/CMakeLists.txt +++ b/recipes/antlr4-cppruntime/all/test_package/CMakeLists.txt @@ -1,9 +1,6 @@ cmake_minimum_required(VERSION 3.8) project(test_package CXX) -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup(TARGETS) - find_package(antlr4-runtime REQUIRED CONFIG) add_executable(${PROJECT_NAME} test_package.cpp) @@ -12,4 +9,4 @@ if(TARGET antlr4_shared) else() target_link_libraries(${PROJECT_NAME} PRIVATE antlr4_static) endif() -set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON) +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17) diff --git a/recipes/antlr4-cppruntime/all/test_package/conanfile.py b/recipes/antlr4-cppruntime/all/test_package/conanfile.py index 90eb89e3f2f46..a9fb96656f203 100644 --- a/recipes/antlr4-cppruntime/all/test_package/conanfile.py +++ b/recipes/antlr4-cppruntime/all/test_package/conanfile.py @@ -1,10 +1,19 @@ +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import cmake_layout, CMake import os -from conans import ConanFile, CMake, tools class TestPackageConan(ConanFile): - settings = "os", "compiler", "build_type", "arch" - generators = "cmake", "cmake_find_package_multi" + settings = "os", "arch", "compiler", "build_type" + generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv" + test_type = "explicit" + + def requirements(self): + self.requires(self.tested_reference_str) + + def layout(self): + cmake_layout(self) def build(self): cmake = CMake(self) @@ -12,6 +21,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 can_run(self): + bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package") + self.run(bin_path, env="conanrun") diff --git a/recipes/antlr4-cppruntime/all/test_v1_package/CMakeLists.txt b/recipes/antlr4-cppruntime/all/test_v1_package/CMakeLists.txt new file mode 100644 index 0000000000000..b9ee4c6f88e3f --- /dev/null +++ b/recipes/antlr4-cppruntime/all/test_v1_package/CMakeLists.txt @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 3.8) +project(test_package CXX) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup(TARGETS) + +find_package(antlr4-runtime REQUIRED CONFIG) + +add_executable(${PROJECT_NAME} ../test_package/test_package.cpp) +if(TARGET antlr4_shared) + target_link_libraries(${PROJECT_NAME} PRIVATE antlr4_shared) +else() + target_link_libraries(${PROJECT_NAME} PRIVATE antlr4_static) +endif() +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17) diff --git a/recipes/antlr4-cppruntime/all/test_v1_package/conanfile.py b/recipes/antlr4-cppruntime/all/test_v1_package/conanfile.py new file mode 100644 index 0000000000000..90eb89e3f2f46 --- /dev/null +++ b/recipes/antlr4-cppruntime/all/test_v1_package/conanfile.py @@ -0,0 +1,17 @@ +import os +from conans import ConanFile, CMake, tools + + +class TestPackageConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + 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) diff --git a/recipes/antlr4-cppruntime/config.yml b/recipes/antlr4-cppruntime/config.yml index 9b65d8dc1061b..fd8294e924d85 100644 --- a/recipes/antlr4-cppruntime/config.yml +++ b/recipes/antlr4-cppruntime/config.yml @@ -1,7 +1,7 @@ versions: "4.9.3": folder: all - "4.10": - folder: all "4.10.1": folder: all + "4.11.1": + folder: all