Repository: conan-io/conan-center-index

Issue:
[request] Perfetto/31.0
### Package Details
  * Package Name/Version: ** Perfetto/31.0**
  * Changelog: **https://github.com/google/perfetto/releases/tag/v31.0**


The above mentioned version is newly released by the upstream project and not yet available as a recipe. Please add this version.

**Pr follows**
```
v31.0 - 2022-11-10:
  Tracing service and probes:
    * Added support for collecting Android Trusty ftrace events.
    * Fixed resetting syscall filter when recording selected syscalls.
  Trace Processor:
    * Improved error messages on SQL syntax errors.
    * Improved performance of queries containing GLOB. Handling of GLOB
      constraints now happens inside trace processor instead of SQLite.
    * Added support for parsing Android Trusty ftrace events.
  UI:
    * Added support for metatracing UI code and integrate with trace processor
      metatracing.
    * Added support for scrolling to a time region using the postMessage API.
    * Enabled Pivot table functionality by default.
    * Fixed downloading of Java heap profiles.
  SDK:
    * Switched to require C++17 by default. A time-limited opt-out exists but
      is planned to be removed in v34. Please contact us at
      perfetto-dev@googlegroups.com if you have thoughts or concerns on this
      move.
```


Discussion:

Resolving patch:
diff --git a/recipes/perfetto/all/conanfile.py b/recipes/perfetto/all/conanfile.py
--- a/recipes/perfetto/all/conanfile.py
+++ b/recipes/perfetto/all/conanfile.py
@@ -3,6 +3,7 @@
 from conan.tools.build import check_min_cppstd
 from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
 from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get
+from conan.tools.microsoft import is_msvc
 from conan.tools.scm import Version
 import os
 
@@ -30,6 +31,20 @@ class PerfettoConan(ConanFile):
 
     short_paths = True
 
+    @property
+    def _minimum_cpp_standard(self):
+        return 11 if Version(self.version) < "31.0" else 17
+
+    @property
+    def _minimum_compilers_version(self):
+        return {
+            "Visual Studio": "15" if Version(self.version) < "31.0" else "16",
+            "msvc": "190",
+            "gcc": "7",
+            "clang": "3.3" if Version(self.version) < "31.0" else "5",
+            "apple-clang": "5.0" if Version(self.version) < "31.0" else "9.1",
+        }
+
     def export_sources(self):
         copy(self, "CMakeLists.txt", src=self.recipe_folder, dst=self.export_sources_folder)
         export_conandata_patches(self)
@@ -46,10 +61,21 @@ def layout(self):
         cmake_layout(self, src_folder="src")
 
     def validate(self):
-        if self.info.settings.compiler == "gcc" and Version(self.info.settings.compiler.version) < 7:
-            raise ConanInvalidConfiguration ("perfetto requires gcc >= 7")
         if self.info.settings.compiler.get_safe("cppstd"):
-            check_min_cppstd(self, 11)
+            check_min_cppstd(self, self._minimum_cpp_standard)
+
+        def loose_lt_semver(v1, v2):
+            lv1 = [int(v) for v in v1.split(".")]
+            lv2 = [int(v) for v in v2.split(".")]
+            min_length = min(len(lv1), len(lv2))
+            return lv1[:min_length] < lv2[:min_length]
+
+        compiler = self.info.settings.compiler
+        min_version = self._minimum_compilers_version.get(str(compiler))
+        if min_version and loose_lt_semver(str(compiler.version), min_version):
+            raise ConanInvalidConfiguration(
+                f"{self.ref} requires {compiler} {min_version}. The current compiler is {compiler} {compiler.version}."
+            )
 
     def source(self):
         get(self, **self.conan_data["sources"][self.version],
@@ -59,6 +85,7 @@ def generate(self):
         tc = CMakeToolchain(self)
         tc.variables["PERFETTO_SRC_DIR"] = self.source_folder.replace("\\", "/")
         tc.variables["PERFETTO_DISABLE_LOGGING"] = self.options.disable_logging
+        tc.variables["PERFETTO_CXX_STANDARD"] = f"cxx_std_{self._minimum_cpp_standard}"
         tc.generate()
 
     def build(self):
@@ -78,4 +105,6 @@ def package_info(self):
             self.cpp_info.system_libs.append("pthread")
         if self.settings.os == "Windows":
             self.cpp_info.system_libs.append("ws2_32")
+        if is_msvc(self):
+            self.cpp_info.cxxflags.append("/Zc:__cplusplus")
 


Test patch:
diff --git a/recipes/perfetto/all/test_package/CMakeLists.txt b/recipes/perfetto/all/test_package/CMakeLists.txt
--- a/recipes/perfetto/all/test_package/CMakeLists.txt
+++ b/recipes/perfetto/all/test_package/CMakeLists.txt
@@ -4,5 +4,9 @@ project(test_package LANGUAGES CXX)
 find_package(perfetto REQUIRED CONFIG)
 
 add_executable(${PROJECT_NAME} test_package.cpp)
-target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
+if(perfetto_VERSION VERSION_LESS "31.0")
+    target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
+else()
+    target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
+endif()
 target_link_libraries(${PROJECT_NAME} PRIVATE perfetto::perfetto)