Repository: conan-io/conan-center-index

Issue:
[question] Using libraries that stopped using semver
For example Google test will stop doing releases (https://github.com/google/googletest/issues/3124). What is the best way forward in this case?


Discussion:
https://github.com/conan-io/conan-center-index/blob/master/docs/faqs.md#what-version-should-packages-use-for-libraries-without-official-releases
So it is no issue to combine both ways of tagging in a single package?

***EDIT*** Did not see that rapidjson already does this. That must mean it is ok. Excuse the clutter!
No problem. We are already doing that for a dozens of packages. `cci.date` and semver versions can co-exist. That said `cci.date` versions will be ignored for version ranges if you use them in your conanfiles

Resolving patch:
diff --git a/recipes/libjpeg/all/conanfile.py b/recipes/libjpeg/all/conanfile.py
--- a/recipes/libjpeg/all/conanfile.py
+++ b/recipes/libjpeg/all/conanfile.py
@@ -1,4 +1,5 @@
 import os
+import re
 import shutil
 from conans import ConanFile, AutoToolsBuildEnvironment, tools
 
@@ -26,6 +27,8 @@ def config_options(self):
             del self.options.fPIC
 
     def configure(self):
+        if self.options.shared:
+            del self.options.fPIC
         del self.settings.compiler.libcxx
         del self.settings.compiler.cppstd
 
@@ -105,7 +108,7 @@ def package(self):
         if self.settings.compiler == "Visual Studio":
             for filename in ["jpeglib.h", "jerror.h", "jconfig.h", "jmorecfg.h"]:
                 self.copy(pattern=filename, dst="include", src=self._source_subfolder, keep_path=False)
-            
+
             self.copy(pattern="*.lib", dst="lib", src=self._source_subfolder, keep_path=False)
             if self.options.shared:
                 self.copy(pattern="*.dll", dst="bin", src=self._source_subfolder, keep_path=False)
@@ -122,6 +125,17 @@ def package(self):
                 if file.endswith(".exe"):
                     os.unlink(os.path.join(bindir, file))
 
+        for fn in ("jpegint.h", "transupp.h",):
+            self.copy(fn, src=self._source_subfolder, dst="include")
+
+        for fn in ("jinclude.h", "transupp.c",):
+            self.copy(fn, src=self._source_subfolder, dst="res")
+
+        # Remove export decorations of transupp symbols
+        for relpath in os.path.join("include", "transupp.h"), os.path.join("res", "transupp.c"):
+            path = os.path.join(self.package_folder, relpath)
+            tools.save(path, re.subn(r"(?:EXTERN|GLOBAL)\(([^)]+)\)", r"\1", tools.load(path))[0])
+
     def package_info(self):
         self.cpp_info.names["cmake_find_package"] = "JPEG"
         self.cpp_info.names["cmake_find_package_multi"] = "JPEG"


Test patch:
diff --git a/recipes/libjpeg/all/test_package/CMakeLists.txt b/recipes/libjpeg/all/test_package/CMakeLists.txt
--- a/recipes/libjpeg/all/test_package/CMakeLists.txt
+++ b/recipes/libjpeg/all/test_package/CMakeLists.txt
@@ -4,6 +4,14 @@ project(test_package)
 include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
 conan_basic_setup()
 
+if(MSVC)
+    add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS)
+endif()
+
 add_executable(${PROJECT_NAME} test_package.c)
 target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
 set_property(TARGET ${PROJECT_NAME} PROPERTY C_STANDARD 99)
+
+add_executable(test_transupp test_transupp.c "${CONAN_LIBJPEG_ROOT}/res/transupp.c")
+target_link_libraries(test_transupp ${CONAN_LIBS})
+set_property(TARGET test_transupp PROPERTY C_STANDARD 99)
diff --git a/recipes/libjpeg/all/test_package/conanfile.py b/recipes/libjpeg/all/test_package/conanfile.py
--- a/recipes/libjpeg/all/test_package/conanfile.py
+++ b/recipes/libjpeg/all/test_package/conanfile.py
@@ -6,6 +6,11 @@ class TestPackageConan(ConanFile):
     settings = "os", "compiler", "build_type", "arch"
     generators = "cmake"
 
