From 1cd379890f417a7061fe29811e64bb31ad5cbd16 Mon Sep 17 00:00:00 2001 From: Martin Delille Date: Fri, 22 Jul 2022 11:04:54 +0200 Subject: [PATCH] Respect c++ standard if already defined --- recipes/qxlsx/all/conandata.yml | 6 ++++ recipes/qxlsx/all/conanfile.py | 20 +++--------- .../all/patches/0003-use-cpp17-with-qt6.patch | 32 +++++++++++++++++++ ...04-defined-cpp-standard-only-if-need.patch | 25 +++++++++++++++ 4 files changed, 67 insertions(+), 16 deletions(-) create mode 100644 recipes/qxlsx/all/patches/0003-use-cpp17-with-qt6.patch create mode 100644 recipes/qxlsx/all/patches/0004-defined-cpp-standard-only-if-need.patch diff --git a/recipes/qxlsx/all/conandata.yml b/recipes/qxlsx/all/conandata.yml index d782241073cad..6f4a9a48d2a08 100644 --- a/recipes/qxlsx/all/conandata.yml +++ b/recipes/qxlsx/all/conandata.yml @@ -8,3 +8,9 @@ patches: base_path: "source_subfolder" - patch_file: "patches/0002-add-install-target.patch" base_path: "source_subfolder" + - patch_file: "patches/0003-use-cpp17-with-qt6.patch" + base_path: "source_subfolder" + patch_source: "https://github.com/QtExcel/QXlsx/pull/223" + - patch_file: "patches/0004-defined-cpp-standard-only-if-need.patch" + base_path: "source_subfolder" + patch_source: "https://github.com/QtExcel/QXlsx/pull/226" diff --git a/recipes/qxlsx/all/conanfile.py b/recipes/qxlsx/all/conanfile.py index 2c24b82bc2cad..66c2a65e43e48 100644 --- a/recipes/qxlsx/all/conanfile.py +++ b/recipes/qxlsx/all/conanfile.py @@ -1,3 +1,4 @@ +from conan.tools.files import apply_conandata_patches from conans import CMake, ConanFile, tools import functools import os @@ -12,7 +13,7 @@ class QXlsxConan(ConanFile): topics = ("qxlsx", "excel", "xlsx") homepage = "https://github.com/QtExcel/QXlsx" url = "https://github.com/conan-io/conan-center-index" - + exports_sources = ["CMakeLists.txt", "patches/**"] settings = "os", "arch", "compiler", "build_type" options = { "shared": [True, False], @@ -29,15 +30,6 @@ class QXlsxConan(ConanFile): def _source_subfolder(self): return "source_subfolder" - @property - def _qt_major(self): - return tools.Version(self.deps_cpp_info["qt"].version).major - - def export_sources(self): - self.copy("CMakeLists.txt") - for patch in self.conan_data.get("patches", {}).get(self.version, []): - self.copy(patch["patch_file"]) - def config_options(self): if self.settings.os == "Windows": del self.options.fPIC @@ -56,16 +48,12 @@ def source(self): @functools.lru_cache(1) def _configure_cmake(self): cmake = CMake(self) - cmake.definitions["QT_VERSION_MAJOR"] = self._qt_major + cmake.definitions["QT_VERSION_MAJOR"] = tools.Version(self.deps_cpp_info["qt"].version).major cmake.configure() return cmake def build(self): - for patch in self.conan_data.get("patches", {}).get(self.version, []): - tools.patch(**patch) - if self._qt_major != "5": - tools.replace_in_file(os.path.join(self._source_subfolder, "QXlsx", "CMakeLists.txt"), - "CMAKE_CXX_STANDARD 11", "CMAKE_CXX_STANDARD 17") + apply_conandata_patches(self) cmake = self._configure_cmake() cmake.build() diff --git a/recipes/qxlsx/all/patches/0003-use-cpp17-with-qt6.patch b/recipes/qxlsx/all/patches/0003-use-cpp17-with-qt6.patch new file mode 100644 index 0000000000000..bb690d6e9b293 --- /dev/null +++ b/recipes/qxlsx/all/patches/0003-use-cpp17-with-qt6.patch @@ -0,0 +1,32 @@ +commit e53efc535340dc74120c53b83b6462ae9144e39d +Author: Martin Delille +Date: Tue Jul 5 10:33:47 2022 +0200 + + Use c++17 when using Qt 6 + +diff --git a/QXlsx/CMakeLists.txt b/QXlsx/CMakeLists.txt +index d82b479..527866c 100644 +--- a/QXlsx/CMakeLists.txt ++++ b/QXlsx/CMakeLists.txt +@@ -11,14 +11,18 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) + + set(CMAKE_AUTOMOC ON) + +-set(CMAKE_CXX_STANDARD 11) +-set(CMAKE_CXX_STANDARD_REQUIRED ON) +- + include(GNUInstallDirs) + + find_package(QT NAMES Qt6 Qt5 COMPONENTS Core Gui REQUIRED) + find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Gui REQUIRED) + ++if (QT_MAJOR_VERSION EQUAL 6) ++ set(CMAKE_CXX_STANDARD 17) ++else() ++ set(CMAKE_CXX_STANDARD 11) ++endif() ++set(CMAKE_CXX_STANDARD_REQUIRED ON) ++ + set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules) + + if(NOT DEFINED ${QXLSX_PARENTPATH}) diff --git a/recipes/qxlsx/all/patches/0004-defined-cpp-standard-only-if-need.patch b/recipes/qxlsx/all/patches/0004-defined-cpp-standard-only-if-need.patch new file mode 100644 index 0000000000000..0f913de90aa00 --- /dev/null +++ b/recipes/qxlsx/all/patches/0004-defined-cpp-standard-only-if-need.patch @@ -0,0 +1,25 @@ +commit 9072fc1b7160fd67123a39cf9590db5133de51ec +Author: Martin Delille +Date: Fri Jul 22 10:21:54 2022 +0200 + + Define cpp standard only if not defined + +diff --git a/QXlsx/CMakeLists.txt b/QXlsx/CMakeLists.txt +index 527866c..7e59cc5 100644 +--- a/QXlsx/CMakeLists.txt ++++ b/QXlsx/CMakeLists.txt +@@ -16,10 +16,12 @@ include(GNUInstallDirs) + find_package(QT NAMES Qt6 Qt5 COMPONENTS Core Gui REQUIRED) + find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Gui REQUIRED) + +-if (QT_MAJOR_VERSION EQUAL 6) ++if(NOT CMAKE_CXX_STANDARD) ++ if (QT_MAJOR_VERSION EQUAL 6) + set(CMAKE_CXX_STANDARD 17) +-else() ++ else() + set(CMAKE_CXX_STANDARD 11) ++ endif() + endif() + set(CMAKE_CXX_STANDARD_REQUIRED ON) +