-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add soxr port * Make config.yml end with a newline * Extract pffft license header from source file * Remove pkgconfig and share folders * Add libm to package_info * Fix fPIC option * Use cmake_find_package_multi generator Co-authored-by: Uilian Ries <uilianries@gmail.com> * Simplify license header extraction * Minor tweak * Fix tools.save call * Use CMake conan helper wrapper * Fix missing newline at end-of-file * Apply suggestions from code review Co-authored-by: Anonymous Maarten <madebr@users.noreply.github.com> * Add separate components for core and lsr * Fix missing newline at end-of-file Co-authored-by: chausner <chausner@users.noreply.github.com> Co-authored-by: Uilian Ries <uilianries@gmail.com> Co-authored-by: Anonymous Maarten <madebr@users.noreply.github.com>
- Loading branch information
1 parent
5fd80ce
commit d298dc7
Showing
10 changed files
with
213 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
cmake_minimum_required(VERSION 2.8.11) | ||
project(cmake_wrapper) | ||
|
||
include(conanbuildinfo.cmake) | ||
conan_basic_setup() | ||
|
||
add_subdirectory("source_subfolder") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
sources: | ||
"0.1.3": | ||
url: https://sourceforge.net/projects/soxr/files/soxr-0.1.3-Source.tar.xz | ||
sha1: "32ea46b1a8c0c15f835422892d02fce8286aec3c" | ||
patches: | ||
"0.1.3": | ||
- base_path: source_subfolder | ||
patch_file: "patches/findpackage-openmp.patch" | ||
- base_path: source_subfolder | ||
patch_file: "patches/cmake-source-dir.patch" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
from conans import ConanFile, CMake, tools | ||
import os | ||
import re | ||
|
||
required_conan_version = ">=1.33.0" | ||
|
||
|
||
class SoxrConan(ConanFile): | ||
name = "soxr" | ||
description = "The SoX Resampler library libsoxr performs fast, high-quality one-dimensional sample rate conversion." | ||
homepage = "https://sourceforge.net/projects/soxr/" | ||
topics = ("resampling", "audio", "sample-rate", "conversion") | ||
license = "LGPL-2.1-or-later" | ||
url = "https://github.com/conan-io/conan-center-index" | ||
settings = "os", "compiler", "build_type", "arch" | ||
options = { | ||
"shared": [True, False], | ||
"fPIC": [True, False], | ||
"with_openmp": [True, False], | ||
"with_lsr_bindings": [True, False] | ||
} | ||
default_options = { | ||
"shared": False, | ||
"fPIC": True, | ||
"with_openmp": False, | ||
"with_lsr_bindings": True | ||
} | ||
generators = "cmake" | ||
exports_sources = ["CMakeLists.txt", "patches/**"] | ||
|
||
_cmake = None | ||
|
||
@property | ||
def _source_subfolder(self): | ||
return "source_subfolder" | ||
|
||
@property | ||
def _build_subfolder(self): | ||
return "build_subfolder" | ||
|
||
def config_options(self): | ||
if self.settings.os == "Windows": | ||
del self.options.fPIC | ||
|
||
def configure(self): | ||
if self.options.shared: | ||
del self.options.fPIC | ||
del self.settings.compiler.cppstd | ||
del self.settings.compiler.libcxx | ||
|
||
def source(self): | ||
tools.get(**self.conan_data["sources"][self.version], | ||
destination=self._source_subfolder, strip_root=True) | ||
|
||
def _configure_cmake(self): | ||
if self._cmake: | ||
return self._cmake | ||
self._cmake = CMake(self) | ||
if self.settings.compiler == "Visual Studio": | ||
self._cmake.definitions["BUILD_SHARED_RUNTIME"] = "MD" in self.settings.compiler.runtime | ||
elif self.settings.compiler == "msvc": | ||
self._cmake.definitions["BUILD_SHARED_RUNTIME"] = self.settings.compiler.runtime == "dynamic" | ||
self._cmake.definitions["BUILD_TESTS"] = False | ||
self._cmake.definitions["WITH_OPENMP"] = self.options.with_openmp | ||
self._cmake.definitions["WITH_LSR_BINDINGS"] = self.options.with_lsr_bindings | ||
self._cmake.configure(build_folder=self._build_subfolder) | ||
return self._cmake | ||
|
||
def build(self): | ||
for patch in self.conan_data.get("patches", {}).get(self.version, []): | ||
tools.patch(**patch) | ||
cmake = self._configure_cmake() | ||
cmake.build() | ||
|
||
def _extract_pffft_license(self): | ||
# extract license header from pffft.c and store it in the package folder | ||
pffft_c = tools.load(os.path.join(self._source_subfolder, "src", "pffft.c")) | ||
license_header = re.search(r"/\* (Copyright.*?)\*/", pffft_c, re.DOTALL).group(1) | ||
license_header = "\n".join(line.lstrip() for line in license_header.splitlines()) | ||
tools.save(os.path.join(self.package_folder, "licenses", "pffft"), license_header) | ||
|
||
def package(self): | ||
self.copy("LICENCE", dst="licenses", src=self._source_subfolder) | ||
self._extract_pffft_license() | ||
cmake = self._configure_cmake() | ||
cmake.install() | ||
tools.rmdir(os.path.join(self.package_folder, "doc")) | ||
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig")) | ||
tools.rmdir(os.path.join(self.package_folder, "share")) | ||
|
||
def package_info(self): | ||
# core component | ||
self.cpp_info.components["core"].names["pkg_config"] = "soxr" | ||
self.cpp_info.components["core"].libs = ["soxr"] | ||
if self.settings.os in ("FreeBSD", "Linux"): | ||
self.cpp_info.components["core"].system_libs = ["m"] | ||
if self.settings.os == "Windows" and self.options.shared: | ||
self.cpp_info.components["core"].defines.append("SOXR_DLL") | ||
if not self.options.shared and self.options.with_openmp: | ||
if self.settings.compiler in ("Visual Studio", "msvc"): | ||
openmp_flags = ["-openmp"] | ||
elif self.settings.compiler in ("gcc", "clang"): | ||
openmp_flags = ["-fopenmp"] | ||
elif self.settings.compiler == "apple-clang": | ||
openmp_flags = ["-Xpreprocessor", "-fopenmp"] | ||
else: | ||
openmp_flags = [] | ||
self.cpp_info.components["core"].exelinkflags = openmp_flags | ||
self.cpp_info.components["core"].sharedlinkflags = openmp_flags | ||
# lsr component | ||
if self.options.with_lsr_bindings: | ||
self.cpp_info.components["lsr"].names["pkg_config"] = "soxr-lsr" | ||
self.cpp_info.components["lsr"].libs = ["soxr-lsr"] | ||
if self.settings.os == "Windows" and self.options.shared: | ||
self.cpp_info.components["lsr"].defines.append("SOXR_DLL") | ||
self.cpp_info.components["lsr"].requires = ["core"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Patch required for proper resolving of CMake modules when using the CMake conan helper wrapper. | ||
--- CMakeLists.txt | ||
+++ CMakeLists.txt | ||
@@ -84,7 +84,7 @@ mark_as_advanced (WITH_HI_PREC_CLOCK WITH_FLOAT_STD_PREC_CLOCK | ||
|
||
# Introspection: | ||
|
||
-list (APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules) | ||
+list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules) | ||
|
||
include (CheckFunctionExists) | ||
include (CheckIncludeFiles) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Adds the REQUIRED flag to find_package for OpenMP so that | ||
we can be sure in the conanfile that if with_openmp is set | ||
that OpenMP is indeed used. This is important since we need to add | ||
compiler flags in package_info() in this case. | ||
--- CMakeLists.txt | ||
+++ CMakeLists.txt | ||
@@ -105,7 +105,7 @@ if (${BUILD_EXAMPLES}) | ||
endif () | ||
|
||
if (WITH_OPENMP) | ||
- find_package (OpenMP) | ||
+ find_package (OpenMP REQUIRED) | ||
if (OPENMP_FOUND) | ||
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") | ||
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
cmake_minimum_required(VERSION 3.1) | ||
project(test_package C) | ||
|
||
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) | ||
conan_basic_setup(TARGETS) | ||
|
||
find_package(soxr CONFIG REQUIRED) | ||
|
||
add_executable(test_package_core test_package_core.c) | ||
target_link_libraries(test_package_core soxr::core) | ||
|
||
if(TARGET soxr::lsr) | ||
add_executable(test_package_lsr test_package_lsr.c) | ||
target_link_libraries(test_package_lsr soxr::lsr) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import os | ||
from conans import ConanFile, CMake, tools | ||
|
||
class TestPackageConan(ConanFile): | ||
settings = "os", "compiler", "build_type", "arch" | ||
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): | ||
# core component | ||
bin_path = os.path.join("bin", "test_package_core") | ||
self.run(bin_path, run_environment=True) | ||
# lsr component | ||
if self.options["soxr"].with_lsr_bindings: | ||
bin_path = os.path.join("bin", "test_package_lsr") | ||
self.run(bin_path, run_environment=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include <soxr.h> | ||
#include <stdio.h> | ||
|
||
int main() { | ||
printf("soxr version: %s\n", soxr_version()); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include <soxr-lsr.h> | ||
#include <stdio.h> | ||
|
||
int main() { | ||
printf("soxr-lsr version: %s\n", src_get_version()); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
versions: | ||
"0.1.3": | ||
folder: all |