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

gnuradio-volk: new recipe #23380

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions recipes/gnuradio-volk/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"3.1.2":
url: "https://github.com/gnuradio/volk/archive/refs/tags/v3.1.2.tar.gz"
sha256: "90082bf68d76d00aa6c35f8bff0e93891b4204d817e1a3ba829486b445f715dc"
140 changes: 140 additions & 0 deletions recipes/gnuradio-volk/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
import os

from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.env import VirtualBuildEnv, Environment
from conan.tools.files import copy, get, rm, save, rmdir
from conan.tools.scm import Version

required_conan_version = ">=1.53.0"


class GnuradioVolkConan(ConanFile):
name = "gnuradio-volk"
description = "VOLK is the Vector-Optimized Library of Kernels."
license = "LGPL-3.0-or-later"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://www.libvolk.org/"
topics = ("simd", "kernel", "sdr", "dsp", "gnuradio")

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

@property
def _min_cppstd(self):
return 17

@property
def _compilers_minimum_version(self):
return {
"gcc": "7",
"clang": "6",
"apple-clang": "10",
"Visual Studio": "15",
"msvc": "191",
}

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

def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")
# To avoid ConanInvalidConfiguration on Windows
self.options["cpython"].shared = True

def layout(self):
cmake_layout(self, src_folder="src")

def requirements(self):
self.requires("cpu_features/0.9.0")
# TODO: add recipe for gstreamer-orc https://github.com/GStreamer/orc

def validate(self):
if self.settings.compiler.cppstd:
check_min_cppstd(self, self._min_cppstd)
minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
if minimum_version and Version(self.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration(
f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support."
)

def build_requirements(self):
self.tool_requires("cpython/3.10.0")
# To avoid a conflict with CMake installed via pip on the system Python
self.tool_requires("cmake/[>=3.15 <4]")

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

@property
def _site_packages_dir(self):
return os.path.join(self.build_folder, "site-packages")

def generate(self):
venv = VirtualBuildEnv(self)
venv.generate()

tc = CMakeToolchain(self)
tc.variables["ENABLE_STATIC_LIBS"] = not self.options.shared
tc.variables["ENABLE_TESTING"] = False
tc.variables["ENABLE_MODTOOL"] = False # Requires Python
tc.variables["ENABLE_ORC"] = False # Not available on CCI
tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0148"] = "OLD" # FindPythonInterp support
tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0077"] = "NEW" # tc.requires support
tc.generate()

deps = CMakeDeps(self)
deps.generate()

env = Environment()
env.append_path("PYTHONPATH", self._site_packages_dir)
env.append_path("PATH", os.path.join(self._site_packages_dir, "bin"))
env.vars(self).save_script("pythonpath")

def _patch_sources(self):
# Disable apps
save(self, os.path.join(self.source_folder, "apps", "CMakeLists.txt"), "")

def _pip_install(self, packages):
self.run(f"python -m pip install {' '.join(packages)} --no-cache-dir --target={self._site_packages_dir}")

def build(self):
self._patch_sources()
self._pip_install(["mako"])
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
copy(self, "COPYING", self.source_folder, os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()
if not self.options.shared:
rm(self, "*.so*", os.path.join(self.package_folder, "lib"))
rm(self, "*.dylib*", os.path.join(self.package_folder, "lib"))
rm(self, "volk.dll.lib", os.path.join(self.package_folder, "lib"))
rm(self, "volk.dll", os.path.join(self.package_folder, "bin"))
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
rm(self, "*.pdb", os.path.join(self.package_folder, "lib"))
rm(self, "*.pdb", os.path.join(self.package_folder, "bin"))

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "Volk")
self.cpp_info.set_property("cmake_target_name", "Volk::volk")
self.cpp_info.set_property("pkg_config_name", "volk")
self.cpp_info.libs = ["volk"]
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs.extend(["m", "pthread"])
8 changes: 8 additions & 0 deletions recipes/gnuradio-volk/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.15)
project(test_package LANGUAGES CXX)

find_package(Volk REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE Volk::volk)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
27 changes: 27 additions & 0 deletions recipes/gnuradio-volk/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os


# It will become the standard on Conan 2.x
class TestPackageConan(ConanFile):
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 can_run(self):
bin_path = os.path.join(self.cpp.build.bindir, "test_package")
self.run(bin_path, env="conanrun")
28 changes: 28 additions & 0 deletions recipes/gnuradio-volk/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <volk/volk.h>

int main() {
int N = 10;
unsigned int alignment = volk_get_alignment();
float* in = (float*)volk_malloc(sizeof(float)*N, alignment);
float* out = (float*)volk_malloc(sizeof(float)*N, alignment);

in[0] = 0.000;
in[1] = 0.524;
in[2] = 0.786;
in[3] = 1.047;
in[4] = 1.571;
in[5] = 1.571;
in[6] = 2.094;
in[7] = 2.356;
in[8] = 2.618;
in[9] = 3.142;

volk_32f_cos_32f(out, in, N);

for(unsigned int ii = 0; ii < N; ++ii){
printf("cos(%1.3f) = %1.3f\n", in[ii], out[ii]);
}

volk_free(in);
volk_free(out);
}
3 changes: 3 additions & 0 deletions recipes/gnuradio-volk/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"3.1.2":
folder: all
Loading