Skip to content

Commit

Permalink
Respect c++ standard if already defined
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinDelille committed Jul 22, 2022
1 parent d92ae5a commit 1cd3798
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 16 deletions.
6 changes: 6 additions & 0 deletions recipes/qxlsx/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
20 changes: 4 additions & 16 deletions recipes/qxlsx/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from conan.tools.files import apply_conandata_patches
from conans import CMake, ConanFile, tools
import functools
import os
Expand All @@ -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],
Expand All @@ -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
Expand All @@ -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()

Expand Down
32 changes: 32 additions & 0 deletions recipes/qxlsx/all/patches/0003-use-cpp17-with-qt6.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
commit e53efc535340dc74120c53b83b6462ae9144e39d
Author: Martin Delille <[email protected]>
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})
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
commit 9072fc1b7160fd67123a39cf9590db5133de51ec
Author: Martin Delille <[email protected]>
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)

0 comments on commit 1cd3798

Please sign in to comment.