Repository: conan-io/conan-center-index

Issue:
[request] mattiasgustavsson/libs
### Package Details
  * Package Name/Version: **???/???**
  * Source code: **https://github.com/mattiasgustavsson/libs**

### Description Of The Library / Tool

Single-file public domain libraries for C/C++

Required by #1544 

I don't know how I can name this recipe !!!



Discussion:
In case of a too generic name we use the owner as a prefix, so it is going to be `mattiasgustavsson-libs`

Since the project makes no releases we use a date based versioning like `20200513`

Resolving patch:
diff --git a/recipes/mattiasgustavsson-libs/all/conanfile.py b/recipes/mattiasgustavsson-libs/all/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/mattiasgustavsson-libs/all/conanfile.py
@@ -0,0 +1,39 @@
+from conans import ConanFile, CMake, tools
+from conans.errors import ConanInvalidConfiguration
+from conans.tools import Version
+import os.path
+import glob
+
+class MattiasgustavssonLibsConan(ConanFile):
+    name = "mattiasgustavsson-libs"
+    description = "Single-file public domain libraries for C/C++"
+    homepage = "https://github.com/mattiasgustavsson/libs"
+    url = "https://github.com/conan-io/conan-center-index"
+    license = ("Unlicense", "MIT")
+    topics = ("utilities", "mattiasgustavsson", "libs")
+    no_copy_source = True
+
+    @property
+    def _source_subfolder(self):
+        return os.path.join(self.source_folder, "source_subfolder")
+
+    def source(self):
+        tools.get(**self.conan_data["sources"][self.version])
+        extracted_dir = glob.glob('libs-*/')[0]
+        os.rename(extracted_dir, self._source_subfolder)
+
+    def _extract_licenses(self):
+        header = tools.load(os.path.join(self._source_subfolder, "thread.h"))
+        mit_content = header[header.find("ALTERNATIVE A - "):header.find("ALTERNATIVE B -")]
+        tools.save("LICENSE_MIT", mit_content)
+        unlicense_content = header[header.find("ALTERNATIVE B - "):header.rfind("*/", 1)]
+        tools.save("LICENSE_UNLICENSE", unlicense_content)
+
+    def package(self):
+        self.copy(pattern="*.h", dst="include", src=self._source_subfolder)
+        self._extract_licenses()
+        self.copy("LICENSE_MIT", dst="licenses")
+        self.copy("LICENSE_UNLICENSE", dst="licenses")
+
+    def package_id(self):
+        self.info.header_only()


Test patch:
diff --git a/recipes/mattiasgustavsson-libs/all/test_package/CMakeLists.txt b/recipes/mattiasgustavsson-libs/all/test_package/CMakeLists.txt
new file mode 100644
--- /dev/null
+++ b/recipes/mattiasgustavsson-libs/all/test_package/CMakeLists.txt
@@ -0,0 +1,8 @@
+cmake_minimum_required(VERSION 2.8.11)
+project(test_package CXX)
+
+include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
+conan_basic_setup()
+
+add_executable(${PROJECT_NAME} test_package.cpp)
+target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
diff --git a/recipes/mattiasgustavsson-libs/all/test_package/conanfile.py b/recipes/mattiasgustavsson-libs/all/test_package/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/mattiasgustavsson-libs/all/test_package/conanfile.py
@@ -0,0 +1,17 @@
+from conans import ConanFile, CMake, tools
+import os
+
+
+class TestPackageConan(ConanFile):
+    settings = "os", "compiler", "build_type", "arch"
+    generators = "cmake"
+
+    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)
diff --git a/recipes/mattiasgustavsson-libs/all/test_package/test_package.cpp b/recipes/mattiasgustavsson-libs/all/test_package/test_package.cpp
new file mode 100644
--- /dev/null
+++ b/recipes/mattiasgustavsson-libs/all/test_package/test_package.cpp
@@ -0,0 +1,15 @@
+#include <iostream>
+
+#define RND_IMPLEMENTATION
+#include "rnd.h"
+
+int main()
+{
+
+    rnd_pcg_t pcg;
+    rnd_pcg_seed(&pcg, 0u); // initialize generator
+
+    std::cout << rnd_pcg_next(&pcg) << std::endl;
+
+    return 0;
+}