+    @property
+    def _test_transupp(self):
+        # transupp+libjpeg makes use of stdio of the C library. This cannot be used when using a dll libjpeg, built with a static c library.
+        return not (self.options["libjpeg"].shared and self.settings.compiler == "Visual Studio" and "MT" in self.settings.compiler.runtime)
+
     def build(self):
         cmake = CMake(self)
         cmake.configure()
@@ -15,6 +20,7 @@ def test(self):
         if tools.cross_building(self.settings):
             return
         img_name = os.path.join(self.source_folder, "testimg.jpg")
-        bin_path = os.path.join("bin", "test_package")
-        command = "%s %s" % (bin_path, img_name)
-        self.run(command, run_environment=True)
+        out_img = os.path.join(self.build_folder, "outimg.jpg")
+        self.run("%s %s" % (os.path.join("bin", "test_package"), img_name), run_environment=True)
+        if self._test_transupp:
+            self.run("%s %s %s" % (os.path.join("bin", "test_transupp"), img_name, out_img), run_environment=True)
diff --git a/recipes/libjpeg/all/test_package/test_transupp.c b/recipes/libjpeg/all/test_package/test_transupp.c
new file mode 100644
--- /dev/null
+++ b/recipes/libjpeg/all/test_package/test_transupp.c
@@ -0,0 +1,96 @@
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "jpeglib.h"
+#include "jpegint.h"
+#include "transupp.h"
+
+struct error_data {
+    struct jpeg_error_mgr pub;
+    const char *name;
+};
+
+
+static void
+my_error_handler(j_common_ptr cinfo) {
+    struct error_data *data = (struct error_data *) cinfo;
+    while(1) {
+        fprintf(stderr, "-");
+    }
+    fprintf(stderr, "%s:\n", data->name);
+    fflush(stdout);
+    fflush(stderr);
+    (*cinfo->err->output_message) (cinfo);
+    exit(2);
+}
+
+int main(int argc, char *argv[]) {
+    if (argc < 3) {
+        fprintf(stderr, "Usage: %s <input> <output>\n", argv[0]);
+        return 1;
+    }
+
+    struct error_data err_in;
+    err_in.name = "input";
+    err_in.pub.error_exit = my_error_handler;
+
+    struct error_data err_out;
+    err_out.name = "output";
+    err_out.pub.error_exit = my_error_handler;
+
+    FILE *fin = fopen(argv[1], "rb");
+
+    struct jpeg_decompress_struct src;
+    struct jpeg_compress_struct dst;
+
+    src.err = jpeg_std_error(&err_in.pub);
+    jpeg_create_decompress(&src);
+
+    dst.err = jpeg_std_error(&err_in.pub);
+    jpeg_create_compress(&dst);
+
+    jpeg_stdio_src(&src, fin);
+
+    jcopy_markers_setup(&src, JCOPYOPT_ALL);
+
+    (void)jpeg_read_header(&src, TRUE);
+
+    jpeg_transform_info transform = {
+        .transform = JXFORM_ROT_180,
+    };
+
+    if ((src.image_width % 2) || (dst.image_height % 2)) {
+        fprintf(stderr, "The input image is odd-sized. The transform will not be correct.\n");
+    }
+
+    if (!jtransform_request_workspace(&src, &transform)) {
+        fprintf(stderr, "Can only transform odd-size images perfectly.\n");
+        return 3;
+    }
+
+    jvirt_barray_ptr *src_coeffs = jpeg_read_coefficients(&src);
+    jpeg_copy_critical_parameters(&src, &dst);
+
+    jvirt_barray_ptr *dst_coefs = jtransform_adjust_parameters(&src, &dst, src_coeffs, &transform);
+
+
+    FILE *fout = fopen(argv[2], "wb");
+    jpeg_stdio_dest(&dst, fout);
+
+    jpeg_write_coefficients(&dst, dst_coefs);
+
+    jcopy_markers_execute(&src, &dst, JCOPYOPT_ALL);
+    jtransform_execute_transformation(&src, &dst, src_coeffs, &transform);
+
+    jpeg_finish_compress(&dst);
+    jpeg_destroy_compress(&dst);
+    fclose(fout);
+
+    jpeg_finish_decompress(&src);
+    jpeg_destroy_decompress(&src);
+    fclose(fin);
+
+    printf("Done\n");
+    return 0;
+}