Skip to content

Commit 41a2169

Browse files
authored
cryptopp: Apply ARM fix on MSVC (#26208)
* Apply ARM fix on MSVC * Add missing patch file * Add commit metadata * Add ACLE backport * Update recipes/cryptopp/all/patches/8.9.0-0001-cve-2023-50980.patch * Cleanup * Validate seems necessary for now * CMake 4 support * Validate older releases for windows arm
1 parent bbffdb8 commit 41a2169

File tree

5 files changed

+322
-52
lines changed

5 files changed

+322
-52
lines changed

recipes/cryptopp/all/conandata.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ patches:
4040
patch_description: "Validate PolynomialMod2 coefficients (CVE-2023-50980)"
4141
patch_type: "vulnerability"
4242
patch_source: "https://github.com/weidai11/cryptopp/issues/1248"
43+
- patch_file: "patches/8.9.0-0002-fix-cmake-msvc-arm64-detection.patch"
44+
patch_source: "https://github.com/abdes/cryptopp-cmake/commit/1940cc0400de2e8161821558e73e3d8d0ddb13d3"
45+
- patch_file: "patches/8.9.0-0003-fix-acle-header-usage-msvc-arm.patch"
46+
patch_description: "Fix ACLE header detection on Windows ARM"
47+
patch_type: "backport"
48+
patch_source: "https://github.com/abdes/cryptopp-cmake/pull/127"
4349
"8.7.0":
4450
- patch_file: "patches/8.7.0-0001-fix-msvc-arm64.patch"
4551
"8.6.0":
@@ -50,4 +56,4 @@ patches:
5056
"8.5.0":
5157
- patch_file: "patches/8.4.0-0001-relocatable-macos.patch"
5258
patch_description: "Relocatable shared lib on macOS"
53-
patch_type: "conan"
59+
patch_type: "conan"

recipes/cryptopp/all/conanfile.py

Lines changed: 21 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
66
from conan.tools.files import (
77
apply_conandata_patches, collect_libs, copy, export_conandata_patches, get,
8-
rename, replace_in_file, rmdir, save
8+
rename, replace_in_file, rmdir
99
)
1010
from conan.tools.scm import Version
1111

1212
import os
13-
import textwrap
1413

15-
required_conan_version = ">=1.53.0"
14+
required_conan_version = ">=2"
1615

1716

1817
class CryptoPPConan(ConanFile):
@@ -36,28 +35,24 @@ class CryptoPPConan(ConanFile):
3635
"use_openmp": False,
3736
}
3837

38+
implements = ["auto_shared_fpic"]
39+
3940
def export_sources(self):
4041
export_conandata_patches(self)
4142

42-
def config_options(self):
43-
if self.settings.os == "Windows":
44-
del self.options.fPIC
45-
46-
def configure(self):
47-
if self.options.shared:
48-
self.options.rm_safe("fPIC")
49-
5043
def layout(self):
5144
cmake_layout(self, src_folder="src")
5245

5346
def validate_build(self):
5447
if is_apple_os(self) and cross_building(self) and Version(self.version) <= "8.6.0":
5548
# See https://github.com/abdes/cryptopp-cmake/pull/38
5649
raise ConanInvalidConfiguration("cryptopp 8.6.0 and lower do not support cross-building on Apple platforms")
57-
50+
5851
def validate(self):
5952
if self.options.shared and Version(self.version) >= "8.7.0":
6053
raise ConanInvalidConfiguration("cryptopp 8.7.0 and higher do not support shared builds")
54+
if Version(self.version) < "8.9.0" and self.settings.os == "Windows" and self.settings.arch == "armv8":
55+
raise ConanInvalidConfiguration("Older releases do not support Windows ARM")
6156

6257
def build_requirements(self):
6358
if Version(self.version) >= "8.7.0":
@@ -82,6 +77,17 @@ def source(self):
8277
# Get cryptopp-cmake sources
8378
get(self, **self.conan_data["sources"][self.version]["cmake"],
8479
destination=os.path.join(self.source_folder, "cryptopp-cmake"), strip_root=True)
80+
self._patch_sources()
81+
82+
def _patch_sources(self):
83+
apply_conandata_patches(self)
84+
# Honor fPIC option
85+
if Version(self.version) < "8.7.0":
86+
replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"),
87+
"SET(CMAKE_POSITION_INDEPENDENT_CODE 1)", "")
88+
else:
89+
replace_in_file(self, os.path.join(self.source_folder, "cryptopp-cmake", "cryptopp", "CMakeLists.txt"),
90+
"set(CMAKE_POSITION_INDEPENDENT_CODE 1)", "")
8591

8692
def generate(self):
8793
tc = CMakeToolchain(self)
@@ -108,10 +114,10 @@ def generate(self):
108114
tc.cache_variables["CRYPTOPP_NATIVE_ARCH"] = True
109115
tc.cache_variables["CRYPTOPP_USE_OPENMP"] = self.options.use_openmp
110116
tc.cache_variables["CMAKE_DISABLE_FIND_PACKAGE_Git"] = True
117+
tc.cache_variables["CMAKE_POLICY_VERSION_MINIMUM"] = "3.5" # CMake 4 support
111118
tc.generate()
112119

113-
def _patch_sources(self):
114-
apply_conandata_patches(self)
120+
def _ensure_android_cpufeatures(self):
115121
# Use cpu-features.h from Android NDK
116122
if self.settings.os == "Android" and Version(self.version) < "8.4.0":
117123
# Replicate logic from: https://github.com/weidai11/cryptopp/blob/CRYPTOPP_8_2_0/cpu.cpp#L46-L52
@@ -124,16 +130,9 @@ def _patch_sources(self):
124130
src=os.path.join(android_ndk_home, "sources", "android", "cpufeatures"),
125131
dst=self.source_folder,
126132
)
127-
# Honor fPIC option
128-
if Version(self.version) < "8.7.0":
129-
replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"),
130-
"SET(CMAKE_POSITION_INDEPENDENT_CODE 1)", "")
131-
else:
132-
replace_in_file(self, os.path.join(self.source_folder, "cryptopp-cmake", "cryptopp", "CMakeLists.txt"),
133-
"set(CMAKE_POSITION_INDEPENDENT_CODE 1)", "")
134133

