Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

liquid-dsp: migrate to Conan v2 #18866

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
7 changes: 3 additions & 4 deletions recipes/liquid-dsp/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
sources:
"1.6.0":
url: "https://github.com/jgaeddert/liquid-dsp/archive/v1.6.0.tar.gz"
sha256: "6ee6a5dfb48e047b118cf613c0b9f43e34356a5667a77a72a55371d2c8c53bf5"
"1.3.2":
url: "https://github.com/jgaeddert/liquid-dsp/archive/refs/tags/v1.3.2.tar.gz"
sha256: "85093624EF9CB90EAD64C836D2F42690197EDACE1A86257D6524C4E4DC870483"
patches:
"1.3.2":
- patch_file: "patches/1.3.2/0001-Remove-headers-check.patch"
base_path: "source_subfolder"
216 changes: 78 additions & 138 deletions recipes/liquid-dsp/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,45 +1,42 @@
from conans import ConanFile, tools
from conans.errors import ConanInvalidConfiguration
from contextlib import contextmanager
import os

required_conan_version = ">=1.33.0"
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.apple import is_apple_os
from conan.tools.build import cross_building
from conan.tools.env import Environment, VirtualBuildEnv
from conan.tools.files import chdir, copy, get, rename
from conan.tools.gnu import Autotools, AutotoolsToolchain
from conan.tools.layout import basic_layout
from conan.tools.microsoft import is_msvc

required_conan_version = ">=1.53.0"


class LiquidDspConan(ConanFile):
name = "liquid-dsp"
description = (
"Digital signal processing library for software-defined radios (and more)"
)
topics = ("dsp", "sdr", "liquid-dsp")
description = "Digital signal processing library for software-defined radios (and more)"
license = "MIT"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/jgaeddert/liquid-dsp"
license = ("MIT",)
settings = "os", "arch", "build_type", "compiler"
exports_sources = ["generate_link_library.bat"]
topics = ("dsp", "sdr")

package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"simdoverride": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"simdoverride": False,
}

_autotools = None

@property
def _source_subfolder(self):
return "source_subfolder"

@property
def _libname(self):
if self.settings.os == "Windows":
return "libliquid"
return "liquid"

@property
def _target_name(self):
if self.settings.os == "Macos":
if is_apple_os(self):
if not self.options.shared:
return "libliquid.ar"
return "libliquid.dylib"
Expand All @@ -49,138 +46,81 @@ def _target_name(self):

@property
def _lib_pattern(self):
if self.settings.os == "Macos" and not self.options.shared:
if is_apple_os(self) and not self.options.shared:
return "libliquid.a"
if self.settings.os != "Windows":
return self._target_name
return "libliquid.lib"
return self._target_name

def configure(self):
del self.settings.compiler.cppstd
del self.settings.compiler.libcxx
def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

@property
def _settings_build(self):
return getattr(self, "settings_build", self.settings)
def configure(self):
self.settings.rm_safe("compiler.cppstd")
self.settings.rm_safe("compiler.libcxx")
if self.options.shared:
self.options.rm_safe("fPIC")

def build_requirements(self):
if self._settings_build.os == "Windows" and not tools.get_env("CONAN_BASH_PATH"):
self.build_requires("msys2/cci.latest")
if self.settings.compiler == "Visual Studio":
self.build_requires("mingw-w64/8.1")
self.build_requires("automake/1.16.4")

