From 60285d30d12ff76f234d16007d42e33fb6d2f100 Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Tue, 18 Oct 2022 04:10:51 +0200 Subject: [PATCH 01/15] Add libmicrohttpd/0.9.75 recipe --- recipes/libmicrohttpd/all/conandata.yml | 9 + recipes/libmicrohttpd/all/conanfile.py | 176 ++++++++++++++++++ .../0.9.75-0001-msbuild-RuntimeLibrary.patch | 24 +++ .../all/test_package/CMakeLists.txt | 7 + .../all/test_package/conanfile.py | 30 +++ .../all/test_package/test_package.c | 50 +++++ .../all/test_package_v1/CMakeLists.txt | 10 + .../all/test_package_v1/conanfile.py | 17 ++ recipes/libmicrohttpd/config.yml | 3 + 9 files changed, 326 insertions(+) create mode 100644 recipes/libmicrohttpd/all/conandata.yml create mode 100644 recipes/libmicrohttpd/all/conanfile.py create mode 100644 recipes/libmicrohttpd/all/patches/0.9.75-0001-msbuild-RuntimeLibrary.patch create mode 100644 recipes/libmicrohttpd/all/test_package/CMakeLists.txt create mode 100644 recipes/libmicrohttpd/all/test_package/conanfile.py create mode 100644 recipes/libmicrohttpd/all/test_package/test_package.c create mode 100644 recipes/libmicrohttpd/all/test_package_v1/CMakeLists.txt create mode 100644 recipes/libmicrohttpd/all/test_package_v1/conanfile.py create mode 100644 recipes/libmicrohttpd/config.yml diff --git a/recipes/libmicrohttpd/all/conandata.yml b/recipes/libmicrohttpd/all/conandata.yml new file mode 100644 index 0000000000000..3093c36ac2903 --- /dev/null +++ b/recipes/libmicrohttpd/all/conandata.yml @@ -0,0 +1,9 @@ +sources: + "0.9.75": + url: "https://ftp.gnu.org/gnu/libmicrohttpd/libmicrohttpd-0.9.75.tar.gz" + sha256: "9278907a6f571b391aab9644fd646a5108ed97311ec66f6359cebbedb0a4e3bb" +patches: + "0.9.75": + - patch_file: "patches/0.9.75-0001-msbuild-RuntimeLibrary.patch" + patch_description: "Remove RuntimeLibrary from vcxproject" + patch_type: "conan" diff --git a/recipes/libmicrohttpd/all/conanfile.py b/recipes/libmicrohttpd/all/conanfile.py new file mode 100644 index 0000000000000..a00717734da4c --- /dev/null +++ b/recipes/libmicrohttpd/all/conanfile.py @@ -0,0 +1,176 @@ +from conan import ConanFile +from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rm, rmdir +from conan.tools.microsoft import MSBuild, MSBuildToolchain, is_msvc, vs_layout +from conan.errors import ConanInvalidConfiguration +from conans import AutoToolsBuildEnvironment +import functools +import os + +required_conan_version = ">1.48.0" + + +class LibmicrohttpdConan(ConanFile): + name = "libmicrohttpd" + description = "A small C library that is supposed to make it easy to run an HTTP server" + homepage = "https://www.gnu.org/software/libmicrohttpd/" + topics = ("libmicrohttpd", "httpd", "server", "service") + license = "LGPL-2.1" + url = "https://github.com/conan-io/conan-center-index" + settings = "os", "arch", "compiler", "build_type" + options = { + "shared": [True, False], + "fPIC": [True, False], + "with_https": [True, False], + "with_error_messages": [True, False], + "with_postprocessor": [True, False], + "with_digest_authentification": [True, False], + "epoll": [True, False], + "with_zlib": [True, False], + } + default_options = { + "shared": False, + "fPIC": True, + "with_https": False, # FIXME: should be True, but gnutls is not yet available in cci + "with_error_messages": True, + "with_postprocessor": True, + "with_digest_authentification": True, + "epoll": True, + "with_zlib": True, + } + generators = "pkg_config" + + @property + def _settings_build(self): + return getattr(self, "settings_build", self.settings) + + def config_options(self): + if self.settings.os == "Windows": + del self.options.fPIC + del self.options.epoll + if is_msvc(self): + del self.options.with_https + del self.options.with_error_messages + del self.options.with_postprocessor + del self.options.with_digest_authentification + del self.options.epoll + del self.options.with_zlib + + def configure(self): + if self.options.shared: + del self.options.fPIC + del self.settings.compiler.libcxx + del self.settings.compiler.cppstd + + def validate(self): + if is_msvc(self): + if self.settings.arch not in ("x86", "x86_64"): + raise ConanInvalidConfiguration("Unsupported architecture (only x86 and x86_64 are supported)") + if self.settings.build_type not in ("Release", "Debug"): + raise ConanInvalidConfiguration("Unsupported build type (only Release and Debug are supported)") + + def requirements(self): + if self.options.get_safe("with_zlib", False): + self.requires("zlib/1.2.12") + if self.options.get_safe("with_https", False): + raise ConanInvalidConfiguration("gnutls is not (yet) available in cci") + + def build_requirements(self): + if self._settings_build.os == "Windows" and not is_msvc(self) and not self.conf.get("tools.microsoft.bash:path", default=False, check_type=bool): + self.build_requires("msys2/cci.latest") + + def source(self): + get(self, **self.conan_data["sources"][self.version], + destination=self.source_folder, strip_root=True) + + def export_sources(self): + export_conandata_patches(self) + + def layout(self): + if is_msvc(self): + vs_layout(self) + + def generate(self): + if is_msvc(self): + tc = MSBuildToolchain(self) + tc.generate() + + @property + def _msvc_configuration(self): + return f"{self.settings.build_type}-{'dll' if self.options.shared else 'static'}" + + @property + def _msvc_sln_folder(self): + return os.path.join("w32", "VS-Any-Version") + + @property + def _msvc_arch(self): + return { + "x86": "Win32", + "x86_64": "x64", + }[str(self.settings.arch)] + + def _patch_sources(self): + apply_conandata_patches(self) + + @functools.lru_cache(1) + def _configure_autotools(self): + yes_no = lambda v: "yes" if v else "no" + autotools = AutoToolsBuildEnvironment(self, win_bash=self._settings_build.os == "Windows") + autotools.libs = [] + if self.settings.os == "Windows": + if self.options.with_zlib: + libdir = self.deps_cpp_info["zlib"].lib_paths[0] + autotools.link_flags.extend([os.path.join(libdir, lib).replace("\\", "/") for lib in os.listdir(libdir)]) + autotools.configure(self.source_folder,[ + "--enable-shared={}".format(yes_no(self.options.shared)), + "--enable-static={}".format(yes_no(not self.options.shared)), + "--enable-https={}".format(yes_no(self.options.with_https)), + "--enable-messages={}".format(yes_no(self.options.with_error_messages)), + "--enable-postprocessor={}".format(yes_no(self.options.with_postprocessor)), + "--enable-dauth={}".format(yes_no(self.options.with_digest_authentification)), + "--enable-epoll={}".format(yes_no(self.options.get_safe("epoll"))), + "--disable-doc", + "--disable-examples", + "--disable-curl", + ]) + return autotools + + def build(self): + self._patch_sources() + if is_msvc(self): + msbuild = MSBuild(self) + msbuild.build_type = self._msvc_configuration + msbuild.build(sln=os.path.join(self._msvc_sln_folder, "libmicrohttpd.sln"), targets=["libmicrohttpd"]) + else: + autotools = self._configure_autotools() + autotools.make() + + def package(self): + copy(self, "COPYING", os.path.join(self.build_folder), os.path.join(self.package_folder, "licenses")) + if is_msvc(self): + copy(self, "*.lib", os.path.join(self.build_folder, self._msvc_sln_folder, "Output", self._msvc_arch), os.path.join(self.package_folder, "lib")) + copy(self, "*.dll", os.path.join(self.build_folder, self._msvc_sln_folder, "Output", self._msvc_arch), os.path.join(self.package_folder, "bin")) + copy(self, "*.h", os.path.join(self.build_folder, self._msvc_sln_folder, "Output", self._msvc_arch), os.path.join(self.package_folder, "include")) + else: + autotools = self._configure_autotools() + autotools.install() + + rm(self, "*.la", os.path.join(self.package_folder, "lib")) + rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig")) + + def package_info(self): + self.cpp_info.set_property("pkg_config_name", "libmicrohttps") + libname = "microhttpd" + if is_msvc(self): + libname = "libmicrohttpd" + if self.options.shared: + libname += "-dll" + if self.settings.build_type == "Debug": + libname += "_d" + self.cpp_info.libs = [libname] + if self.settings.os in ("FreeBSD", "Linux"): + self.cpp_info.system_libs = ["pthread"] + elif self.settings.os == "Windows": + if self.options.shared: + self.cpp_info.defines.append("MHD_W32DLL") + self.cpp_info.system_libs = ["ws2_32"] diff --git a/recipes/libmicrohttpd/all/patches/0.9.75-0001-msbuild-RuntimeLibrary.patch b/recipes/libmicrohttpd/all/patches/0.9.75-0001-msbuild-RuntimeLibrary.patch new file mode 100644 index 0000000000000..479b2b902d1d8 --- /dev/null +++ b/recipes/libmicrohttpd/all/patches/0.9.75-0001-msbuild-RuntimeLibrary.patch @@ -0,0 +1,24 @@ +--- w32/common/libmicrohttpd-build-settings.vcxproj ++++ w32/common/libmicrohttpd-build-settings.vcxproj +@@ -31,8 +31,8 @@ + + + _LIB;MHD_W32LIB;%(PreprocessorDefinitions) +- MultiThreadedDebug +- MultiThreaded ++ + + + Ws2_32.lib +@@ -45,8 +45,8 @@ + + + _USRDLL;MHD_W32DLL;%(PreprocessorDefinitions) +- MultiThreadedDebugDLL +- MultiThreadedDLL ++ + + + Ws2_32.lib;%(AdditionalDependencies) diff --git a/recipes/libmicrohttpd/all/test_package/CMakeLists.txt b/recipes/libmicrohttpd/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..534adba0c584f --- /dev/null +++ b/recipes/libmicrohttpd/all/test_package/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.1) +project(test_package LANGUAGES C) + +find_package(libmicrohttpd REQUIRED CONFIG) + +add_executable(${PROJECT_NAME} test_package.c) +target_link_libraries(${PROJECT_NAME} PRIVATE libmicrohttpd::libmicrohttpd) diff --git a/recipes/libmicrohttpd/all/test_package/conanfile.py b/recipes/libmicrohttpd/all/test_package/conanfile.py new file mode 100644 index 0000000000000..f72d1f660e19f --- /dev/null +++ b/recipes/libmicrohttpd/all/test_package/conanfile.py @@ -0,0 +1,30 @@ +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout +import os + + +class TestPackageConan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + generators = "CMakeDeps", "VirtualRunEnv" + test_type = "explicit" + + def layout(self): + cmake_layout(self) + + def requirements(self): + self.requires(self.tested_reference_str) + + def generate(self): + tc = CMakeToolchain(self) + tc.generate() + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + if can_run(self): + bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package") + self.run(bin_path, env="conanrun") diff --git a/recipes/libmicrohttpd/all/test_package/test_package.c b/recipes/libmicrohttpd/all/test_package/test_package.c new file mode 100644 index 0000000000000..8d14719809e4e --- /dev/null +++ b/recipes/libmicrohttpd/all/test_package/test_package.c @@ -0,0 +1,50 @@ +#include +#include +#include +#include + +#define PAGE "libmicrohttpd demo"\ + "libmicrohttpd demo" + +static int ahc_echo(void * cls, + struct MHD_Connection * connection, + const char * url, + const char * method, + const char * version, + const char * upload_data, + size_t * upload_data_size, + void ** ptr) { + static int dummy; + const char * page = cls; + struct MHD_Response * response; + int ret; + + if (0 != strcmp(method, "GET")) + return MHD_NO; /* unexpected method */ + if (&dummy != *ptr) + { + /* The first time only the headers are valid, + do not respond in the first round... */ + *ptr = &dummy; + return MHD_YES; + } + if (0 != *upload_data_size) + return MHD_NO; /* upload data in a GET!? */ + *ptr = NULL; /* clear context pointer */ + response = MHD_create_response_from_buffer (strlen(page), + (void*) page, + MHD_RESPMEM_PERSISTENT); + ret = MHD_queue_response(connection, + MHD_HTTP_OK, + response); + MHD_destroy_response(response); + return ret; +} + +int main(int argc, + char ** argv) { + struct MHD_Daemon * d; + d = NULL; + MHD_stop_daemon(d); + return 0; +} diff --git a/recipes/libmicrohttpd/all/test_package_v1/CMakeLists.txt b/recipes/libmicrohttpd/all/test_package_v1/CMakeLists.txt new file mode 100644 index 0000000000000..0b95e58322269 --- /dev/null +++ b/recipes/libmicrohttpd/all/test_package_v1/CMakeLists.txt @@ -0,0 +1,10 @@ +cmake_minimum_required(VERSION 3.1) +project(test_package LANGUAGES C) + +include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake") +conan_basic_setup(TARGETS) + +find_package(libmicrohttpd REQUIRED CONFIG) + +add_executable(${PROJECT_NAME} ../test_package/test_package.c) +target_link_libraries(${PROJECT_NAME} PRIVATE libmicrohttpd::libmicrohttpd) diff --git a/recipes/libmicrohttpd/all/test_package_v1/conanfile.py b/recipes/libmicrohttpd/all/test_package_v1/conanfile.py new file mode 100644 index 0000000000000..38f4483872d47 --- /dev/null +++ b/recipes/libmicrohttpd/all/test_package_v1/conanfile.py @@ -0,0 +1,17 @@ +from conans import ConanFile, CMake, tools +import os + + +class TestPackageConan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + generators = "cmake", "cmake_find_package_multi" + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + if not tools.cross_building(self): + bin_path = os.path.join("bin", "test_package") + self.run(bin_path, run_environment=True) diff --git a/recipes/libmicrohttpd/config.yml b/recipes/libmicrohttpd/config.yml new file mode 100644 index 0000000000000..48e6a23d34df6 --- /dev/null +++ b/recipes/libmicrohttpd/config.yml @@ -0,0 +1,3 @@ +versions: + "0.9.75": + folder: all From d75cec13bac8b99805b9e434733bfcfc8d0ee652 Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Tue, 18 Oct 2022 04:15:18 +0200 Subject: [PATCH 02/15] libmicrohttpd: fix test-package directory name --- .../all/{test_package_v1 => test_v1_package}/CMakeLists.txt | 0 .../all/{test_package_v1 => test_v1_package}/conanfile.py | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename recipes/libmicrohttpd/all/{test_package_v1 => test_v1_package}/CMakeLists.txt (100%) rename recipes/libmicrohttpd/all/{test_package_v1 => test_v1_package}/conanfile.py (100%) diff --git a/recipes/libmicrohttpd/all/test_package_v1/CMakeLists.txt b/recipes/libmicrohttpd/all/test_v1_package/CMakeLists.txt similarity index 100% rename from recipes/libmicrohttpd/all/test_package_v1/CMakeLists.txt rename to recipes/libmicrohttpd/all/test_v1_package/CMakeLists.txt diff --git a/recipes/libmicrohttpd/all/test_package_v1/conanfile.py b/recipes/libmicrohttpd/all/test_v1_package/conanfile.py similarity index 100% rename from recipes/libmicrohttpd/all/test_package_v1/conanfile.py rename to recipes/libmicrohttpd/all/test_v1_package/conanfile.py From fefe7faa0a9d4287f60c27b7467c59c8b5774d93 Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Tue, 18 Oct 2022 15:04:19 +0200 Subject: [PATCH 03/15] libmicrohttpd: fix test_package + address feedback --- recipes/libmicrohttpd/all/conanfile.py | 37 ++++--- .../all/test_package/test_package.c | 102 +++++++++++------- 2 files changed, 84 insertions(+), 55 deletions(-) diff --git a/recipes/libmicrohttpd/all/conanfile.py b/recipes/libmicrohttpd/all/conanfile.py index a00717734da4c..c8e8b6f252c58 100644 --- a/recipes/libmicrohttpd/all/conanfile.py +++ b/recipes/libmicrohttpd/all/conanfile.py @@ -6,7 +6,7 @@ import functools import os -required_conan_version = ">1.48.0" +required_conan_version = ">1.52.0" class LibmicrohttpdConan(ConanFile): @@ -44,7 +44,7 @@ def _settings_build(self): return getattr(self, "settings_build", self.settings) def config_options(self): - if self.settings.os == "Windows": + if self.settings.os != "Linux": del self.options.fPIC del self.options.epoll if is_msvc(self): @@ -52,30 +52,35 @@ def config_options(self): del self.options.with_error_messages del self.options.with_postprocessor del self.options.with_digest_authentification - del self.options.epoll del self.options.with_zlib def configure(self): if self.options.shared: del self.options.fPIC - del self.settings.compiler.libcxx - del self.settings.compiler.cppstd + try: + del self.settings.compiler.libcxx + except Exception: + pass + try: + del self.settings.compiler.cppstd + except Exception: + pass def validate(self): if is_msvc(self): - if self.settings.arch not in ("x86", "x86_64"): + if self.info.settings.arch not in ("x86", "x86_64"): raise ConanInvalidConfiguration("Unsupported architecture (only x86 and x86_64 are supported)") - if self.settings.build_type not in ("Release", "Debug"): + if self.info.settings.build_type not in ("Release", "Debug"): raise ConanInvalidConfiguration("Unsupported build type (only Release and Debug are supported)") def requirements(self): if self.options.get_safe("with_zlib", False): - self.requires("zlib/1.2.12") + self.requires("zlib/1.2.13") if self.options.get_safe("with_https", False): raise ConanInvalidConfiguration("gnutls is not (yet) available in cci") def build_requirements(self): - if self._settings_build.os == "Windows" and not is_msvc(self) and not self.conf.get("tools.microsoft.bash:path", default=False, check_type=bool): + if self._settings_build.os == "Windows" and not is_msvc(self) and not self.conf.get("tools.microsoft.bash:path", default=False, check_type=str): self.build_requires("msys2/cci.latest") def source(self): @@ -122,13 +127,13 @@ def _configure_autotools(self): libdir = self.deps_cpp_info["zlib"].lib_paths[0] autotools.link_flags.extend([os.path.join(libdir, lib).replace("\\", "/") for lib in os.listdir(libdir)]) autotools.configure(self.source_folder,[ - "--enable-shared={}".format(yes_no(self.options.shared)), - "--enable-static={}".format(yes_no(not self.options.shared)), - "--enable-https={}".format(yes_no(self.options.with_https)), - "--enable-messages={}".format(yes_no(self.options.with_error_messages)), - "--enable-postprocessor={}".format(yes_no(self.options.with_postprocessor)), - "--enable-dauth={}".format(yes_no(self.options.with_digest_authentification)), - "--enable-epoll={}".format(yes_no(self.options.get_safe("epoll"))), + f"--enable-shared={yes_no(self.options.shared)}", + f"--enable-static={yes_no(not self.options.shared)}", + f"--enable-https={yes_no(self.options.with_https)}", + f"--enable-messages={yes_no(self.options.with_error_messages)}", + f"--enable-postprocessor={yes_no(self.options.with_postprocessor)}", + f"--enable-dauth={yes_no(self.options.with_digest_authentification)}", + f"--enable-epoll={yes_no(self.options.get_safe('epoll'))}", "--disable-doc", "--disable-examples", "--disable-curl", diff --git a/recipes/libmicrohttpd/all/test_package/test_package.c b/recipes/libmicrohttpd/all/test_package/test_package.c index 8d14719809e4e..cb40829c7a43b 100644 --- a/recipes/libmicrohttpd/all/test_package/test_package.c +++ b/recipes/libmicrohttpd/all/test_package/test_package.c @@ -3,48 +3,72 @@ #include #include -#define PAGE "libmicrohttpd demo"\ - "libmicrohttpd demo" +#define PORT 8888 +#define PAGE \ + "" \ + "" \ + "libmicrohttpd demo" \ + "" \ + "" \ + "libmicrohttpd demo" \ + "" \ + "" -static int ahc_echo(void * cls, - struct MHD_Connection * connection, - const char * url, - const char * method, - const char * version, - const char * upload_data, - size_t * upload_data_size, - void ** ptr) { - static int dummy; - const char * page = cls; - struct MHD_Response * response; - int ret; +static enum MHD_Result ahc_echo(void * cls, + struct MHD_Connection *connection, + const char *url, + const char *method, + const char *version, + const char *upload_data, + long unsigned int *upload_data_size, + void **con_cls) { + struct MHD_Response *response; + int ret; - if (0 != strcmp(method, "GET")) - return MHD_NO; /* unexpected method */ - if (&dummy != *ptr) - { - /* The first time only the headers are valid, - do not respond in the first round... */ - *ptr = &dummy; - return MHD_YES; + if (strcmp(method, "GET") != 0) { + /** + * unexpected method + */ + return MHD_NO; } - if (0 != *upload_data_size) - return MHD_NO; /* upload data in a GET!? */ - *ptr = NULL; /* clear context pointer */ - response = MHD_create_response_from_buffer (strlen(page), - (void*) page, - MHD_RESPMEM_PERSISTENT); - ret = MHD_queue_response(connection, - MHD_HTTP_OK, - response); - MHD_destroy_response(response); - return ret; + if (*con_cls == NULL) { + /** + * The first time only the headers are valid, + * do not respond in the first round. + * But accept the connection. + */ + *con_cls = connection; + return MHD_YES; + } + if (*upload_data_size != 0) { + /** + * upload data in a GET!? + */ + return MHD_NO; + } + response = MHD_create_response_from_buffer(strlen(PAGE), (void*)PAGE, MHD_RESPMEM_PERSISTENT); + ret = MHD_queue_response(connection, MHD_HTTP_OK, response); + MHD_destroy_response(response); + return ret; } -int main(int argc, - char ** argv) { - struct MHD_Daemon * d; - d = NULL; - MHD_stop_daemon(d); - return 0; +int main(int argc, char *argv[]) { + struct MHD_Daemon *daemon; + + // Don't open a port and do not block so CI isn't interrupted. +#if 0 + daemon = MHD_start_daemon(MHD_USE_INTERNAL_POLLING_THREAD, + PORT, NULL, NULL, + &ahc_echo, NULL, MHD_OPTION_END); + if (daemon == NULL) { + return 1; + } + + (void)getchar(); +#else + daemon = NULL; +#endif + + MHD_stop_daemon(daemon); + return 0; } From 413807766037839eb0b2b780c0685b7b3fb3ebf6 Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Tue, 18 Oct 2022 15:06:33 +0200 Subject: [PATCH 04/15] libmicrohttpd: 1.52.0 will do --- recipes/libmicrohttpd/all/conanfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/libmicrohttpd/all/conanfile.py b/recipes/libmicrohttpd/all/conanfile.py index c8e8b6f252c58..150854c20d224 100644 --- a/recipes/libmicrohttpd/all/conanfile.py +++ b/recipes/libmicrohttpd/all/conanfile.py @@ -6,7 +6,7 @@ import functools import os -required_conan_version = ">1.52.0" +required_conan_version = ">=1.52.0" class LibmicrohttpdConan(ConanFile): From 95f281ed42f2cfa71879ff4088c067ee1ccd0803 Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Tue, 18 Oct 2022 18:03:52 +0200 Subject: [PATCH 05/15] libmicrohttpd: experimental patch to fix VS2017 --- recipes/libmicrohttpd/all/conanfile.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/recipes/libmicrohttpd/all/conanfile.py b/recipes/libmicrohttpd/all/conanfile.py index 150854c20d224..0336d81ec4a0a 100644 --- a/recipes/libmicrohttpd/all/conanfile.py +++ b/recipes/libmicrohttpd/all/conanfile.py @@ -1,4 +1,4 @@ -from conan import ConanFile +from conan import ConanFile, Version from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rm, rmdir from conan.tools.microsoft import MSBuild, MSBuildToolchain, is_msvc, vs_layout from conan.errors import ConanInvalidConfiguration @@ -105,7 +105,14 @@ def _msvc_configuration(self): @property def _msvc_sln_folder(self): - return os.path.join("w32", "VS-Any-Version") + if self.settings.compiler == "Visual Studio": + if Version(self.settings.compiler.version) >= 2019: + subdir = "VS-Any-Version" + else: + subdir = "VS2017" + else: + subdir = "VS-Any-Version" + return os.path.join("w32", subdir) @property def _msvc_arch(self): From 68828f0e00c9e86379c66bb164d58f2d6107350f Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Tue, 18 Oct 2022 23:20:37 +0200 Subject: [PATCH 06/15] libmicrohttpd: fix MSVC MT --- recipes/libmicrohttpd/all/conanfile.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/recipes/libmicrohttpd/all/conanfile.py b/recipes/libmicrohttpd/all/conanfile.py index 0336d81ec4a0a..003a19f1e99f8 100644 --- a/recipes/libmicrohttpd/all/conanfile.py +++ b/recipes/libmicrohttpd/all/conanfile.py @@ -1,5 +1,5 @@ from conan import ConanFile, Version -from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rm, rmdir +from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, replace_in_file, rm, rmdir from conan.tools.microsoft import MSBuild, MSBuildToolchain, is_msvc, vs_layout from conan.errors import ConanInvalidConfiguration from conans import AutoToolsBuildEnvironment @@ -98,6 +98,13 @@ def generate(self): if is_msvc(self): tc = MSBuildToolchain(self) tc.generate() + # FIXME: MSBuildToolchain cannot change the configuation names + replace_in_file( + self, + os.path.join(self.build_folder, "conan", "conantoolchain.props"), + f"'{str(self.settings.build_type)}'", + f"'{self._msvc_configuration}'" + ) @property def _msvc_configuration(self): @@ -106,7 +113,7 @@ def _msvc_configuration(self): @property def _msvc_sln_folder(self): if self.settings.compiler == "Visual Studio": - if Version(self.settings.compiler.version) >= 2019: + if Version(self.settings.compiler.version) >= 16: subdir = "VS-Any-Version" else: subdir = "VS2017" @@ -150,6 +157,15 @@ def _configure_autotools(self): def build(self): self._patch_sources() if is_msvc(self): + # vs_path = vs_installation_path("15") + # vcvars_path = os.path.join(vs_path, "VC/Auxiliary/Build/vcvarsall.bat") + + # platform_arch = "x86" if self.settings.arch == "x86" else "x64" + # build_type = self.settings.build_type + # cmd = ('set "VSCMD_START_DIR=%%CD%%" && ' + # '"%s" x64 && msbuild "MyProject.sln" /p:Configuration=%s ' + # '/p:Platform=%s ' % (vcvars_path, build_type, platform_arch)) + # self.run(cmd) msbuild = MSBuild(self) msbuild.build_type = self._msvc_configuration msbuild.build(sln=os.path.join(self._msvc_sln_folder, "libmicrohttpd.sln"), targets=["libmicrohttpd"]) From 3d3729bd104249ed181afb0a1ce75cc0142ebfcf Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Tue, 18 Oct 2022 23:24:46 +0200 Subject: [PATCH 07/15] libmicrohttpd: use conantoolchain.props --- recipes/libmicrohttpd/all/conandata.yml | 2 +- .../patches/0.9.75-0001-msbuild-RuntimeLibrary.patch | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/recipes/libmicrohttpd/all/conandata.yml b/recipes/libmicrohttpd/all/conandata.yml index 3093c36ac2903..baf8560b8d3f1 100644 --- a/recipes/libmicrohttpd/all/conandata.yml +++ b/recipes/libmicrohttpd/all/conandata.yml @@ -5,5 +5,5 @@ sources: patches: "0.9.75": - patch_file: "patches/0.9.75-0001-msbuild-RuntimeLibrary.patch" - patch_description: "Remove RuntimeLibrary from vcxproject" + patch_description: "Remove RuntimeLibrary from vcxproject + use conantoolchain.props" patch_type: "conan" diff --git a/recipes/libmicrohttpd/all/patches/0.9.75-0001-msbuild-RuntimeLibrary.patch b/recipes/libmicrohttpd/all/patches/0.9.75-0001-msbuild-RuntimeLibrary.patch index 479b2b902d1d8..b3dc82df26fa9 100644 --- a/recipes/libmicrohttpd/all/patches/0.9.75-0001-msbuild-RuntimeLibrary.patch +++ b/recipes/libmicrohttpd/all/patches/0.9.75-0001-msbuild-RuntimeLibrary.patch @@ -1,3 +1,14 @@ +--- w32/common/common-build-settings.vcxproj ++++ w32/common/common-build-settings.vcxproj +@@ -5,7 +5,7 @@ + Only 0 and 1 are used currently --> + 0 + 1 +- ++ + + $(SolutionDir);$(MhdW32Common);$(MhdSrc)include;$(IncludePath) + --- w32/common/libmicrohttpd-build-settings.vcxproj +++ w32/common/libmicrohttpd-build-settings.vcxproj @@ -31,8 +31,8 @@ From 9dbac9b1768e89988c3246909242b9c57ac3ff76 Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Tue, 18 Oct 2022 23:27:29 +0200 Subject: [PATCH 08/15] libmicrohttpd: clean-up --- recipes/libmicrohttpd/all/conanfile.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/recipes/libmicrohttpd/all/conanfile.py b/recipes/libmicrohttpd/all/conanfile.py index 003a19f1e99f8..5602cf4c75547 100644 --- a/recipes/libmicrohttpd/all/conanfile.py +++ b/recipes/libmicrohttpd/all/conanfile.py @@ -157,15 +157,6 @@ def _configure_autotools(self): def build(self): self._patch_sources() if is_msvc(self): - # vs_path = vs_installation_path("15") - # vcvars_path = os.path.join(vs_path, "VC/Auxiliary/Build/vcvarsall.bat") - - # platform_arch = "x86" if self.settings.arch == "x86" else "x64" - # build_type = self.settings.build_type - # cmd = ('set "VSCMD_START_DIR=%%CD%%" && ' - # '"%s" x64 && msbuild "MyProject.sln" /p:Configuration=%s ' - # '/p:Platform=%s ' % (vcvars_path, build_type, platform_arch)) - # self.run(cmd) msbuild = MSBuild(self) msbuild.build_type = self._msvc_configuration msbuild.build(sln=os.path.join(self._msvc_sln_folder, "libmicrohttpd.sln"), targets=["libmicrohttpd"]) From 3a8406135842c2a99311afed5f7435f8f575e30c Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Tue, 18 Oct 2022 23:29:51 +0200 Subject: [PATCH 09/15] Turns out conan knew how to do it after all --- recipes/libmicrohttpd/all/conanfile.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/recipes/libmicrohttpd/all/conanfile.py b/recipes/libmicrohttpd/all/conanfile.py index 5602cf4c75547..c5093be9f2538 100644 --- a/recipes/libmicrohttpd/all/conanfile.py +++ b/recipes/libmicrohttpd/all/conanfile.py @@ -1,5 +1,5 @@ from conan import ConanFile, Version -from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, replace_in_file, rm, rmdir +from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rm, rmdir from conan.tools.microsoft import MSBuild, MSBuildToolchain, is_msvc, vs_layout from conan.errors import ConanInvalidConfiguration from conans import AutoToolsBuildEnvironment @@ -97,14 +97,8 @@ def layout(self): def generate(self): if is_msvc(self): tc = MSBuildToolchain(self) + tc.configuration = self._msvc_configuration tc.generate() - # FIXME: MSBuildToolchain cannot change the configuation names - replace_in_file( - self, - os.path.join(self.build_folder, "conan", "conantoolchain.props"), - f"'{str(self.settings.build_type)}'", - f"'{self._msvc_configuration}'" - ) @property def _msvc_configuration(self): From 1c16eca8925afe348162d2487edc2712057afe13 Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Wed, 19 Oct 2022 11:27:22 +0200 Subject: [PATCH 10/15] Use PkgConfigDeps --- recipes/libmicrohttpd/all/conanfile.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/recipes/libmicrohttpd/all/conanfile.py b/recipes/libmicrohttpd/all/conanfile.py index c5093be9f2538..f7e5f786c6af4 100644 --- a/recipes/libmicrohttpd/all/conanfile.py +++ b/recipes/libmicrohttpd/all/conanfile.py @@ -1,5 +1,6 @@ from conan import ConanFile, Version from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rm, rmdir +from conan.tools.gnu import PkgConfigDeps from conan.tools.microsoft import MSBuild, MSBuildToolchain, is_msvc, vs_layout from conan.errors import ConanInvalidConfiguration from conans import AutoToolsBuildEnvironment @@ -13,7 +14,7 @@ class LibmicrohttpdConan(ConanFile): name = "libmicrohttpd" description = "A small C library that is supposed to make it easy to run an HTTP server" homepage = "https://www.gnu.org/software/libmicrohttpd/" - topics = ("libmicrohttpd", "httpd", "server", "service") + topics = ("httpd", "server", "service") license = "LGPL-2.1" url = "https://github.com/conan-io/conan-center-index" settings = "os", "arch", "compiler", "build_type" @@ -37,7 +38,6 @@ class LibmicrohttpdConan(ConanFile): "epoll": True, "with_zlib": True, } - generators = "pkg_config" @property def _settings_build(self): @@ -99,6 +99,9 @@ def generate(self): tc = MSBuildToolchain(self) tc.configuration = self._msvc_configuration tc.generate() + else: + pkg = PkgConfigDeps(self) + pkg.generate() @property def _msvc_configuration(self): From 21b2a2c3ce8c4e96d6cbc338ee685ad0f7d648f5 Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Wed, 19 Oct 2022 11:28:17 +0200 Subject: [PATCH 11/15] catch removing fPIC --- recipes/libmicrohttpd/all/conanfile.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/recipes/libmicrohttpd/all/conanfile.py b/recipes/libmicrohttpd/all/conanfile.py index f7e5f786c6af4..51a11e5b03535 100644 --- a/recipes/libmicrohttpd/all/conanfile.py +++ b/recipes/libmicrohttpd/all/conanfile.py @@ -45,7 +45,10 @@ def _settings_build(self): def config_options(self): if self.settings.os != "Linux": - del self.options.fPIC + try: + del self.options.fPIC + except Exception: + pass del self.options.epoll if is_msvc(self): del self.options.with_https From 752250a36b9ce0b23e80fc2d58b256a229c416a9 Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Wed, 19 Oct 2022 11:29:33 +0200 Subject: [PATCH 12/15] Set win_bash attribute --- recipes/libmicrohttpd/all/conanfile.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/recipes/libmicrohttpd/all/conanfile.py b/recipes/libmicrohttpd/all/conanfile.py index 51a11e5b03535..607bc36ae1709 100644 --- a/recipes/libmicrohttpd/all/conanfile.py +++ b/recipes/libmicrohttpd/all/conanfile.py @@ -83,8 +83,10 @@ def requirements(self): raise ConanInvalidConfiguration("gnutls is not (yet) available in cci") def build_requirements(self): - if self._settings_build.os == "Windows" and not is_msvc(self) and not self.conf.get("tools.microsoft.bash:path", default=False, check_type=str): - self.build_requires("msys2/cci.latest") + if self._settings_build.os == "Windows" and not is_msvc(self): + self.win_bash = True + if not self.conf.get("tools.microsoft.bash:path", default=False, check_type=str): + self.tool_requires("msys2/cci.latest") def source(self): get(self, **self.conan_data["sources"][self.version], From 5fbf438ccfc8f8fba531bda5313cbf73a65672c1 Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Wed, 19 Oct 2022 12:26:07 +0200 Subject: [PATCH 13/15] Use conan vs AutotoolsToolchain + Autotools --- recipes/libmicrohttpd/all/conanfile.py | 54 ++++++++++++-------------- 1 file changed, 25 insertions(+), 29 deletions(-) diff --git a/recipes/libmicrohttpd/all/conanfile.py b/recipes/libmicrohttpd/all/conanfile.py index 607bc36ae1709..1a356d477f374 100644 --- a/recipes/libmicrohttpd/all/conanfile.py +++ b/recipes/libmicrohttpd/all/conanfile.py @@ -1,10 +1,8 @@ from conan import ConanFile, Version from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rm, rmdir -from conan.tools.gnu import PkgConfigDeps -from conan.tools.microsoft import MSBuild, MSBuildToolchain, is_msvc, vs_layout +from conan.tools.gnu import Autotools, AutotoolsDeps, AutotoolsToolchain, PkgConfigDeps +from conan.tools.microsoft import MSBuild, MSBuildToolchain, is_msvc, vs_layout, unix_path from conan.errors import ConanInvalidConfiguration -from conans import AutoToolsBuildEnvironment -import functools import os required_conan_version = ">=1.52.0" @@ -105,8 +103,28 @@ def generate(self): tc.configuration = self._msvc_configuration tc.generate() else: + yes_no = lambda v: "yes" if v else "no" pkg = PkgConfigDeps(self) pkg.generate() + autotools = AutotoolsToolchain(self) + autotools.configure_args.extend([ + f"--enable-shared={yes_no(self.options.shared)}", + f"--enable-static={yes_no(not self.options.shared)}", + f"--enable-https={yes_no(self.options.with_https)}", + f"--enable-messages={yes_no(self.options.with_error_messages)}", + f"--enable-postprocessor={yes_no(self.options.with_postprocessor)}", + f"--enable-dauth={yes_no(self.options.with_digest_authentification)}", + f"--enable-epoll={yes_no(self.options.get_safe('epoll'))}", + "--disable-doc", + "--disable-examples", + "--disable-curl", + ]) + if self.settings.os == "Windows": + if self.options.with_zlib: + # This fixes libtool refusing to build a shared library when it sees `-lz` + libdir = self.deps_cpp_info["zlib"].lib_paths[0] + autotools.extra_ldflags.extend([os.path.join(libdir, lib).replace("\\", "/") for lib in os.listdir(libdir)]) + autotools.generate() @property def _msvc_configuration(self): @@ -133,29 +151,6 @@ def _msvc_arch(self): def _patch_sources(self): apply_conandata_patches(self) - @functools.lru_cache(1) - def _configure_autotools(self): - yes_no = lambda v: "yes" if v else "no" - autotools = AutoToolsBuildEnvironment(self, win_bash=self._settings_build.os == "Windows") - autotools.libs = [] - if self.settings.os == "Windows": - if self.options.with_zlib: - libdir = self.deps_cpp_info["zlib"].lib_paths[0] - autotools.link_flags.extend([os.path.join(libdir, lib).replace("\\", "/") for lib in os.listdir(libdir)]) - autotools.configure(self.source_folder,[ - f"--enable-shared={yes_no(self.options.shared)}", - f"--enable-static={yes_no(not self.options.shared)}", - f"--enable-https={yes_no(self.options.with_https)}", - f"--enable-messages={yes_no(self.options.with_error_messages)}", - f"--enable-postprocessor={yes_no(self.options.with_postprocessor)}", - f"--enable-dauth={yes_no(self.options.with_digest_authentification)}", - f"--enable-epoll={yes_no(self.options.get_safe('epoll'))}", - "--disable-doc", - "--disable-examples", - "--disable-curl", - ]) - return autotools - def build(self): self._patch_sources() if is_msvc(self): @@ -163,7 +158,8 @@ def build(self): msbuild.build_type = self._msvc_configuration msbuild.build(sln=os.path.join(self._msvc_sln_folder, "libmicrohttpd.sln"), targets=["libmicrohttpd"]) else: - autotools = self._configure_autotools() + autotools = Autotools(self) + autotools.configure() autotools.make() def package(self): @@ -173,7 +169,7 @@ def package(self): copy(self, "*.dll", os.path.join(self.build_folder, self._msvc_sln_folder, "Output", self._msvc_arch), os.path.join(self.package_folder, "bin")) copy(self, "*.h", os.path.join(self.build_folder, self._msvc_sln_folder, "Output", self._msvc_arch), os.path.join(self.package_folder, "include")) else: - autotools = self._configure_autotools() + autotools = Autotools(self) autotools.install() rm(self, "*.la", os.path.join(self.package_folder, "lib")) From fcbc2e29dfdcc35c5293ecde99670cfeaa6678d7 Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Wed, 19 Oct 2022 16:13:22 +0200 Subject: [PATCH 14/15] Apply suggestions from code review Co-authored-by: Uilian Ries Co-authored-by: Jordan Williams --- recipes/libmicrohttpd/all/conanfile.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/recipes/libmicrohttpd/all/conanfile.py b/recipes/libmicrohttpd/all/conanfile.py index 1a356d477f374..9f5013aeb563d 100644 --- a/recipes/libmicrohttpd/all/conanfile.py +++ b/recipes/libmicrohttpd/all/conanfile.py @@ -1,7 +1,8 @@ from conan import ConanFile, Version from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rm, rmdir -from conan.tools.gnu import Autotools, AutotoolsDeps, AutotoolsToolchain, PkgConfigDeps -from conan.tools.microsoft import MSBuild, MSBuildToolchain, is_msvc, vs_layout, unix_path +from conan.tools.gnu import Autotools, AutotoolsToolchain, PkgConfigDeps +from conan.tools.microsoft import MSBuild, MSBuildToolchain, is_msvc, vs_layout +from conan.tools.layout import basic_layout from conan.errors import ConanInvalidConfiguration import os @@ -57,7 +58,10 @@ def config_options(self): def configure(self): if self.options.shared: - del self.options.fPIC + try: + del self.options.fPIC + except Exception: + pass try: del self.settings.compiler.libcxx except Exception: @@ -96,6 +100,8 @@ def export_sources(self): def layout(self): if is_msvc(self): vs_layout(self) + else: + basic_layout(self) def generate(self): if is_msvc(self): From 324800ce93b76136bb518fea3f544daa53f1c9ca Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Wed, 19 Oct 2022 16:41:00 +0200 Subject: [PATCH 15/15] copy LICENSE from source_folder --- recipes/libmicrohttpd/all/conanfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/libmicrohttpd/all/conanfile.py b/recipes/libmicrohttpd/all/conanfile.py index 9f5013aeb563d..8c7a9d8fa18cb 100644 --- a/recipes/libmicrohttpd/all/conanfile.py +++ b/recipes/libmicrohttpd/all/conanfile.py @@ -169,7 +169,7 @@ def build(self): autotools.make() def package(self): - copy(self, "COPYING", os.path.join(self.build_folder), os.path.join(self.package_folder, "licenses")) + copy(self, "COPYING", os.path.join(self.source_folder), os.path.join(self.package_folder, "licenses")) if is_msvc(self): copy(self, "*.lib", os.path.join(self.build_folder, self._msvc_sln_folder, "Output", self._msvc_arch), os.path.join(self.package_folder, "lib")) copy(self, "*.dll", os.path.join(self.build_folder, self._msvc_sln_folder, "Output", self._msvc_arch), os.path.join(self.package_folder, "bin"))