Skip to content

Commit

Permalink
Merge branch 'master' into update-libpng-in-qt-22654
Browse files Browse the repository at this point in the history
  • Loading branch information
dheater authored Feb 6, 2024
2 parents f9587a6 + 52526d5 commit d532ba7
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 48 deletions.
14 changes: 7 additions & 7 deletions recipes/scnlib/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
sources:
"2.0.0":
url: "https://github.com/eliaskosunen/scnlib/archive/refs/tags/v2.0.0.tar.gz"
sha256: "2a35356a3a7485fdf97f28cfbea52db077cf4e7bab0a5a0fc3b04e89630334cd"
"1.1.3":
url: "https://github.com/eliaskosunen/scnlib/archive/refs/tags/v1.1.3.tar.gz"
sha256: "32ca1baed2da5d86aa03273c87580ef32e95925697d252138507ec0545d86ab2"
Expand All @@ -8,10 +11,11 @@ sources:
"1.0":
url: "https://github.com/eliaskosunen/scnlib/archive/refs/tags/v1.0.tar.gz"
sha256: "5b8333e522206c2a74e57a9c9544c4fe4e7858cfe93e216905b463eaf91af5fe"
"0.4":
url: "https://github.com/eliaskosunen/scnlib/archive/refs/tags/v0.4.tar.gz"
sha256: "f23e66b00c9d38671b39b83c082a5b2db1cf05b3e3eff7b4a769487d9ed9d366"
patches:
"2.0.0":
- patch_file: "patches/2.0.0-0001-remove-re2-version.patch"
patch_description: "remove re2 version on find_package"
patch_type: "portability"
"1.1.3":
- patch_file: "patches/1.1.3-0001-install-dll-windows.patch"
patch_description: "add runtime destination path on install"
Expand Down Expand Up @@ -42,7 +46,3 @@ patches:
- patch_file: "patches/1.0-0003-use-conan-package.patch"
patch_description: "use conan package of fast-float"
patch_type: "conan"
"0.4":
- patch_file: "patches/0.4-0001-install-dll-windows.patch"
patch_description: "add runtime destination path on install"
patch_type: "portability"
110 changes: 86 additions & 24 deletions recipes/scnlib/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from conan import ConanFile
from conan.tools.microsoft import check_min_vs
from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy, rm, rmdir
from conan.tools.build import check_min_cppstd
from conan.tools.scm import Version
from conan.tools.layout import basic_layout
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.microsoft import is_msvc
from conan.errors import ConanInvalidConfiguration

import os

Expand All @@ -23,54 +24,102 @@ class ScnlibConan(ConanFile):
"header_only": [True, False],
"shared": [True, False],
"fPIC": [True, False],
"regex_backend": ["None", "std", "boost", "boost_icu", "re2"],
}
default_options = {
"header_only": False,
"shared": False,
"fPIC": True,
"regex_backend": "std",
}

@property
def _min_cppstd(self):
return 11
if Version(self.version) < "2.0.0":
return "11"
else:
# scn/2.0.0 has complation error on MSVC c++17
# we have to use versions which support c++20
# https://github.com/eliaskosunen/scnlib/issues/97
# https://github.com/conan-io/conan-center-index/pull/22455#issuecomment-1924444193
return "20" if is_msvc(self) else "17"

@property
def _compilers_minimum_version(self):
return {
"17": {
"gcc": "8",
"clang": "7",
# scn/2.0.0 requires std::regex_constants::multiline
"apple-clang": "14",
},
"20": {
"Visual Studio": "17",
"msvc": "193",
}
}.get(self._min_cppstd, {})

def export_sources(self):
export_conandata_patches(self)

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
if Version(self.version) < "2.0":
del self.options.regex_backend

def configure(self):
if self.options.header_only or self.options.shared:
if self.options.get_safe("header_only") or self.options.shared:
self.options.rm_safe("fPIC")
if self.options.header_only:
if self.options.get_safe("header_only"):
del self.options.shared
self.package_type = "header-library"