def export_sources(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
self.copy(patch["patch_file"])
def layout(self):
basic_layout(self, src_folder="src")

def validate(self):
if hasattr(self, "settings_build") and tools.cross_building(self):
if cross_building(self):
raise ConanInvalidConfiguration("Cross building is not yet supported. Contributions are welcome")
if is_msvc(self):
raise ConanInvalidConfiguration("MSVC is not supported due to missing 'complex' data type support")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Conan 1 this recipe supports Windows, why are we removing support in this migration?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It did so only through fetching MinGW via Conan and building with it instead of MSVC. I did try that approach and got it to work locally, but it kept failing on C3I due to a missing DLL despite at least 10 iterations of trying to fix this (and Windows is very unhelpful with its DLL error messages).
Relying on GCC from MinGW is a bit of a fragile edge-case for Conan, since it also becomes a build/runtime dependency unless you link GCC statically into a shared library. It's not well supported. See also #21193 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okey, we will leave this for the future then. It is better to have this recipe working in conan v2 for now. Even if it does not support MSVC


def build_requirements(self):
# For ./bootstrap.sh
self.tool_requires("autoconf/2.71")
self.tool_requires("automake/1.16.5")

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

def _patch_sources(self):
if self.settings.os == "Windows":
for patch in self.conan_data["patches"][self.version]:
tools.patch(**patch)

def _gen_link_library(self):
if self.settings.compiler != "Visual Studio" or (not self.options.shared):
return
self.run("cmd /c generate_link_library.bat")
with tools.chdir(self._source_subfolder):
self.run(
"{} /def:libliquid.def /out:libliquid.lib /machine:{}".format(
os.getenv("AR"), "X86" if self.settings.arch == "x86" else "X64"
),
win_bash=tools.os_info.is_windows,
)
def generate(self):
venv = VirtualBuildEnv(self)
venv.generate()

def _rename_libraries(self):
with tools.chdir(self._source_subfolder):
if self.settings.os == "Windows" and self.options.shared:
tools.rename("libliquid.so", "libliquid.dll")
elif self.settings.os == "Windows" and not self.options.shared:
tools.rename("libliquid.a", "libliquid.lib")
elif self.settings.os == "Macos" and not self.options.shared:
tools.rename("libliquid.ar", "libliquid.a")

@contextmanager
def _build_context(self):
if self.settings.compiler == "Visual Studio":
env = {
"CC": "gcc",
"CXX": "g++",
"LD": "ld",
"AR": "ar",
}
with tools.environment_append(env):
yield
else:
yield

@contextmanager
def _msvc_context(self):
if self.settings.compiler == "Visual Studio":
with tools.vcvars(self.settings):
env = {
"CC": "cl -nologo",
"CXX": "cl -nologo",
"AR": "lib",
"LD": "link",
}
with tools.environment_append(env):
yield
gcc_env = Environment()
if self.settings.build_type == "Debug":
cflags = "-g -O0"
else:
yield
cflags = "-s -O2 -DNDEBUG"
gcc_env.append("CFLAGS", cflags)
gcc_env.vars(self, scope="gcc").save_script("conan_gcc_env")

def build(self):
self._patch_sources()
ncpus = tools.cpu_count()
configure_args = []
cflags = ["-static-libgcc"]
tc = AutotoolsToolchain(self)
if self.settings.build_type == "Debug":
configure_args.append("--enable-debug-messages")
cflags.extend(["-g", "-O0"])
else:
cflags.extend(["-s", "-O2", "-DNDEBUG"])
tc.configure_args.append("--enable-debug-messages")
if self.options.simdoverride:
configure_args.append("--enable-simdoverride")
if self.settings.compiler == "Visual Studio":
configure_args.append("CFLAGS='{}'".format(" ".join(cflags)))
configure_args_str = " ".join(configure_args)
with self._build_context():
with tools.chdir(self._source_subfolder):
self.run("./bootstrap.sh", win_bash=tools.os_info.is_windows)
self.run(
"./configure {}".format(configure_args_str),
win_bash=tools.os_info.is_windows,
)
self.run(
"make {} -j{}".format(self._target_name, ncpus),
win_bash=tools.os_info.is_windows,
)
tc.configure_args.append("--enable-simdoverride")
tc.generate(gcc_env)

def _rename_libraries(self):
with chdir(self, self.source_folder):
if is_apple_os(self) and not self.options.shared:
rename(self, "libliquid.ar", "libliquid.a")

def build(self):
with chdir(self, self.source_folder):
self.run("./bootstrap.sh", env=["conanbuild", "gcc"])
autotools = Autotools(self)
autotools.configure()
autotools.make(self._target_name)
self._rename_libraries()
with self._msvc_context():
self._gen_link_library()

def package(self):
self.copy(pattern="LICENSE", src=self._source_subfolder, dst="licenses")
self.copy(
pattern="liquid.h",
dst=os.path.join("include", "liquid"),
src=os.path.join(self._source_subfolder, "include"),
)
self.copy(pattern="libliquid.dll", dst="bin", src=self._source_subfolder)
self.copy(pattern=self._lib_pattern, dst="lib", src=self._source_subfolder)
copy(self, "LICENSE",
dst=os.path.join(self.package_folder, "licenses"),
src=self.source_folder)
copy(self, "liquid.h",
dst=os.path.join(self.package_folder, "include", "liquid"),
src=os.path.join(self.source_folder, "include"))
copy(self, self._lib_pattern,
dst=os.path.join(self.package_folder, "lib"),
src=self.source_folder)

def package_info(self):
self.cpp_info.libs = [self._libname]
if self.settings.os == "Linux":
self.cpp_info.libs = ["liquid"]
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs.append("m")
4 changes: 0 additions & 4 deletions recipes/liquid-dsp/all/generate_link_library.bat

This file was deleted.

This file was deleted.

9 changes: 4 additions & 5 deletions recipes/liquid-dsp/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
cmake_minimum_required(VERSION 3.0)
project(test_package)
cmake_minimum_required(VERSION 3.15)
project(test_package LANGUAGES CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
find_package(liquid-dsp REQUIRED CONFIG)

add_executable(${CMAKE_PROJECT_NAME} test_package.cpp)
target_link_libraries(${CMAKE_PROJECT_NAME} ${CONAN_LIBS})
target_link_libraries(${CMAKE_PROJECT_NAME} liquid-dsp::liquid-dsp)
21 changes: 15 additions & 6 deletions recipes/liquid-dsp/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
from conans import ConanFile, CMake, tools
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"

def requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self.settings):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindir, "test_package")
self.run(bin_path, env="conanrun")
2 changes: 2 additions & 0 deletions recipes/liquid-dsp/config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
versions:
"1.6.0":
folder: "all"
"1.3.2":
folder: "all"
Loading