135134
def build(self):
136-
self._patch_sources()
135+
self._ensure_android_cpufeatures()
137136
cmake = CMake(self)
138137
if Version(self.version) < "8.7.0":
139138
cmake.configure()
@@ -149,29 +148,6 @@ def package(self):
149148
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
150149
else:
151150
rmdir(self, os.path.join(self.package_folder, "share"))
152-
# TODO: to remove in conan v2 once cmake_find_package* generators removed
153-
self._create_cmake_module_alias_targets(
154-
os.path.join(self.package_folder, self._module_file_rel_path),
155-
{
156-
"cryptopp-shared": "cryptopp::cryptopp-shared",
157-
"cryptopp-static": "cryptopp::cryptopp-static"
158-
}
159-
)
160-
161-
def _create_cmake_module_alias_targets(self, module_file, targets):
162-
content = ""
163-
for alias, aliased in targets.items():
164-
content += textwrap.dedent(f"""\
165-
if(TARGET {aliased} AND NOT TARGET {alias})
166-
add_library({alias} INTERFACE IMPORTED)
167-
set_property(TARGET {alias} PROPERTY INTERFACE_LINK_LIBRARIES {aliased})
168-
endif()
169-
""")
170-
save(self, module_file, content)
171-
172-
@property
173-
def _module_file_rel_path(self):
174-
return os.path.join("lib", "cmake", f"conan-official-{self.name}-targets.cmake")
175151

176152
def package_info(self):
177153
self.cpp_info.set_property("cmake_file_name", "cryptopp")
@@ -195,11 +171,5 @@ def package_info(self):
195171
self.cpp_info.components["libcryptopp"].sharedlinkflags = openmp_flag
196172
self.cpp_info.components["libcryptopp"].exelinkflags = openmp_flag
197173

198-
# TODO: to remove in conan v2 once cmake_find_package* & pkg_config generators removed
199-
self.cpp_info.names["pkg_config"] = "libcryptopp"
200-
self.cpp_info.components["libcryptopp"].names["cmake_find_package"] = legacy_cmake_target
201-
self.cpp_info.components["libcryptopp"].names["cmake_find_package_multi"] = legacy_cmake_target
202-
self.cpp_info.components["libcryptopp"].build_modules["cmake_find_package"] = [self._module_file_rel_path]
203-
self.cpp_info.components["libcryptopp"].build_modules["cmake_find_package_multi"] = [self._module_file_rel_path]
204174
self.cpp_info.components["libcryptopp"].set_property("cmake_target_name", "cryptopp::cryptopp")
205175
self.cpp_info.components["libcryptopp"].set_property("pkg_config_name", "libcryptopp")

recipes/cryptopp/all/patches/8.9.0-0001-cve-2023-50980.patch

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ https://github.com/weidai11/cryptopp/issues/1248
22
https://github.com/weidai11/cryptopp/commit/eb383b8e1622
33
https://github.com/weidai11/cryptopp/commit/641ae35258de
44
https://github.com/weidai11/cryptopp/commit/93208e83937a
5+
6+
---
7+
8+
diff --git a/gf2n.cpp b/gf2n.cpp
9+
index 452e698..56c10de 100644
510
--- a/gf2n.cpp
611
+++ b/gf2n.cpp
712
@@ -135,6 +135,14 @@ PolynomialMod2 PolynomialMod2::Monomial(size_t i)
@@ -62,6 +67,8 @@ https://github.com/weidai11/cryptopp/commit/93208e83937a
6267
}
6368

6469
const GF2NT::Element& GF2NT233::Multiply(const Element &a, const Element &b) const
70+
diff --git a/gf2n.h b/gf2n.h
71+
index 4aef31e..38e2a91 100644
6572
--- a/gf2n.h
6673
+++ b/gf2n.h
6774
@@ -69,9 +69,11 @@ public:
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
From 1940cc0400de2e8161821558e73e3d8d0ddb13d3 Mon Sep 17 00:00:00 2001
2+
From: Steveice10 <[email protected]>
3+
Date: Thu, 25 Jan 2024 04:56:36 -0800
4+
Subject: [PATCH] build: fix compiling for ARM with MSVC but not Visual Studio
5+
generator (#106)
6+
7+
---
8+
diff --git a/cryptopp-cmake/cryptopp/CMakeLists.txt b/cryptopp-cmake/cryptopp/CMakeLists.txt
9+
index 7a78807..b64256f 100644
10+
--- a/cryptopp-cmake/cryptopp/CMakeLists.txt
11+
+++ b/cryptopp-cmake/cryptopp/CMakeLists.txt
12+
@@ -1241,7 +1241,7 @@ set_source_files_properties(
13+
# Compiler: MSVC
14+
# ------------------------------------------------------------------------------
15+
if(MSVC AND NOT CRYPTOPP_DISABLE_ASM)
16+
- if(${CMAKE_GENERATOR_PLATFORM} MATCHES "ARM")
17+
+ if(${CMAKE_GENERATOR_PLATFORM} MATCHES "ARM" OR CRYPTOPP_ARM32 OR CRYPTOPP_ARMV8)
18+
message(
19+
STATUS
20+
"[cryptopp] Disabling ASM because ARM is specified as target platform."

0 commit comments

Comments
 (0)