def layout(self):
if self.options.header_only:
if self.options.get_safe("header_only"):
basic_layout(self, src_folder="src")
else:
cmake_layout(self, src_folder="src")

def requirements(self):
if Version(self.version) >= "1.0":
self.requires("fast_float/6.0.0")
self.requires("fast_float/6.1.0")
if Version(self.version) >= "2.0":
self.requires("simdutf/4.0.5")
if self.options.get_safe("regex_backend") in ["boost", "boost_icu"]:
self.requires("boost/1.83.0")
elif self.options.get_safe("regex_backend") == "re2":
self.requires("re2/20231101")

def package_id(self):
if self.info.options.get_safe("header_only"):
self.info.clear()

def validate(self):
if self.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, self._min_cppstd)
check_min_vs(self, 192 if Version(self.version) >= "1.0" else 191)

def package_id(self):
if self.info.options.header_only:
self.info.clear()
minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
if minimum_version and Version(self.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration(
f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support."
)
if self.options.get_safe("regex_backend") == "boost_icu" and \
not self.dependencies["boost"].options.get_safe("i18n_backend_icu"):
raise ConanInvalidConfiguration(
f"{self.ref} with regex_backend=Boost_icu option requires boost::i18n_backend_icu to be enabled."
)
if Version(self.version) >= "2.0.0" and self.options.header_only:
raise ConanInvalidConfiguration(f"{self.ref} doesn't support header only mode.")
if Version(self.version) >= "2.0.0" and self.settings.compiler == "gcc" and Version(self.settings.compiler.version).major == "11":
raise ConanInvalidConfiguration(f"{self.ref} doesn't support gcc 11.x due to std::regex_constants::multiline is not defined.")

def build_requirements(self):
self.tool_requires("cmake/[>=3.16 <4]")

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
if self.options.header_only:
if self.options.get_safe("header_only"):
return

tc = CMakeToolchain(self)
Expand All @@ -80,23 +129,32 @@ def generate(self):
tc.variables["SCN_DOCS"] = False
tc.variables["SCN_INSTALL"] = True
tc.variables["CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS"] = True
if Version(self.version) >= "1.0":
if Version(self.version) < "2.0":
tc.variables["SCN_USE_BUNDLED_FAST_FLOAT"] = False
else:
tc.variables["SCN_USE_EXTERNAL_SIMDUTF"] = True
tc.variables["SCN_USE_EXTERNAL_FAST_FLOAT"] = True
tc.variables["SCN_BENCHMARKS_BUILDTIME"] = False
tc.variables["SCN_BENCHMARKS_BINARYSIZE"] = False
tc.variables["SCN_DISABLE_REGEX"] = self.options.regex_backend is None
if self.options.regex_backend is not None:
tc.variables["SCN_REGEX_BACKEND"] = self.options.regex_backend
tc.variables["SCN_USE_EXTERNAL_REGEX_BACKEND"] = True
tc.generate()

deps = CMakeDeps(self)
deps.generate()

def build(self):
apply_conandata_patches(self)
if not self.options.header_only:
if not self.options.get_safe("header_only"):
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
copy(self, pattern="LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
if self.options.header_only:
if self.options.get_safe("header_only"):
copy(self, "*", dst=os.path.join(self.package_folder, "include"), src=os.path.join(self.source_folder, "include"))
src_folder = os.path.join(self.source_folder, "src")
if Version(self.version) >= "1.0":
Expand All @@ -111,23 +169,27 @@ def package(self):
cmake.install()
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
rmdir(self, os.path.join(self.package_folder, "share"))
if Version(self.version) >= "1.0":
rm(self, "*.cmake", os.path.join(self.package_folder, "include", "scn", "detail"))
rmdir(self, os.path.join(self.package_folder, "include", "scn", "detail", "CMakeFiles"))
rmdir(self, os.path.join(self.package_folder, "include", "scn", "detail", "deps", "CMakeFiles"))
rm(self, "*.cmake", os.path.join(self.package_folder, "include", "scn", "detail"))
rmdir(self, os.path.join(self.package_folder, "include", "scn", "detail", "CMakeFiles"))
rmdir(self, os.path.join(self.package_folder, "include", "scn", "detail", "deps", "CMakeFiles"))

def package_info(self):
target = "scn-header-only" if self.options.header_only else "scn"
target = "scn-header-only" if self.options.get_safe("header_only") else "scn"
self.cpp_info.set_property("cmake_file_name", "scn")
self.cpp_info.set_property("cmake_target_name", f"scn::{target}")
# TODO: back to global scope in conan v2 once cmake_find_package* generators removed
if self.options.header_only:
if self.options.get_safe("header_only"):
self.cpp_info.components["_scnlib"].defines = ["SCN_HEADER_ONLY=1"]
else:
self.cpp_info.components["_scnlib"].defines = ["SCN_HEADER_ONLY=0"]
self.cpp_info.components["_scnlib"].libs = ["scn"]
if Version(self.version) >= "1.0":
self.cpp_info.components["_scnlib"].requires = ["fast_float::fast_float"]
self.cpp_info.components["_scnlib"].requires.append("fast_float::fast_float")
if Version(self.version) >= "2.0":
self.cpp_info.components["_scnlib"].requires.append("simdutf::simdutf")
if self.options.get_safe("regex_backend") in ["boost", "boost_icu"]:
self.cpp_info.components["_scnlib"].requires.append("boost::regex")
elif self.options.get_safe("regex_backend") == "re2":
self.cpp_info.components["_scnlib"].requires.append("re2::re2")

if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.components["_scnlib"].system_libs.append("m")
Expand Down
10 changes: 0 additions & 10 deletions recipes/scnlib/all/patches/0.4-0001-install-dll-windows.patch

This file was deleted.

13 changes: 13 additions & 0 deletions recipes/scnlib/all/patches/2.0.0-0001-remove-re2-version.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/cmake/dependencies.cmake b/cmake/dependencies.cmake
index ae2832b..fec6359 100644
--- a/cmake/dependencies.cmake
+++ b/cmake/dependencies.cmake
@@ -154,7 +154,7 @@ if (SCN_REGEX_BACKEND STREQUAL "re2")
message(FATAL_ERROR "SCN_REGEX_BOOST_USE_ICU isn't supported when SCN_REGEX_BACKEND is re2")
endif ()

- find_package(re2 11.0.0 REQUIRED)
+ find_package(re2 REQUIRED)
set(SCN_REGEX_BACKEND_TARGET re2::re2)
endif ()

7 changes: 6 additions & 1 deletion recipes/scnlib/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,9 @@ if(TARGET scn::scn-header-only)
else()
target_link_libraries(${PROJECT_NAME} PRIVATE scn::scn)
endif()
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
if (scn_VERSION VERSION_LESS "2.0.0")
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
else()
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
target_compile_definitions(${PROJECT_NAME} PUBLIC SCNLIB_V2)
endif()
26 changes: 22 additions & 4 deletions recipes/scnlib/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
#include <iostream>
#include <string>

#ifndef SCNLIB_V2

#include <scn/scn.h>

#include <string>
int main() {
std::string word;
auto result = scn::scan("Hello world", "{}", word);
std::cout << word << '\n';
std::cout << result.range_as_string() << '\n';
}

#else

#include <scn/scan.h>

int main() {
std::string s{"conan-center-index"};
auto span = scn::make_span(s);
return 0;
if (auto result = scn::scan<std::string>("Hello world!", "{}")) {
std::cout << result->value() << '\n';
} else {
std::cout << "Couldn't parse a word: " << result.error().msg() << '\n';
}
}

#endif
4 changes: 2 additions & 2 deletions recipes/scnlib/config.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
versions:
"2.0.0":
folder: all
"1.1.3":
folder: all
"1.1.2":
folder: all
"1.0":
folder: all
"0.4":
folder: all

0 comments on commit d532ba7

Please sign in to comment.