From ea28b705d265a4389556ec1a9151891f9c6ee85a Mon Sep 17 00:00:00 2001 From: SpaceIm <30052553+SpaceIm@users.noreply.github.com> Date: Wed, 13 Jan 2021 11:05:30 +0100 Subject: [PATCH 1/8] add required_conan_version validate() requires conan >=1.32.0 --- recipes/libsass/all/conanfile.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/recipes/libsass/all/conanfile.py b/recipes/libsass/all/conanfile.py index 13b26e6c8ae61..db44bc13afbbc 100644 --- a/recipes/libsass/all/conanfile.py +++ b/recipes/libsass/all/conanfile.py @@ -2,6 +2,8 @@ from conans.errors import ConanInvalidConfiguration import os +required_conan_version = ">=1.32.0" + class LibsassConan(ConanFile): name = "libsass" From d1183824ad3d56b223df2c334b9d08aaa94d77c1 Mon Sep 17 00:00:00 2001 From: SpaceIm <30052553+SpaceIm@users.noreply.github.com> Date: Wed, 13 Jan 2021 11:07:36 +0100 Subject: [PATCH 2/8] move build_requires to build_requirements() --- recipes/libsass/all/conanfile.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/recipes/libsass/all/conanfile.py b/recipes/libsass/all/conanfile.py index db44bc13afbbc..bf1e6c1b69aae 100644 --- a/recipes/libsass/all/conanfile.py +++ b/recipes/libsass/all/conanfile.py @@ -16,8 +16,6 @@ class LibsassConan(ConanFile): options = {"shared": [True, False], "fPIC": [True, False]} default_options = {"shared": False, "fPIC": True} - build_requires = "autoconf/2.69", "libtool/2.4.6" - _autotools = None @property @@ -28,6 +26,10 @@ def validate(self): if self.settings.os not in ["Linux", "FreeBSD", "Macos"]: raise ConanInvalidConfiguration("libsass supports only Linux, FreeBSD and Macos") + def build_requirements(self): + self.build_requires("autoconf/2.69") + self.build_requires("libtool/2.4.6") + def source(self): tools.get(**self.conan_data["sources"][self.version]) extracted_dir = self.name + "-" + self.version From 687f8dc6fb116a8cc3d8184924c1294c63cc607f Mon Sep 17 00:00:00 2001 From: SpaceIm <30052553+SpaceIm@users.noreply.github.com> Date: Wed, 13 Jan 2021 11:11:38 +0100 Subject: [PATCH 3/8] delete fPIC option if shared --- recipes/libsass/all/conanfile.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/recipes/libsass/all/conanfile.py b/recipes/libsass/all/conanfile.py index bf1e6c1b69aae..da7decf98bb4a 100644 --- a/recipes/libsass/all/conanfile.py +++ b/recipes/libsass/all/conanfile.py @@ -22,6 +22,10 @@ class LibsassConan(ConanFile): def _source_subfolder(self): return "source_subfolder" + def configure(self): + if self.options.shared: + del self.options.fPIC + def validate(self): if self.settings.os not in ["Linux", "FreeBSD", "Macos"]: raise ConanInvalidConfiguration("libsass supports only Linux, FreeBSD and Macos") From ff5fc4dffdfc43ebae55272b44a5bcd1f8a615f8 Mon Sep 17 00:00:00 2001 From: SpaceIm <30052553+SpaceIm@users.noreply.github.com> Date: Wed, 13 Jan 2021 11:12:00 +0100 Subject: [PATCH 4/8] explicit pkg_config name --- recipes/libsass/all/conanfile.py | 1 + 1 file changed, 1 insertion(+) diff --git a/recipes/libsass/all/conanfile.py b/recipes/libsass/all/conanfile.py index da7decf98bb4a..0339994bfeaf8 100644 --- a/recipes/libsass/all/conanfile.py +++ b/recipes/libsass/all/conanfile.py @@ -66,6 +66,7 @@ def package(self): tools.remove_files_by_mask(self.package_folder, "*.la") def package_info(self): + self.cpp_info.names["pkg_config"] = "libsass" self.cpp_info.libs = ["sass"] if self.settings.os in ["Linux", "FreeBSD"]: self.cpp_info.system_libs = ["dl", "m"] From 7268065bff7224fb1691c37ed6b9ed0c3698d5a3 Mon Sep 17 00:00:00 2001 From: SpaceIm <30052553+SpaceIm@users.noreply.github.com> Date: Wed, 13 Jan 2021 12:13:26 +0100 Subject: [PATCH 5/8] early ConanInvalidConfiguration in configure() Co-authored-by: ericLemanissier --- recipes/libsass/all/conanfile.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/recipes/libsass/all/conanfile.py b/recipes/libsass/all/conanfile.py index 0339994bfeaf8..b307406de1bd1 100644 --- a/recipes/libsass/all/conanfile.py +++ b/recipes/libsass/all/conanfile.py @@ -2,8 +2,6 @@ from conans.errors import ConanInvalidConfiguration import os -required_conan_version = ">=1.32.0" - class LibsassConan(ConanFile): name = "libsass" @@ -25,8 +23,6 @@ def _source_subfolder(self): def configure(self): if self.options.shared: del self.options.fPIC - - def validate(self): if self.settings.os not in ["Linux", "FreeBSD", "Macos"]: raise ConanInvalidConfiguration("libsass supports only Linux, FreeBSD and Macos") From e6c68f219cd536f18cb5f0f9768c378d8c7eb7a9 Mon Sep 17 00:00:00 2001 From: SpaceIm <30052553+SpaceIm@users.noreply.github.com> Date: Wed, 13 Jan 2021 12:17:41 +0100 Subject: [PATCH 6/8] requires conan >= 1.29.1 for tools.remove_files_by_mask() --- recipes/libsass/all/conanfile.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/recipes/libsass/all/conanfile.py b/recipes/libsass/all/conanfile.py index b307406de1bd1..2e61549292a31 100644 --- a/recipes/libsass/all/conanfile.py +++ b/recipes/libsass/all/conanfile.py @@ -2,6 +2,8 @@ from conans.errors import ConanInvalidConfiguration import os +required_conan_version = ">=1.29.1" + class LibsassConan(ConanFile): name = "libsass" From cd85f5699b94ca4985d1091aec34331dfe241ce0 Mon Sep 17 00:00:00 2001 From: SpaceIm <30052553+SpaceIm@users.noreply.github.com> Date: Wed, 13 Jan 2021 14:46:20 +0100 Subject: [PATCH 7/8] add mingw support --- recipes/libsass/all/conanfile.py | 65 ++++++++++++++++++++++++++++---- 1 file changed, 57 insertions(+), 8 deletions(-) diff --git a/recipes/libsass/all/conanfile.py b/recipes/libsass/all/conanfile.py index 2e61549292a31..175c750143fe2 100644 --- a/recipes/libsass/all/conanfile.py +++ b/recipes/libsass/all/conanfile.py @@ -22,15 +22,25 @@ class LibsassConan(ConanFile): def _source_subfolder(self): return "source_subfolder" + @property + def _is_mingw(self): + return self.settings.os == "Windows" and self.settings.compiler == "gcc" + + def config_options(self): + if self.settings.os == "Windows": + del self.options.fPIC + def configure(self): if self.options.shared: del self.options.fPIC - if self.settings.os not in ["Linux", "FreeBSD", "Macos"]: - raise ConanInvalidConfiguration("libsass supports only Linux, FreeBSD and Macos") + if self.settings.compiler == "Visual Studio": + # TODO: add Visual Studio support + raise ConanInvalidConfiguration("Visual Studio not yet supported in libsass recipe") def build_requirements(self): - self.build_requires("autoconf/2.69") - self.build_requires("libtool/2.4.6") + if self.settings.os != "Windows": + self.build_requires("autoconf/2.69") + self.build_requires("libtool/2.4.6") def source(self): tools.get(**self.conan_data["sources"][self.version]) @@ -40,7 +50,6 @@ def source(self): def _configure_autotools(self): if self._autotools: return self._autotools - self.run("autoreconf -fiv", run_environment=True) self._autotools = AutoToolsBuildEnvironment(self) args = [] args.append("--disable-tests") @@ -49,20 +58,60 @@ def _configure_autotools(self): self._autotools.configure(args=args) return self._autotools - def build(self): + def _build_autotools(self): with tools.chdir(self._source_subfolder): tools.save(path="VERSION", content="%s" % self.version) + self.run("{} -fiv".format(tools.get_env("AUTORECONF"))) autotools = self._configure_autotools() autotools.make() - def package(self): + @property + def _make_program(self): + return tools.get_env("CONAN_MAKE_PROGRAM", tools.which("make") or tools.which("mingw32-make")) + + def _build_mingw(self): + makefile = os.path.join(self._source_subfolder, "Makefile") + tools.replace_in_file(makefile, "CFLAGS += -O2", "") + tools.replace_in_file(makefile, "CXXFLAGS += -O2", "") + tools.replace_in_file(makefile, "LDFLAGS += -O2", "") + with tools.chdir(self._source_subfolder): + env_vars = AutoToolsBuildEnvironment(self).vars + env_vars.update({ + "BUILD": "shared" if self.options.shared else "static", + "PREFIX": tools.unix_path(os.path.join(self.package_folder)), + # Don't force static link to mingw libs, leave this decision to consumer (through LDFLAGS in env) + "STATIC_ALL": "0", + "STATIC_LIBGCC": "0", + "STATIC_LIBSTDCPP": "0", + }) + with tools.environment_append(env_vars): + self.run("{} -f Makefile".format(self._make_program)) + + def build(self): + if self._is_mingw: + self._build_mingw() + else: + self._build_autotools() + + def _install_autotools(self): with tools.chdir(self._source_subfolder): autotools = self._configure_autotools() autotools.install() - self.copy("LICENSE", src=self._source_subfolder, dst="licenses") tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig")) tools.remove_files_by_mask(self.package_folder, "*.la") + def _install_mingw(self): + self.copy("*.h", dst="include", src=os.path.join(self._source_subfolder, "include")) + self.copy("*.dll", dst="bin", src=os.path.join(self._source_subfolder, "lib")) + self.copy("*.a", dst="lib", src=os.path.join(self._source_subfolder, "lib")) + + def package(self): + self.copy("LICENSE", src=self._source_subfolder, dst="licenses") + if self._is_mingw: + self._install_mingw() + else: + self._install_autotools() + def package_info(self): self.cpp_info.names["pkg_config"] = "libsass" self.cpp_info.libs = ["sass"] From 48df4496fb3235bee622653adb6c294801405696 Mon Sep 17 00:00:00 2001 From: SpaceIm <30052553+SpaceIm@users.noreply.github.com> Date: Wed, 13 Jan 2021 14:46:59 +0100 Subject: [PATCH 8/8] allow to be consumed in C project libsass is a C++ library with C API --- recipes/libsass/all/conanfile.py | 4 +++- recipes/libsass/all/test_package/CMakeLists.txt | 5 ++--- .../all/test_package/{test_package.cpp => test_package.c} | 5 +++-- 3 files changed, 8 insertions(+), 6 deletions(-) rename recipes/libsass/all/test_package/{test_package.cpp => test_package.c} (78%) diff --git a/recipes/libsass/all/conanfile.py b/recipes/libsass/all/conanfile.py index 175c750143fe2..f25db37cb13b1 100644 --- a/recipes/libsass/all/conanfile.py +++ b/recipes/libsass/all/conanfile.py @@ -116,4 +116,6 @@ def package_info(self): self.cpp_info.names["pkg_config"] = "libsass" self.cpp_info.libs = ["sass"] if self.settings.os in ["Linux", "FreeBSD"]: - self.cpp_info.system_libs = ["dl", "m"] + self.cpp_info.system_libs.extend(["dl", "m"]) + if not self.options.shared and tools.stdcpp_library(self): + self.cpp_info.system_libs.append(tools.stdcpp_library(self)) diff --git a/recipes/libsass/all/test_package/CMakeLists.txt b/recipes/libsass/all/test_package/CMakeLists.txt index e97ecc6c7a569..7b9b613cbb24a 100644 --- a/recipes/libsass/all/test_package/CMakeLists.txt +++ b/recipes/libsass/all/test_package/CMakeLists.txt @@ -1,9 +1,8 @@ cmake_minimum_required(VERSION 3.1) -project(test_package) - +project(test_package C) include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) conan_basic_setup() -add_executable(${PROJECT_NAME} test_package.cpp) +add_executable(${PROJECT_NAME} test_package.c) target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS}) diff --git a/recipes/libsass/all/test_package/test_package.cpp b/recipes/libsass/all/test_package/test_package.c similarity index 78% rename from recipes/libsass/all/test_package/test_package.cpp rename to recipes/libsass/all/test_package/test_package.c index f726b99f6f31e..33bd73b9a2757 100644 --- a/recipes/libsass/all/test_package/test_package.cpp +++ b/recipes/libsass/all/test_package/test_package.c @@ -1,5 +1,6 @@ -#include "sass.h" -#include +#include + +#include int main() { printf("libsass version %s\t language version %s\n", libsass_version(), libsass_language_version());