Skip to content

Commit 0f07a45

Browse files
committed
several fixes & improvements
- relocatable shared lib on macOS - put source code under src folder - use rm_safe - delete fPIC if Windows only - allow other build type than Release & Debug for msvc - add VirtualBuildEnv for autotools build (since there is msys2 in build requirements for MinGW) - remove PkgConfigDeps. It's used to discover gnutls only, but it's disabled by the recipe currently. - more future proof way to use MSBuild helper (see conan-io/conan#12817) - disable whole program optimization in msvc build
1 parent 745fb0b commit 0f07a45

File tree

4 files changed

+72
-124
lines changed

4 files changed

+72
-124
lines changed

recipes/libmicrohttpd/all/conandata.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ sources:
44
sha256: "9278907a6f571b391aab9644fd646a5108ed97311ec66f6359cebbedb0a4e3bb"
55
patches:
66
"0.9.75":
7-
- patch_file: "patches/0.9.75-0001-msbuild-RuntimeLibrary.patch"
8-
patch_description: "Remove RuntimeLibrary from vcxproject + use conantoolchain.props"
9-
patch_type: "conan"
10-
- patch_file: "patches/0.9.75-0002-allow-release-with-debug-runtime.patch"
11-
patch_description: "Remove RuntimeLibrary from vcxproject + use conantoolchain.props"
7+
- patch_file: "patches/0.9.75-0001-allow-release-with-debug-runtime.patch"
8+
patch_description: "Allow to build Release with Debug runtime"
129
patch_type: "conan"

recipes/libmicrohttpd/all/conanfile.py

Lines changed: 70 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
from conan import ConanFile, Version
2-
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rm, rmdir
3-
from conan.tools.gnu import Autotools, AutotoolsToolchain, PkgConfigDeps
4-
from conan.tools.microsoft import MSBuild, MSBuildToolchain, is_msvc, vs_layout
5-
from conan.tools.layout import basic_layout
1+
from conan import ConanFile
62
from conan.errors import ConanInvalidConfiguration
3+
from conan.tools.apple import fix_apple_shared_install_name
4+
from conan.tools.build import cross_building
5+
from conan.tools.env import VirtualBuildEnv, VirtualRunEnv
6+
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, replace_in_file, rm, rmdir
7+
from conan.tools.gnu import Autotools, AutotoolsToolchain, AutotoolsDeps
8+
from conan.tools.layout import basic_layout
9+
from conan.tools.microsoft import is_msvc, MSBuild, MSBuildToolchain
710
import os
811

9-
required_conan_version = ">=1.52.0"
12+
required_conan_version = ">=1.54.0"
1013

1114

1215
class LibmicrohttpdConan(ConanFile):
@@ -42,12 +45,13 @@ class LibmicrohttpdConan(ConanFile):
4245
def _settings_build(self):
4346
return getattr(self, "settings_build", self.settings)
4447

48+
def export_sources(self):
49+
export_conandata_patches(self)
50+
4551
def config_options(self):
52+
if self.settings.os == "Windows":
53+
del self.options.fPIC
4654
if self.settings.os != "Linux":
47-
try:
48-
del self.options.fPIC
49-
except Exception:
50-
pass
5155
del self.options.epoll
5256
if is_msvc(self):
5357
del self.options.with_https
@@ -58,62 +62,45 @@ def config_options(self):
5862

5963
def configure(self):
6064
if self.options.shared:
61-
try:
62-
del self.options.fPIC
63-
except Exception:
64-
pass
65-
try:
66-
del self.settings.compiler.libcxx
67-
except Exception:
68-
pass
69-
try:
70-
del self.settings.compiler.cppstd
71-
except Exception:
72-
pass
65+
self.options.rm_safe("fPIC")
66+
self.settings.rm_safe("compiler.cppstd")
67+
self.settings.rm_safe("compiler.libcxx")
7368

74-
def validate(self):
75-
if is_msvc(self):
76-
if self.info.settings.arch not in ("x86", "x86_64"):
77-
raise ConanInvalidConfiguration("Unsupported architecture (only x86 and x86_64 are supported)")
78-
if self.info.settings.build_type not in ("Release", "Debug"):
79-
raise ConanInvalidConfiguration("Unsupported build type (only Release and Debug are supported)")
69+
def layout(self):
70+
basic_layout(self, src_folder="src")
8071

8172
def requirements(self):
82-
if self.options.get_safe("with_zlib", False):
73+
if self.options.get_safe("with_zlib"):
8374
self.requires("zlib/1.2.13")
84-
if self.options.get_safe("with_https", False):
75+
76+
def validate(self):
77+
if is_msvc(self) and self.settings.arch not in ("x86", "x86_64"):
78+
raise ConanInvalidConfiguration("Unsupported architecture (only x86 and x86_64 are supported)")
79+
if self.options.get_safe("with_https"):
8580
raise ConanInvalidConfiguration("gnutls is not (yet) available in cci")
8681

8782
def build_requirements(self):
8883
if self._settings_build.os == "Windows" and not is_msvc(self):
8984
self.win_bash = True
90-
if not self.conf.get("tools.microsoft.bash:path", default=False, check_type=str):
85+
if not self.conf.get("tools.microsoft.bash:path", check_type=str):
9186
self.tool_requires("msys2/cci.latest")
9287

9388
def source(self):
94-
get(self, **self.conan_data["sources"][self.version],
95-
destination=self.source_folder, strip_root=True)
96-
97-
def export_sources(self):
98-
export_conandata_patches(self)
99-
100-
def layout(self):
101-
if is_msvc(self):
102-
vs_layout(self)
103-
else:
104-
basic_layout(self)
89+
get(self, **self.conan_data["sources"][self.version], strip_root=True)
10590

10691
def generate(self):
10792
if is_msvc(self):
10893
tc = MSBuildToolchain(self)
10994
tc.configuration = self._msvc_configuration
95+
tc.properties["WholeProgramOptimization"] = "false"
11096
tc.generate()
11197
else:
98+
VirtualBuildEnv(self).generate()
99+
if not cross_building(self):
100+
VirtualRunEnv(self).generate(scope="build")
101+
tc = AutotoolsToolchain(self)
112102
yes_no = lambda v: "yes" if v else "no"
113-
pkg = PkgConfigDeps(self)
114-
pkg.generate()
115-
autotools = AutotoolsToolchain(self)
116-
autotools.configure_args.extend([
103+
tc.configure_args.extend([
117104
f"--enable-shared={yes_no(self.options.shared)}",
118105
f"--enable-static={yes_no(not self.options.shared)}",
119106
f"--enable-https={yes_no(self.options.with_https)}",
@@ -125,67 +112,67 @@ def generate(self):
125112
"--disable-examples",
126113
"--disable-curl",
127114
])
128-
if self.settings.os == "Windows":
129-
if self.options.with_zlib:
130-
# This fixes libtool refusing to build a shared library when it sees `-lz`
131-
libdir = self.deps_cpp_info["zlib"].lib_paths[0]
132-
autotools.extra_ldflags.extend([os.path.join(libdir, lib).replace("\\", "/") for lib in os.listdir(libdir)])
133-
autotools.generate()
115+
tc.generate()
116+
AutotoolsDeps(self).generate()
134117

135118
@property
136119
def _msvc_configuration(self):
137-
return f"{self.settings.build_type}-{'dll' if self.options.shared else 'static'}"
120+
prefix = "Debug" if self.settings.build_type == "Debug" else "Release"
121+
suffix = "dll" if self.options.shared else "static"
122+
return f"{prefix}-{suffix}"
138123

139124
@property
140125
def _msvc_sln_folder(self):
141-
if self.settings.compiler == "Visual Studio":
142-
if Version(self.settings.compiler.version) >= 16:
143-
subdir = "VS-Any-Version"
144-
else:
145-
subdir = "VS2017"
146-
else:
147-
subdir = "VS-Any-Version"
148-
return os.path.join("w32", subdir)
149-
150-
@property
151-
def _msvc_platform(self):
152-
return {
153-
"x86": "Win32",
154-
"x86_64": "x64",
155-
}[str(self.settings.arch)]
156-
157-
def _patch_sources(self):
158-
apply_conandata_patches(self)
126+
# TODO: use VS-Any-Version folder once https://github.com/conan-io/conan/pull/12817 available in conan client
127+
return os.path.join(self.source_folder, "w32", "VS2022")
159128

160129
def build(self):
161-
self._patch_sources()
130+
apply_conandata_patches(self)
162131
if is_msvc(self):
132+
#==============================
133+
# TODO: to remove once https://github.com/conan-io/conan/pull/12817 available in conan client
134+
vcxproj_file = os.path.join(self._msvc_sln_folder, "libmicrohttpd.vcxproj")
135+
replace_in_file(
136+
self, vcxproj_file,
137+
"<WholeProgramOptimization Condition=\"! $(Configuration.StartsWith('Debug'))\">true</WholeProgramOptimization>",
138+
"",
139+
)
140+
toolset = MSBuildToolchain(self).toolset
141+
replace_in_file(
142+
self, vcxproj_file,
143+
"<PlatformToolset>v143</PlatformToolset>",
144+
f"<PlatformToolset>{toolset}</PlatformToolset>",
145+
)
146+
conantoolchain_props = os.path.join(self.generators_folder, MSBuildToolchain.filename)
147+
replace_in_file(
148+
self, vcxproj_file,
149+
"<Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.targets\" />",
150+
f"<Import Project=\"{conantoolchain_props}\" /><Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.targets\" />",
151+
)
152+
#==============================
153+
163154
msbuild = MSBuild(self)
164155
msbuild.build_type = self._msvc_configuration
165-
msbuild.platform = self._msvc_platform
156+
msbuild.platform = "Win32" if self.settings.arch == "x86" else msbuild.platform
166157
msbuild.build(sln=os.path.join(self._msvc_sln_folder, "libmicrohttpd.sln"), targets=["libmicrohttpd"])
167158
else:
168159
autotools = Autotools(self)
169160
autotools.configure()
170161
autotools.make()
171162

172163
def package(self):
173-
copy(self, "COPYING", os.path.join(self.source_folder), os.path.join(self.package_folder, "licenses"))
164+
copy(self, "COPYING", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
174165
if is_msvc(self):
175-
# 32-bit (x86) libraries are stored in the root
176-
output_dir = os.path.join(self.build_folder, self._msvc_sln_folder, "Output")
177-
if self.settings.arch in ("x86_64", ):
178-
# 64-bit (x64) libraries are stored in a subfolder
179-
output_dir = os.path.join(output_dir, self._msvc_platform)
180-
copy(self, "*.lib", output_dir, os.path.join(self.package_folder, "lib"))
181-
copy(self, "*.dll", output_dir, os.path.join(self.package_folder, "bin"))
182-
copy(self, "*.h", output_dir, os.path.join(self.package_folder, "include"))
166+
output_dir = os.path.join(self._msvc_sln_folder, "Output")
167+
copy(self, "*.lib", src=output_dir, dst=os.path.join(self.package_folder, "lib"), keep_path=False)
168+
copy(self, "*.dll", src=output_dir, dst=os.path.join(self.package_folder, "bin"), keep_path=False)
169+
copy(self, "*.h", src=output_dir, dst=os.path.join(self.package_folder, "include"), keep_path=False)
183170
else:
184171
autotools = Autotools(self)
185172
autotools.install()
186-
187173
rm(self, "*.la", os.path.join(self.package_folder, "lib"))
188174
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
175+
fix_apple_shared_install_name(self)
189176

190177
def package_info(self):
191178
self.cpp_info.set_property("pkg_config_name", "libmicrohttps")

recipes/libmicrohttpd/all/patches/0.9.75-0002-allow-release-with-debug-runtime.patch renamed to recipes/libmicrohttpd/all/patches/0.9.75-0001-allow-release-with-debug-runtime.patch

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
This patch allows building libmicrohttpd in Release configuration with a debug runtime (e.g. MTd)
21
--- src/microhttpd/mhd_assert.h
32
+++ src/microhttpd/mhd_assert.h
43
@@ -35,7 +35,7 @@

recipes/libmicrohttpd/all/patches/0.9.75-0001-msbuild-RuntimeLibrary.patch

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)