Repository: conan-io/conan-center-index

Issue:
[request] <miniaud.io>/<0.10.32>
### Package Details
  * Package Name/Version: **miniaud.io/0.10.32**
  * Website: **http://miniaud.io/**
  * Source code: **https://github.com/mackron/miniaudio**


### Description Of The Library / Tool

This is a header-only library that gives a cross platform-audio API, including webasm. 

I'd like to see it in conan. I could do it myself, if you have pointers about recipes for header-only libs. 


Discussion:
Extra info: the master branch on github always has the latest stable version. Versions are given by the specific commit on the master branch. 

Resolving patch:
diff --git a/recipes/miniaudio/all/conanfile.py b/recipes/miniaudio/all/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/miniaudio/all/conanfile.py
@@ -0,0 +1,69 @@
+from conans import ConanFile, tools
+import os
+import glob
+
+
+class MiniaudioConan(ConanFile):
+    name = "miniaudio"
+    description = "A single file audio playback and capture library."
+    topics = ("conan", "miniaudio", "header-only", "sound")
+    homepage = "https://github.com/mackron/miniaudio"
+    url = "https://github.com/conan-io/conan-center-index"
+    license = ["Unlicense", "MIT-0"]
+    settings = "os", "compiler", "build_type", "arch"
+
+    no_copy_source = True
+
+    @property
+    def _source_subfolder(self):
+        return "source_subfolder"
+
+    def source(self):
+        tools.get(**self.conan_data["sources"][self.version])
+        extracted_dir = glob.glob(self.name + "-*/")[0]
+        os.rename(extracted_dir, self._source_subfolder)
+
+    def package(self):
+        self.copy(pattern="LICENSE", dst="licenses", src=self._source_subfolder)
+        self.copy(pattern="miniaudio.h", dst="include", src=self._source_subfolder)
+        self.copy(
+            pattern="stb_vorbis.c",
+            dst="include/extras",
+            src=os.path.join(self._source_subfolder, "extras"),
+        )
+        self.copy(
+            pattern="dr_*.h",
+            dst="include/extras",
+            src=os.path.join(self._source_subfolder, "extras"),
+        )
+        self.copy(
+            pattern="ma_speex_resampler.h",
+            dst="include/extras/speex_resampler/",
+            src=os.path.join(self._source_subfolder, "extras/speex_resampler/"),
+        )
+        self.copy(
+            pattern="*.*",
+            dst="include/extras/speex_resampler/thirdparty",
+            src=os.path.join(
+                self._source_subfolder, "extras/speex_resampler/thirdparty"
+            ),
+        )
+        self.copy(
+            pattern="miniaudio.*",
+            dst="include/extras/miniaudio_split",
+            src=os.path.join(self._source_subfolder, "extras/miniaudio_split"),
+        )
+
+    def package_info(self):
+        if self.settings.os in ["Linux", "FreeBSD"]:
+            self.cpp_info.system_libs.extend(["m", "pthread"])
+        if self.settings.os == "Linux":
+            self.cpp_info.system_libs.append("dl")
+        if self.settings.os == "Macos":
+            self.cpp_info.frameworks.extend(
+                ["CoreFoundation", "CoreAudio", "AudioUnit"]
+            )
+            self.cpp_info.defines.append("MA_NO_RUNTIME_LINKING=1")
+
+    def package_id(self):
+        self.info.header_only()


Test patch:
diff --git a/recipes/miniaudio/all/test_package/CMakeLists.txt b/recipes/miniaudio/all/test_package/CMakeLists.txt
new file mode 100644
--- /dev/null
+++ b/recipes/miniaudio/all/test_package/CMakeLists.txt
@@ -0,0 +1,7 @@
+cmake_minimum_required(VERSION 3.1)
+project(test_package C)
+
+find_package(miniaudio REQUIRED)
+
+add_executable(test_package example.c)
+target_link_libraries(test_package miniaudio::miniaudio)
diff --git a/recipes/miniaudio/all/test_package/conanfile.py b/recipes/miniaudio/all/test_package/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/miniaudio/all/test_package/conanfile.py
@@ -0,0 +1,16 @@
+from conans import ConanFile, CMake, tools
+import os
+
+
+class TestPackageConan(ConanFile):
+    settings = "os", "compiler", "build_type", "arch"
+    generators = "cmake_find_package"
+
+    def build(self):
+        cmake = CMake(self)
+        cmake.configure()
+        cmake.build()
+
+    def test(self):
+        if not tools.cross_building(self.settings):
+            self.run("test_package", run_environment=True)
diff --git a/recipes/miniaudio/all/test_package/example.c b/recipes/miniaudio/all/test_package/example.c
new file mode 100644
--- /dev/null
+++ b/recipes/miniaudio/all/test_package/example.c
@@ -0,0 +1,51 @@
+/*
+Demonstrates how to enumerate over devices.
+Device enumaration requires a `ma_context` object which is initialized with
+`ma_context_init()`. Conceptually, the context sits above a device. You can have
+many devices to one context. If you use device enumeration, you should
+explicitly specify the same context you used for enumeration in the call to
+`ma_device_init()` when you initialize your devices.
+*/
+#define MINIAUDIO_IMPLEMENTATION
+#include <miniaudio.h>
+
+#include <stdio.h>
+
+int main(int argc, char **argv) {
+  ma_result result;
+  ma_context context;
+  ma_device_info *pPlaybackDeviceInfos;
+  ma_uint32 playbackDeviceCount;
+  ma_device_info *pCaptureDeviceInfos;
+  ma_uint32 captureDeviceCount;
+  ma_uint32 iDevice;
+
+  if (ma_context_init(NULL, 0, NULL, &context) != MA_SUCCESS) {
+    printf("Failed to initialize context.\n");
+    return -2;
+  }
+
+  result = ma_context_get_devices(&context, &pPlaybackDeviceInfos,
+                                  &playbackDeviceCount, &pCaptureDeviceInfos,
+                                  &captureDeviceCount);
+  if (result != MA_SUCCESS) {
+    printf("Failed to retrieve device information.\n");
+    return -3;
+  }
+
+  printf("Playback Devices\n");
+  for (iDevice = 0; iDevice < playbackDeviceCount; ++iDevice) {
+    printf("    %u: %s\n", iDevice, pPlaybackDeviceInfos[iDevice].name);
+  }
+
+  printf("\n");
+
+  printf("Capture Devices\n");
+  for (iDevice = 0; iDevice < captureDeviceCount; ++iDevice) {
+    printf("    %u: %s\n", iDevice, pCaptureDeviceInfos[iDevice].name);
+  }
+
+  ma_context_uninit(&context);
+
+  return 0;
+}