From 91c1f8388f3291ca2104806dfc288544ec28a4a9 Mon Sep 17 00:00:00 2001 From: Joakim Haugen Date: Mon, 2 Oct 2023 10:46:53 +0200 Subject: [PATCH 01/17] fmilibrary: add recipe for version 2.4.1 --- recipes/fmilibrary/all/conandata.yml | 29 + recipes/fmilibrary/all/conanfile.py | 141 ++ .../2.4.1-001-static-c99snprintf.patch | 25 + ...1-002-add-minizip-tools-as-functions.patch | 1265 +++++++++++++++++ .../2.4.1-003-use-expat-from-conan.patch | 43 + ...-004-use-minizip-and-zlib-from-conan.patch | 55 + ...005-ensure-conan-friendly-cmakelists.patch | 34 + .../2.4.1-006-link-external-targets.patch | 47 + .../patches/2.4.1-007-enable-testing.patch | 24 + .../all/test_package/CMakeLists.txt | 8 + .../fmilibrary/all/test_package/conanfile.py | 26 + .../all/test_package/test_package.c | 8 + recipes/fmilibrary/config.yml | 3 + 13 files changed, 1708 insertions(+) create mode 100644 recipes/fmilibrary/all/conandata.yml create mode 100644 recipes/fmilibrary/all/conanfile.py create mode 100644 recipes/fmilibrary/all/patches/2.4.1-001-static-c99snprintf.patch create mode 100644 recipes/fmilibrary/all/patches/2.4.1-002-add-minizip-tools-as-functions.patch create mode 100644 recipes/fmilibrary/all/patches/2.4.1-003-use-expat-from-conan.patch create mode 100644 recipes/fmilibrary/all/patches/2.4.1-004-use-minizip-and-zlib-from-conan.patch create mode 100644 recipes/fmilibrary/all/patches/2.4.1-005-ensure-conan-friendly-cmakelists.patch create mode 100644 recipes/fmilibrary/all/patches/2.4.1-006-link-external-targets.patch create mode 100644 recipes/fmilibrary/all/patches/2.4.1-007-enable-testing.patch create mode 100644 recipes/fmilibrary/all/test_package/CMakeLists.txt create mode 100644 recipes/fmilibrary/all/test_package/conanfile.py create mode 100644 recipes/fmilibrary/all/test_package/test_package.c create mode 100644 recipes/fmilibrary/config.yml diff --git a/recipes/fmilibrary/all/conandata.yml b/recipes/fmilibrary/all/conandata.yml new file mode 100644 index 0000000000000..016f145b8a4c9 --- /dev/null +++ b/recipes/fmilibrary/all/conandata.yml @@ -0,0 +1,29 @@ +sources: + "2.4.1": + url: + - "https://github.com/modelon-community/fmi-library/archive/refs/tags/2.4.1.tar.gz" + sha256: "8199d3e9423494b714b9c4e42f055248457a7c9162df3d4652000aa9a10b8316" +patches: + "2.4.1": + - patch_file: "patches/2.4.1-001-static-c99snprintf.patch" + patch_description: "Always build c99snprintf as static library" + patch_type: "bugfix" + patch_source: "https://github.com/open-simulation-platform/conan-fmilibrary/blob/master/build-static-c99snprintf.patch" + - patch_file: "patches/2.4.1-002-add-minizip-tools-as-functions.patch" + patch_description: "Add minizip and miniunz as functions instead of executables" + patch_type: "conan" + - patch_file: "patches/2.4.1-003-use-expat-from-conan.patch" + patch_description: "Use expat from conan instead of internal" + patch_type: "conan" + - patch_file: "patches/2.4.1-004-use-minizip-and-zlib-from-conan.patch" + patch_description: "Use minizip (and zlib) from conan instead of internal" + patch_type: "conan" + - patch_file: "patches/2.4.1-005-ensure-conan-friendly-cmakelists.patch" + patch_description: "Do minor changes to CMakeLists for conan friendliness" + patch_type: "conan" + - patch_file: "patches/2.4.1-006-link-external-targets.patch" + patch_description: "Link external targets no longer merged in fmilib" + patch_type: "conan" + - patch_file: "patches/2.4.1-007-enable-testing.patch" + patch_description: "Ensure that tests can be run with cmake" + patch_type: "conan" diff --git a/recipes/fmilibrary/all/conanfile.py b/recipes/fmilibrary/all/conanfile.py new file mode 100644 index 0000000000000..0a0f0dfa6c884 --- /dev/null +++ b/recipes/fmilibrary/all/conanfile.py @@ -0,0 +1,141 @@ +from os import path +import posixpath +from conan import ConanFile +from conan.errors import ConanInvalidConfiguration +from conan.tools.build import check_min_cppstd +from conan.tools.microsoft import is_msvc_static_runtime, is_msvc +from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy, rmdir +from conan.tools.scm import Version +from conan.tools.env import Environment +from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout + +required_conan_version = ">=1.53.0" + + +class PackageConan(ConanFile): + name = "fmilibrary" + description = "C library for importing FMUs" + license = "BSD-3-Clause" + url = "https://github.com/conan-io/conan-center-index" + homepage = "https://github.com/modelon-community/fmi-library" + topics = ("fmi", "fmi-standard", "fmu") + package_type = "library" + settings = "os", "arch", "compiler", "build_type" + options = { + "shared": [True, False], + "fPIC": [True, False], + "with_fmus": [True, False] + } + default_options = { + "shared": False, + "fPIC": True, + "with_fmus": True + } + + def export_sources(self): + export_conandata_patches(self) + + 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") + + self.options["expat"].shared = self.options.shared + self.options["minizip"].shared = self.options.shared + self.options["zlib"].shared = self.options.shared + + def layout(self): + cmake_layout(self, src_folder="src") + + def requirements(self): + self.requires("fmi1/1.0.1") + self.requires("fmi2/2.0.4") + if self.version >= Version("3.0a2"): + self.requires("fmi3/3.0.1") + self.requires("expat/2.4.9") + self.requires("minizip/1.2.13") + # c99_snprintf -> should be externalised + + def build_requirements(self): + if self.version >= Version("3.0a2") and self.options.with_fmus: + self.test_requires("catch2/2.13.10") + + def validate(self): + if self.version >= Version("3.0a2") and self.options.with_fmus: + if self.settings.compiler.get_safe("cppstd"): + check_min_cppstd(self, 11) + + def source(self): + get(self, **self.conan_data["sources"][self.version], strip_root=True) + + def generate(self): + + copy(self, "fmiModel*.h", self.dependencies["fmi1"].cpp_info.components["modex"].includedirs[0], + path.join(self.build_folder, "fmis", "FMI1")) + copy(self, "fmiPlatformTypes.h", self.dependencies["fmi1"].cpp_info.components["cosim"].includedirs[0], + path.join(self.build_folder, "fmis", "FMI1")) + copy(self, "fmiFunctions.h", self.dependencies["fmi1"].cpp_info.components["cosim"].includedirs[0], + path.join(self.build_folder, "fmis", "FMI1")) + copy(self, "*.h", self.dependencies["fmi2"].cpp_info.includedirs[0], + path.join(self.build_folder, "fmis", "FMI2")) + + tc = CMakeToolchain(self) + tc.variables["FMILIB_BUILD_STATIC_LIB"] = not self.options.shared + tc.variables["FMILIB_BUILD_SHARED_LIB"] = self.options.shared + tc.variables["FMILIB_BUILD_TESTS"] = self.options.with_fmus + tc.variables["FMILIB_FMI_STANDARD_HEADERS"] = posixpath.join(self.build_folder, "fmis").replace("\\", "/") + tc.variables["FMILIB_GENERATE_DOXYGEN_DOC"] = False + + if is_msvc(self): + tc.variables["FMILIB_BUILD_WITH_STATIC_RTLIB"] = is_msvc_static_runtime(self) + + tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0026"] = "OLD" + tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0045"] = "OLD" + tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0046"] = "OLD" + + tc.generate() + tc = CMakeDeps(self) + tc.generate() + + def build(self): + apply_conandata_patches(self) + cmake = CMake(self) + cmake.configure() + cmake.build() + + if not self.conf.get("tools.build:skip_test", default=True): + env = Environment() + env.define("CTEST_OUTPUT_ON_FAILURE", "ON") + with env.vars(self).apply(): + cmake.test() + + def package(self): + copy(self, pattern="LICENSE.md", dst=path.join(self.package_folder, "licenses"), + src=self.source_folder) + copy(self, pattern="FMILIB_Acknowledgements.txt", + dst=path.join(self.package_folder, "licenses"), + src=self.source_folder) + copy(self, pattern="*.fmu", dst=path.join(self.package_folder, "res", "fmus"), + src=path.join(self.build_folder, "Testing"), keep_path=False) + + cmake = CMake(self) + cmake.install() + + rmdir(self, path.join(self.package_folder, "doc")) + + def package_info(self): + if self.options.shared: + self.cpp_info.libs = ["fmilib_shared"] + else: + self.cpp_info.libs = ["fmilib"] + + if self.settings.os in ["Linux", "FreeBSD"]: + self.cpp_info.system_libs.append("dl") + + if self.settings.os in ["Windows"]: + self.cpp_info.system_libs.append("Shlwapi") + + self.cpp_info.resdirs = ["res"] diff --git a/recipes/fmilibrary/all/patches/2.4.1-001-static-c99snprintf.patch b/recipes/fmilibrary/all/patches/2.4.1-001-static-c99snprintf.patch new file mode 100644 index 0000000000000..e9a53020cb3cc --- /dev/null +++ b/recipes/fmilibrary/all/patches/2.4.1-001-static-c99snprintf.patch @@ -0,0 +1,25 @@ +From e4ad54090e455289ac23a45867b17c8dca88e704 Mon Sep 17 00:00:00 2001 +From: Joakim Haugen +Date: Tue, 19 Sep 2023 08:59:53 +0200 +Subject: [PATCH] Link c99snprintf statically + +--- + ThirdParty/c99_snprintf/CMakeLists.txt | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/ThirdParty/c99_snprintf/CMakeLists.txt b/ThirdParty/c99_snprintf/CMakeLists.txt +index 6f513b4..6c9b676 100644 +--- a/ThirdParty/c99_snprintf/CMakeLists.txt ++++ b/ThirdParty/c99_snprintf/CMakeLists.txt +@@ -119,7 +119,7 @@ add_definitions(${DEFINES}) + + file(WRITE ${CMAKE_BINARY_DIR}/c99snprintf_defs "${DEFINES}") + +-add_library(c99snprintf c99-snprintf_1.1/snprintf.c) ++add_library(c99snprintf STATIC c99-snprintf_1.1/snprintf.c) + + if(CYGWIN) + message("not tested") +-- +2.30.2 + diff --git a/recipes/fmilibrary/all/patches/2.4.1-002-add-minizip-tools-as-functions.patch b/recipes/fmilibrary/all/patches/2.4.1-002-add-minizip-tools-as-functions.patch new file mode 100644 index 0000000000000..3177371f59953 --- /dev/null +++ b/recipes/fmilibrary/all/patches/2.4.1-002-add-minizip-tools-as-functions.patch @@ -0,0 +1,1265 @@ +From ebe6fc7a2d4ef78b2e421c8fa23a30d28079319b Mon Sep 17 00:00:00 2001 +From: Joakim Haugen +Date: Wed, 24 May 2023 15:27:49 +0200 +Subject: [PATCH] Add minizip tools as functions + +--- + src/ZIP/include/miniunz.h | 11 + + src/ZIP/include/minizip.h | 12 + + src/ZIP/src/miniunz.c | 670 ++++++++++++++++++++++++++++++++++++++ + src/ZIP/src/minizip.c | 529 ++++++++++++++++++++++++++++++ + 4 files changed, 1222 insertions(+) + create mode 100644 src/ZIP/include/miniunz.h + create mode 100644 src/ZIP/include/minizip.h + create mode 100644 src/ZIP/src/miniunz.c + create mode 100644 src/ZIP/src/minizip.c + +diff --git a/src/ZIP/include/miniunz.h b/src/ZIP/include/miniunz.h +new file mode 100644 +index 0000000..d958b3d +--- /dev/null ++++ b/src/ZIP/include/miniunz.h +@@ -0,0 +1,11 @@ ++#ifndef MINIUNZ_H ++#define MINIUNZ_H ++#ifdef __cplusplus ++extern "C" { ++#endif ++ ++ int miniunz(int argc , char *argv[]); /* Renamed the main function */ ++#ifdef __cplusplus ++} ++#endif ++#endif /* End of header file MINIUNZ_H */ +diff --git a/src/ZIP/include/minizip.h b/src/ZIP/include/minizip.h +new file mode 100644 +index 0000000..767dbde +--- /dev/null ++++ b/src/ZIP/include/minizip.h +@@ -0,0 +1,12 @@ ++#ifndef MINIZIP_H ++#define MINIZIP_H ++#ifdef __cplusplus ++extern "C" { ++#endif ++ ++ int minizip(int argc , char *argv[]); /* Renamed the main function */ ++ ++#ifdef __cplusplus ++} ++#endif ++#endif /* End of header file MINIZIP_H */ +diff --git a/src/ZIP/src/miniunz.c b/src/ZIP/src/miniunz.c +new file mode 100644 +index 0000000..7a73f6a +--- /dev/null ++++ b/src/ZIP/src/miniunz.c +@@ -0,0 +1,670 @@ ++/* ++ miniunz.c ++ Version 1.1, February 14h, 2010 ++ sample part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) ++ ++ Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) ++ ++ Modifications of Unzip for Zip64 ++ Copyright (C) 2007-2008 Even Rouault ++ ++ Modifications for Zip64 support on both zip and unzip ++ Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) ++*/ ++ ++#if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__)) ++ #ifndef __USE_FILE_OFFSET64 ++ #define __USE_FILE_OFFSET64 ++ #endif ++ #ifndef __USE_LARGEFILE64 ++ #define __USE_LARGEFILE64 ++ #endif ++ #ifndef _LARGEFILE64_SOURCE ++ #define _LARGEFILE64_SOURCE ++ #endif ++ #ifndef _FILE_OFFSET_BIT ++ #define _FILE_OFFSET_BIT 64 ++ #endif ++#endif ++ ++#ifdef __APPLE__ ++// In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions ++#define FOPEN_FUNC(filename, mode) fopen(filename, mode) ++#define FTELLO_FUNC(stream) ftello(stream) ++#define FSEEKO_FUNC(stream, offset, origin) fseeko(stream, offset, origin) ++#else ++#define FOPEN_FUNC(filename, mode) fopen64(filename, mode) ++#define FTELLO_FUNC(stream) ftello64(stream) ++#define FSEEKO_FUNC(stream, offset, origin) fseeko64(stream, offset, origin) ++#endif ++ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#ifdef _WIN32 ++# include ++# include ++#else ++# include ++# include ++#include ++#include ++#endif ++ ++ ++#include "unzip.h" ++ ++#define CASESENSITIVITY (0) ++#define WRITEBUFFERSIZE (8192) ++#define MAXFILENAME (256) ++ ++#ifdef _WIN32 ++#define USEWIN32IOAPI ++#include "iowin32.h" ++#endif ++ ++/* MODIFICATION Replace all stdout prints with this function for better control */ ++static int minizip_printf( const char * format, ... ) ++{ ++ return 1; ++} ++ ++/* ++ mini unzip, demo of unzip package ++ ++ usage : ++ Usage : miniunz [-exvlo] file.zip [file_to_extract] [-d extractdir] ++ ++ list the file in the zipfile, and print the content of FILE_ID.ZIP or README.TXT ++ if it exists ++*/ ++ ++ ++/* change_file_date : change the date/time of a file ++ filename : the filename of the file where date/time must be modified ++ dosdate : the new date at the MSDos format (4 bytes) ++ tmu_date : the SAME new date at the tm_unz format */ ++void change_file_date(filename,dosdate,tmu_date) ++ const char *filename; ++ uLong dosdate; ++ tm_unz tmu_date; ++{ ++#ifdef _WIN32 ++ HANDLE hFile; ++ FILETIME ftm,ftLocal,ftCreate,ftLastAcc,ftLastWrite; ++ ++ hFile = CreateFileA(filename,GENERIC_READ | GENERIC_WRITE, ++ 0,NULL,OPEN_EXISTING,0,NULL); ++ GetFileTime(hFile,&ftCreate,&ftLastAcc,&ftLastWrite); ++ DosDateTimeToFileTime((WORD)(dosdate>>16),(WORD)dosdate,&ftLocal); ++ LocalFileTimeToFileTime(&ftLocal,&ftm); ++ SetFileTime(hFile,&ftm,&ftLastAcc,&ftm); ++ CloseHandle(hFile); ++#else ++#if defined(__unix) || defined(__APPLE__) ++ (void)dosdate; ++ struct utimbuf ut; ++ struct tm newdate; ++ newdate.tm_sec = tmu_date.tm_sec; ++ newdate.tm_min=tmu_date.tm_min; ++ newdate.tm_hour=tmu_date.tm_hour; ++ newdate.tm_mday=tmu_date.tm_mday; ++ newdate.tm_mon=tmu_date.tm_mon; ++ if (tmu_date.tm_year > 1900) ++ newdate.tm_year=tmu_date.tm_year - 1900; ++ else ++ newdate.tm_year=tmu_date.tm_year ; ++ newdate.tm_isdst=-1; ++ ++ ut.actime=ut.modtime=mktime(&newdate); ++ utime(filename,&ut); ++#endif ++#endif ++} ++ ++ ++/* mymkdir and change_file_date are not 100 % portable ++ As I don't know well Unix, I wait feedback for the unix portion */ ++ ++int mymkdir(dirname) ++ const char* dirname; ++{ ++ int ret=0; ++#ifdef _WIN32 ++ ret = _mkdir(dirname); ++#elif __unix ++ ret = mkdir (dirname,0775); ++#elif __APPLE__ ++ ret = mkdir (dirname,0775); ++#else ++#error Unknown platform ++#endif ++ return ret; ++} ++ ++int makedir (newdir) ++ char *newdir; ++{ ++ char *buffer ; ++ char *p; ++ size_t len = strlen(newdir); ++ ++ if (len == 0) ++ return 0; ++ ++ buffer = (char*)malloc(len+1); ++ if (buffer==NULL) ++ { ++ minizip_printf("Error allocating memory\n"); ++ return UNZ_INTERNALERROR; ++ } ++ strcpy(buffer,newdir); ++ ++ if (buffer[len-1] == '/') { ++ buffer[len-1] = '\0'; ++ } ++ if (mymkdir(buffer) == 0) ++ { ++ free(buffer); ++ return 1; ++ } ++ ++ p = buffer+1; ++ while (1) ++ { ++ char hold; ++ ++ while(*p && *p != '\\' && *p != '/') ++ p++; ++ hold = *p; ++ *p = 0; ++ if ((mymkdir(buffer) == -1) && (errno == ENOENT)) ++ { ++ minizip_printf("couldn't create directory %s\n",buffer); ++ free(buffer); ++ return 0; ++ } ++ if (hold == 0) ++ break; ++ *p++ = hold; ++ } ++ free(buffer); ++ return 1; ++} ++ ++static void do_banner() ++{ ++ /*printf("MiniUnz 1.01b, demo of zLib + Unz package written by Gilles Vollant\n"); ++ printf("more info at http://www.winimage.com/zLibDll/unzip.html\n\n");*/ ++} ++ ++static void do_help() ++{ ++ printf("Usage : miniunz [-e] [-x] [-v] [-l] [-o] [-p password] file.zip [file_to_extr.] [-d extractdir]\n\n" \ ++ " -e Extract without pathname (junk paths)\n" \ ++ " -x Extract with pathname\n" \ ++ " -v list files\n" \ ++ " -l list files\n" \ ++ " -d directory to extract into\n" \ ++ " -o overwrite files without prompting\n" \ ++ " -p extract crypted file using password\n\n"); ++} ++ ++static void Display64BitsSize(ZPOS64_T n, int size_char) ++{ ++ /* to avoid compatibility problem , we do here the conversion */ ++ char number[21]; ++ int offset=19; ++ int pos_string = 19; ++ number[20]=0; ++ for (;;) { ++ number[offset]=(char)((n%10)+'0'); ++ if (number[offset] != '0') ++ pos_string=offset; ++ n/=10; ++ if (offset==0) ++ break; ++ offset--; ++ } ++ { ++ int size_display_string = 19-pos_string; ++ while (size_char > size_display_string) ++ { ++ size_char--; ++ minizip_printf(" "); ++ } ++ } ++ ++ minizip_printf("%s",&number[pos_string]); ++} ++ ++static int do_list(uf) ++ unzFile uf; ++{ ++ uLong i; ++ unz_global_info64 gi; ++ int err; ++ ++ err = unzGetGlobalInfo64(uf,&gi); ++ if (err!=UNZ_OK) ++ minizip_printf("error %d with zipfile in unzGetGlobalInfo \n",err); ++ minizip_printf(" Length Method Size Ratio Date Time CRC-32 Name\n"); ++ minizip_printf(" ------ ------ ---- ----- ---- ---- ------ ----\n"); ++ for (i=0;i0) ++ ratio = (uLong)((file_info.compressed_size*100)/file_info.uncompressed_size); ++ ++ /* display a '*' if the file is crypted */ ++ if ((file_info.flag & 1) != 0) ++ charCrypt='*'; ++ ++ if (file_info.compression_method==0) ++ string_method="Stored"; ++ else ++ if (file_info.compression_method==Z_DEFLATED) ++ { ++ uInt iLevel=(uInt)((file_info.flag & 0x6)/2); ++ if (iLevel==0) ++ string_method="Defl:N"; ++ else if (iLevel==1) ++ string_method="Defl:X"; ++ else if ((iLevel==2) || (iLevel==3)) ++ string_method="Defl:F"; /* 2:fast , 3 : extra fast*/ ++ } ++ else ++ if (file_info.compression_method==Z_BZIP2ED) ++ { ++ string_method="BZip2 "; ++ } ++ else ++ string_method="Unkn. "; ++ ++ Display64BitsSize(file_info.uncompressed_size,7); ++ minizip_printf(" %6s%c",string_method,charCrypt); ++ Display64BitsSize(file_info.compressed_size,7); ++ minizip_printf(" %3lu%% %2.2lu-%2.2lu-%2.2lu %2.2lu:%2.2lu %8.8lx %s\n", ++ ratio, ++ (uLong)file_info.tmu_date.tm_mon + 1, ++ (uLong)file_info.tmu_date.tm_mday, ++ (uLong)file_info.tmu_date.tm_year % 100, ++ (uLong)file_info.tmu_date.tm_hour,(uLong)file_info.tmu_date.tm_min, ++ (uLong)file_info.crc,filename_inzip); ++ if ((i+1)='a') && (rep<='z')) ++ rep -= 0x20; ++ } ++ while ((rep!='Y') && (rep!='N') && (rep!='A')); ++ } ++ ++ if (rep == 'N') ++ skip = 1; ++ ++ if (rep == 'A') ++ *popt_overwrite=1; ++ } ++ ++ if ((skip==0) && (err==UNZ_OK)) ++ { ++ fout=FOPEN_FUNC(write_filename,"wb"); ++ /* some zipfile don't contain directory alone before file */ ++ if ((fout==NULL) && ((*popt_extract_without_path)==0) && ++ (filename_withoutpath!=(char*)filename_inzip)) ++ { ++ char c=*(filename_withoutpath-1); ++ *(filename_withoutpath-1)='\0'; ++ makedir(write_filename); ++ *(filename_withoutpath-1)=c; ++ fout=FOPEN_FUNC(write_filename,"wb"); ++ } ++ ++ if (fout==NULL) ++ { ++ minizip_printf("error opening %s\n",write_filename); ++ } ++ } ++ ++ if (fout!=NULL) ++ { ++ minizip_printf(" extracting: %s\n",write_filename); ++ ++ do ++ { ++ err = unzReadCurrentFile(uf,buf,size_buf); ++ if (err<0) ++ { ++ minizip_printf("error %d with zipfile in unzReadCurrentFile\n",err); ++ break; ++ } ++ if (err>0) ++ if (fwrite(buf,(unsigned)err,1,fout)!=1) ++ { ++ minizip_printf("error in writing extracted file\n"); ++ err=UNZ_ERRNO; ++ break; ++ } ++ } ++ while (err>0); ++ if (fout) ++ fclose(fout); ++ ++ if (err==0) ++ change_file_date(write_filename,file_info.dosDate, ++ file_info.tmu_date); ++ } ++ ++ if (err==UNZ_OK) ++ { ++ err = unzCloseCurrentFile (uf); ++ if (err!=UNZ_OK) ++ { ++ minizip_printf("error %d with zipfile in unzCloseCurrentFile\n",err); ++ } ++ } ++ else ++ unzCloseCurrentFile(uf); /* don't lose the error */ ++ } ++ ++ free(buf); ++ return err; ++} ++ ++ ++int do_extract(uf,opt_extract_without_path,opt_overwrite,password) ++ unzFile uf; ++ int opt_extract_without_path; ++ int opt_overwrite; ++ const char* password; ++{ ++ uLong i; ++ unz_global_info64 gi; ++ int err; ++ ++ err = unzGetGlobalInfo64(uf,&gi); ++ if (err!=UNZ_OK) ++ minizip_printf("error %d with zipfile in unzGetGlobalInfo \n",err); ++ ++ for (i=0;i ++#include ++#include ++#include ++#include ++#include ++ ++#ifdef _WIN32 ++# include ++# include ++#else ++# include ++# include ++# include ++# include ++#endif ++ ++#include "zip.h" ++ ++#ifdef _WIN32 ++ #define USEWIN32IOAPI ++ #include "iowin32.h" ++#endif ++ ++ ++ ++#define WRITEBUFFERSIZE (16384) ++#define MAXFILENAME (256) ++ ++/* MODIFICATION Replace all stdout prints with this function for better control */ ++static int minizip_printf( const char * format, ... ) ++{ ++ return 1; ++} ++ ++#ifdef _WIN32 ++int filetime(f, tmzip, dt) ++ const char *f; /* name of file to get info on */ ++ tm_zip *tmzip; /* return value: access, modific. and creation times */ ++ uLong *dt; /* dostime */ ++{ ++ int ret = 0; ++ { ++ FILETIME ftLocal; ++ HANDLE hFind; ++ WIN32_FIND_DATAA ff32; ++ ++ hFind = FindFirstFileA(f,&ff32); ++ if (hFind != INVALID_HANDLE_VALUE) ++ { ++ FileTimeToLocalFileTime(&(ff32.ftLastWriteTime),&ftLocal); ++ FileTimeToDosDateTime(&ftLocal,((LPWORD)dt)+1,((LPWORD)dt)+0); ++ FindClose(hFind); ++ ret = 1; ++ } ++ } ++ return ret; ++} ++#else ++#if defined(__unix) || defined(__APPLE__) ++int filetime(f, tmzip, dt) ++ const char *f; /* name of file to get info on */ ++ tm_zip *tmzip; /* return value: access, modific. and creation times */ ++ uLong *dt; /* dostime */ ++{ ++ (void)dt; ++ int ret=0; ++ struct stat s; /* results of stat() */ ++ struct tm* filedate; ++ time_t tm_t=0; ++ ++ if (strcmp(f,"-")!=0) ++ { ++ char name[MAXFILENAME+1]; ++ size_t len = strlen(f); ++ if (len > MAXFILENAME) ++ len = MAXFILENAME; ++ ++ strncpy(name, f,MAXFILENAME-1); ++ /* strncpy doesnt append the trailing NULL, of the string is too long. */ ++ name[ MAXFILENAME ] = '\0'; ++ ++ if (name[len - 1] == '/') ++ name[len - 1] = '\0'; ++ /* not all systems allow stat'ing a file with / appended */ ++ if (stat(name,&s)==0) ++ { ++ tm_t = s.st_mtime; ++ ret = 1; ++ } ++ } ++ filedate = localtime(&tm_t); ++ ++ tmzip->tm_sec = filedate->tm_sec; ++ tmzip->tm_min = filedate->tm_min; ++ tmzip->tm_hour = filedate->tm_hour; ++ tmzip->tm_mday = filedate->tm_mday; ++ tmzip->tm_mon = filedate->tm_mon ; ++ tmzip->tm_year = filedate->tm_year; ++ ++ return ret; ++} ++#else ++uLong filetime(f, tmzip, dt) ++ const char *f; /* name of file to get info on */ ++ tm_zip *tmzip; /* return value: access, modific. and creation times */ ++ uLong *dt; /* dostime */ ++{ ++ return 0; ++} ++#endif ++#endif ++ ++ ++ ++ ++static int check_exist_file(filename) ++ const char* filename; ++{ ++ FILE* ftestexist; ++ int ret = 1; ++ ftestexist = FOPEN_FUNC(filename,"rb"); ++ if (ftestexist==NULL) ++ ret = 0; ++ else ++ fclose(ftestexist); ++ return ret; ++} ++ ++static void do_banner() ++{ ++ /* ++ minizip_printf("MiniZip 1.1, demo of zLib + MiniZip64 package, written by Gilles Vollant\n"); ++ minizip_printf("more info on MiniZip at http://www.winimage.com/zLibDll/minizip.html\n\n"); ++ */ ++} ++ ++static void do_help() ++{ ++ minizip_printf("Usage : minizip [-o] [-a] [-0 to -9] [-p password] [-j] file.zip [files_to_add]\n\n" \ ++ " -o Overwrite existing file.zip\n" \ ++ " -a Append to existing file.zip\n" \ ++ " -0 Store only\n" \ ++ " -1 Compress faster\n" \ ++ " -9 Compress better\n\n" \ ++ " -j exclude path. store only the file name.\n\n"); ++} ++ ++/* calculate the CRC32 of a file, ++ because to encrypt a file, we need known the CRC32 of the file before */ ++int getFileCrc(const char* filenameinzip,void*buf,unsigned long size_buf,unsigned long* result_crc) ++{ ++ unsigned long calculate_crc=0; ++ int err=ZIP_OK; ++ FILE * fin = FOPEN_FUNC(filenameinzip,"rb"); ++ ++ unsigned long size_read = 0; ++ /* unsigned long total_read = 0; */ ++ if (fin==NULL) ++ { ++ err = ZIP_ERRNO; ++ } ++ ++ if (err == ZIP_OK) ++ do ++ { ++ err = ZIP_OK; ++ size_read = fread(buf,1,size_buf,fin); ++ if (size_read < size_buf) ++ if (feof(fin)==0) ++ { ++ minizip_printf("error in reading %s\n",filenameinzip); ++ err = ZIP_ERRNO; ++ } ++ ++ if (size_read>0) ++ calculate_crc = crc32_z(calculate_crc,buf,size_read); ++ /* total_read += size_read; */ ++ ++ } while ((err == ZIP_OK) && (size_read>0)); ++ ++ if (fin) ++ fclose(fin); ++ ++ *result_crc=calculate_crc; ++ minizip_printf("file %s crc %lx\n", filenameinzip, calculate_crc); ++ return err; ++} ++ ++int isLargeFile(const char* filename) ++{ ++ int largeFile = 0; ++ ZPOS64_T pos = 0; ++ FILE* pFile = FOPEN_FUNC(filename, "rb"); ++ ++ if(pFile != NULL) ++ { ++ FSEEKO_FUNC(pFile, 0, SEEK_END); ++ pos = (ZPOS64_T)FTELLO_FUNC(pFile); ++ ++ minizip_printf("File : %s is %lld bytes\n", filename, pos); ++ ++ if(pos >= 0xffffffff) ++ largeFile = 1; ++ ++ fclose(pFile); ++ } ++ ++ return largeFile; ++} ++ ++int minizip(argc,argv) ++ int argc; ++ char *argv[]; ++{ ++ int i; ++ int opt_overwrite=0; ++ int opt_compress_level=Z_DEFAULT_COMPRESSION; ++ int opt_exclude_path=0; ++ int zipfilenamearg = 0; ++ char filename_try[MAXFILENAME+16]; ++ int zipok; ++ int err=0; ++ size_t size_buf=0; ++ void* buf=NULL; ++ const char* password=NULL; ++ ++ ++ do_banner(); ++ if (argc==1) ++ { ++ do_help(); ++ return 0; ++ } ++ else ++ { ++ for (i=1;i='0') && (c<='9')) ++ opt_compress_level = c-'0'; ++ if ((c=='j') || (c=='J')) ++ opt_exclude_path = 1; ++ ++ if (((c=='p') || (c=='P')) && (i+1='a') && (rep<='z')) ++ rep -= 0x20; ++ } ++ while ((rep!='Y') && (rep!='N') && (rep!='A')); ++ if (rep=='N') ++ zipok = 0; ++ if (rep=='A') ++ opt_overwrite = 2; ++ } ++ } ++ ++ if (zipok==1) ++ { ++ zipFile zf; ++ int errclose; ++# ifdef USEWIN32IOAPI ++ zlib_filefunc64_def ffunc; ++ fill_win32_filefunc64A(&ffunc); ++ zf = zipOpen2_64(filename_try,(opt_overwrite==2) ? 2 : 0,NULL,&ffunc); ++# else ++ zf = zipOpen64(filename_try,(opt_overwrite==2) ? 2 : 0); ++# endif ++ ++ if (zf == NULL) ++ { ++ minizip_printf("error opening %s\n",filename_try); ++ err= ZIP_ERRNO; ++ } ++ else ++ minizip_printf("creating %s\n",filename_try); ++ ++ for (i=zipfilenamearg+1;(i='0') || (argv[i][1]<='9'))) && ++ (strlen(argv[i]) == 2))) ++ { ++ FILE * fin; ++ size_t size_read; ++ const char* filenameinzip = argv[i]; ++ const char *savefilenameinzip; ++ zip_fileinfo zi; ++ unsigned long crcFile=0; ++ int zip64 = 0; ++ ++ zi.tmz_date.tm_sec = zi.tmz_date.tm_min = zi.tmz_date.tm_hour = ++ zi.tmz_date.tm_mday = zi.tmz_date.tm_mon = zi.tmz_date.tm_year = 0; ++ zi.dosDate = 0; ++ zi.internal_fa = 0; ++ zi.external_fa = 0; ++ filetime(filenameinzip,&zi.tmz_date,&zi.dosDate); ++ ++/* ++ err = zipOpenNewFileInZip(zf,filenameinzip,&zi, ++ NULL,0,NULL,0,NULL / * comment * /, ++ (opt_compress_level != 0) ? Z_DEFLATED : 0, ++ opt_compress_level); ++*/ ++ if ((password != NULL) && (err==ZIP_OK)) ++ err = getFileCrc(filenameinzip,buf,size_buf,&crcFile); ++ ++ zip64 = isLargeFile(filenameinzip); ++ ++ /* The path name saved, should not include a leading slash. */ ++ /*if it did, windows/xp and dynazip couldn't read the zip file. */ ++ savefilenameinzip = filenameinzip; ++ while( savefilenameinzip[0] == '\\' || savefilenameinzip[0] == '/' ) ++ { ++ savefilenameinzip++; ++ } ++ ++ /*should the zip file contain any path at all?*/ ++ if( opt_exclude_path ) ++ { ++ const char *tmpptr; ++ const char *lastslash = 0; ++ for( tmpptr = savefilenameinzip; *tmpptr; tmpptr++) ++ { ++ if( *tmpptr == '\\' || *tmpptr == '/') ++ { ++ lastslash = tmpptr; ++ } ++ } ++ if( lastslash != NULL ) ++ { ++ savefilenameinzip = lastslash+1; /* base filename follows last slash. */ ++ } ++ } ++ ++ /**/ ++ err = zipOpenNewFileInZip3_64(zf,savefilenameinzip,&zi, ++ NULL,0,NULL,0,NULL /* comment*/, ++ (opt_compress_level != 0) ? Z_DEFLATED : 0, ++ opt_compress_level,0, ++ /* -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, */ ++ -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, ++ password,crcFile, zip64); ++ ++ if (err != ZIP_OK) ++ minizip_printf("error in opening %s in zipfile\n",filenameinzip); ++ else ++ { ++ fin = FOPEN_FUNC(filenameinzip,"rb"); ++ if (fin==NULL) ++ { ++ err=ZIP_ERRNO; ++ minizip_printf("error in opening %s for reading\n",filenameinzip); ++ } ++ } ++ ++ if (err == ZIP_OK) ++ do ++ { ++ err = ZIP_OK; ++ size_read = fread(buf,1,size_buf,fin); ++ if (size_read < size_buf) ++ if (feof(fin)==0) ++ { ++ minizip_printf("error in reading %s\n",filenameinzip); ++ err = ZIP_ERRNO; ++ } ++ ++ if (size_read>0) ++ { ++ err = zipWriteInFileInZip (zf,buf,(unsigned)size_read); ++ if (err<0) ++ { ++ minizip_printf("error in writing %s in the zipfile\n", ++ filenameinzip); ++ } ++ ++ } ++ } while ((err == ZIP_OK) && (size_read>0)); ++ ++ if (fin) ++ fclose(fin); ++ ++ if (err<0) ++ err=ZIP_ERRNO; ++ else ++ { ++ err = zipCloseFileInZip(zf); ++ if (err!=ZIP_OK) ++ minizip_printf("error in closing %s in the zipfile\n", ++ filenameinzip); ++ } ++ } ++ } ++ errclose = zipClose(zf,NULL); ++ if (errclose != ZIP_OK) ++ minizip_printf("error in closing %s\n",filename_try); ++ } ++ else ++ { ++ do_help(); ++ } ++ ++ free(buf); ++ return 0; ++} +-- +2.30.2 + diff --git a/recipes/fmilibrary/all/patches/2.4.1-003-use-expat-from-conan.patch b/recipes/fmilibrary/all/patches/2.4.1-003-use-expat-from-conan.patch new file mode 100644 index 0000000000000..0275aa7884759 --- /dev/null +++ b/recipes/fmilibrary/all/patches/2.4.1-003-use-expat-from-conan.patch @@ -0,0 +1,43 @@ +From b7d707b76a5c447d30ef67bd4eb9f3a9e9faffd7 Mon Sep 17 00:00:00 2001 +From: Joakim Haugen +Date: Wed, 24 May 2023 16:23:04 +0200 +Subject: [PATCH 1/3] Use expat from conan + +--- + Config.cmake/fmixml.cmake | 7 +++++-- + 1 file changed, 5 insertions(+), 2 deletions(-) + +diff --git a/Config.cmake/fmixml.cmake b/Config.cmake/fmixml.cmake +index ddd3c1f..c60322c 100644 +--- a/Config.cmake/fmixml.cmake ++++ b/Config.cmake/fmixml.cmake +@@ -137,6 +137,7 @@ set(FMIXMLSOURCE + src/FMI2/fmi2_xml_variable.c + ) + ++if(FALSE) + include(ExternalProject) + + # The *_POSTFIX variables are set because it makes it easier to determine the name of +@@ -213,7 +214,9 @@ endif() + + set(EXPAT_INCLUDE_DIRS ${CMAKE_BINARY_DIR}/ExpatEx/install/include) + +-include_directories("${EXPAT_INCLUDE_DIRS}" "${FMILIB_THIRDPARTYLIBS}/FMI/" "${FMIXMLGENDIR}/FMI1" "${FMIXMLGENDIR}/FMI2") ++endif() ++find_package(expat CONFIG REQUIRED) ++include_directories("${FMILIB_THIRDPARTYLIBS}/FMI/" "${FMIXMLGENDIR}/FMI1" "${FMIXMLGENDIR}/FMI2") + + PREFIXLIST(FMIXMLSOURCE ${FMIXMLDIR}/) + PREFIXLIST(FMIXMLHEADERS ${FMIXMLDIR}/) +@@ -232,6 +235,6 @@ if(MSVC) + target_compile_definitions(fmixml PUBLIC XML_STATIC) + endif() + +-target_link_libraries(fmixml ${JMUTIL_LIBRARIES} expat) ++target_link_libraries(fmixml ${JMUTIL_LIBRARIES} expat::expat) + + endif(NOT FMIXMLDIR) +-- +2.30.2 + diff --git a/recipes/fmilibrary/all/patches/2.4.1-004-use-minizip-and-zlib-from-conan.patch b/recipes/fmilibrary/all/patches/2.4.1-004-use-minizip-and-zlib-from-conan.patch new file mode 100644 index 0000000000000..ef76b6103b52e --- /dev/null +++ b/recipes/fmilibrary/all/patches/2.4.1-004-use-minizip-and-zlib-from-conan.patch @@ -0,0 +1,55 @@ +From 3195c7ee77f40cde7231357e6f6e8cf247fc3452 Mon Sep 17 00:00:00 2001 +From: Joakim Haugen +Date: Wed, 24 May 2023 16:26:15 +0200 +Subject: [PATCH 2/3] Use minizip and zlib from conan + +--- + Config.cmake/fmizip.cmake | 16 ++++++++++------ + 1 file changed, 10 insertions(+), 6 deletions(-) + +diff --git a/Config.cmake/fmizip.cmake b/Config.cmake/fmizip.cmake +index 091fc4d..7618d51 100644 +--- a/Config.cmake/fmizip.cmake ++++ b/Config.cmake/fmizip.cmake +@@ -19,28 +19,32 @@ if(NOT FMIZIPDIR) + # set(DOXYFILE_EXTRA_SOURCES "${DOXYFILE_EXTRA_SOURCES} \"${FMIZIPDIR}/include\"") + + set(FMIZIP_LIBRARIES fmizip) +- +- add_subdirectory(Config.cmake/Minizip) +- +- include_directories("${FMIZIPDIR}/include" "${FMILIB_THIRDPARTYLIBS}/Minizip/minizip" "${FMILIB_THIRDPARTYLIBS}/FMI" "${FMILIB_THIRDPARTYLIBS}/Zlib/zlib-1.2.6" "${FMILibrary_BINARY_DIR}/zlib") ++ ++ #add_subdirectory(Config.cmake/Minizip) ++ ++ include_directories("${FMIZIPDIR}/include" "${FMILIB_THIRDPARTYLIBS}/FMI") + + set(FMIZIPSOURCE + ${FMIZIPDIR}/src/fmi_zip_unzip.c + ${FMIZIPDIR}/src/fmi_zip_zip.c ++ ${FMIZIPDIR}/src/minizip.c ++ ${FMIZIPDIR}/src/miniunz.c + ) + + set(FMIZIPHEADERS + # src/fmi_zip_unzip_impl.h + ${FMIZIPDIR}/include/FMI/fmi_zip_unzip.h + ${FMIZIPDIR}/include/FMI/fmi_zip_zip.h ++ ${FMIZIPDIR}/include/minizip.h ++ ${FMIZIPDIR}/include/miniunz.h + ) + + #include_directories("${FMILIB_THIRDPARTYLIBS}/zlib/lib/VS2005/win32") + +-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DZLIB_STATIC") ++find_package(minizip CONFIG REQUIRED) + + add_library(fmizip ${FMILIBKIND} ${FMIZIPSOURCE} ${FMIZIPHEADERS}) + +-target_link_libraries(fmizip minizip jmutils) ++target_link_libraries(fmizip minizip::minizip jmutils) + + endif(NOT FMIZIPDIR) +-- +2.30.2 + diff --git a/recipes/fmilibrary/all/patches/2.4.1-005-ensure-conan-friendly-cmakelists.patch b/recipes/fmilibrary/all/patches/2.4.1-005-ensure-conan-friendly-cmakelists.patch new file mode 100644 index 0000000000000..42a41f5049e61 --- /dev/null +++ b/recipes/fmilibrary/all/patches/2.4.1-005-ensure-conan-friendly-cmakelists.patch @@ -0,0 +1,34 @@ +From dc7777f1212cc64c46a12cfd55ab76276a77ac56 Mon Sep 17 00:00:00 2001 +From: Joakim Haugen +Date: Wed, 24 May 2023 16:28:20 +0200 +Subject: [PATCH 3/3] Ensure conan friendly cmakelists + +--- + CMakeLists.txt | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/CMakeLists.txt b/CMakeLists.txt +index b01aba5..56ca3ee 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -200,7 +200,7 @@ endif() + + add_subdirectory(ThirdParty/c99_snprintf) + +-SET(CMAKE_MODULE_PATH ${FMILIBRARYHOME}/Config.cmake) ++list(APPEND CMAKE_MODULE_PATH ${FMILIBRARYHOME}/Config.cmake) + + include(jmutil) + include(fmixml) +@@ -230,7 +230,7 @@ configure_file ( + "${FMILibrary_BINARY_DIR}/fmilib_config.h" + ) + +-set(FMILIB_SHARED_SUBLIBS ${FMIXML_LIBRARIES} ${FMIZIP_LIBRARIES} ${FMICAPI_LIBRARIES} expat minizip zlib c99snprintf) ++set(FMILIB_SHARED_SUBLIBS ${FMIXML_LIBRARIES} ${FMIZIP_LIBRARIES} ${FMICAPI_LIBRARIES} c99snprintf) + set(FMILIB_SUBLIBS ${FMIIMPORT_LIBRARIES} ${JMUTIL_LIBRARIES} ${FMILIB_SHARED_SUBLIBS}) + set(FMILIB_SHARED_SRC ${FMIIMPORTSOURCE} ${JMUTILSOURCE} ${FMIIMPORTHEADERS}) + +-- +2.30.2 + diff --git a/recipes/fmilibrary/all/patches/2.4.1-006-link-external-targets.patch b/recipes/fmilibrary/all/patches/2.4.1-006-link-external-targets.patch new file mode 100644 index 0000000000000..3c95d27adba6f --- /dev/null +++ b/recipes/fmilibrary/all/patches/2.4.1-006-link-external-targets.patch @@ -0,0 +1,47 @@ +From df411a1782a608cbfdc46c9ecafb0a4faae0151f Mon Sep 17 00:00:00 2001 +From: Joakim Haugen +Date: Wed, 24 May 2023 16:46:58 +0200 +Subject: [PATCH] Debug testing + +--- + Config.cmake/runtime_test.cmake | 8 ++++---- + 1 file changed, 4 insertions(+), 4 deletions(-) + +diff --git a/Config.cmake/runtime_test.cmake b/Config.cmake/runtime_test.cmake +index d61137f..0765268 100644 +--- a/Config.cmake/runtime_test.cmake ++++ b/Config.cmake/runtime_test.cmake +@@ -26,7 +26,7 @@ endif() + + #Create function that zipz the dummy FMUs + add_executable (compress_test_fmu_zip ${RTTESTDIR}/compress_test_fmu_zip.c) +-target_link_libraries (compress_test_fmu_zip ${FMIZIP_LIBRARIES}) ++target_link_libraries (compress_test_fmu_zip ${FMIZIP_LIBRARIES} minizip::minizip) + + set_target_properties( + jm_vector_test jm_locale_test compress_test_fmu_zip +@@ -116,7 +116,7 @@ function(compress_fmu OUTPUT_FOLDER_T MODEL_IDENTIFIER_T FILE_NAME_CS_ME_EXT_T T + + endfunction(compress_fmu) + +-set(FMILIBFORTEST fmilib) ++set(FMILIBFORTEST fmilib minizip::minizip expat::expat) + + if(FMILIB_BUILD_SHARED_LIB AND (FMILIB_LINK_TEST_TO_SHAREDLIB OR NOT FMILIB_BUILD_STATIC_LIB)) + set(FMILIBFORTEST fmilib_shared) +@@ -128,10 +128,10 @@ endif() + message(STATUS "Tests will be linked with ${FMILIBFORTEST}" ) + + add_executable (fmi_zip_zip_test ${RTTESTDIR}/FMI1/fmi_zip_zip_test.c ) +-target_link_libraries (fmi_zip_zip_test ${FMIZIP_LIBRARIES}) ++target_link_libraries (fmi_zip_zip_test ${FMIZIP_LIBRARIES} minizip::minizip) + + add_executable (fmi_zip_unzip_test ${RTTESTDIR}/FMI1/fmi_zip_unzip_test.c ) +-target_link_libraries (fmi_zip_unzip_test ${FMIZIP_LIBRARIES}) ++target_link_libraries (fmi_zip_unzip_test ${FMIZIP_LIBRARIES} minizip::minizip) + + add_executable (fmi_import_test + ${RTTESTDIR}/fmi_import_test.c +-- +2.30.2 + diff --git a/recipes/fmilibrary/all/patches/2.4.1-007-enable-testing.patch b/recipes/fmilibrary/all/patches/2.4.1-007-enable-testing.patch new file mode 100644 index 0000000000000..3f1a600ca7316 --- /dev/null +++ b/recipes/fmilibrary/all/patches/2.4.1-007-enable-testing.patch @@ -0,0 +1,24 @@ +From c70876cb1159ecc757d460102d42ed6b6daac66f Mon Sep 17 00:00:00 2001 +From: Joakim Haugen +Date: Fri, 15 Sep 2023 15:26:38 +0200 +Subject: [PATCH] Enable testing + +--- + CMakeLists.txt | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/CMakeLists.txt b/CMakeLists.txt +index b01aba5..eff4b40 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -291,6 +291,7 @@ if(FMILIB_BUILD_SHARED_LIB) + endif() + + if(FMILIB_BUILD_TESTS) ++ enable_testing() + include(runtime_test) + configure_file ( + "${FMILibrary_SOURCE_DIR}/Config.cmake/config_test.h.cmake" +-- +2.30.2 + diff --git a/recipes/fmilibrary/all/test_package/CMakeLists.txt b/recipes/fmilibrary/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..acc92b4852be4 --- /dev/null +++ b/recipes/fmilibrary/all/test_package/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.15) + +project(test_package LANGUAGES C) + +find_package(fmilibrary REQUIRED CONFIG) + +add_executable(${PROJECT_NAME} test_package.c) +target_link_libraries(${PROJECT_NAME} PRIVATE fmilibrary::fmilibrary) diff --git a/recipes/fmilibrary/all/test_package/conanfile.py b/recipes/fmilibrary/all/test_package/conanfile.py new file mode 100644 index 0000000000000..ef5d7042163ec --- /dev/null +++ b/recipes/fmilibrary/all/test_package/conanfile.py @@ -0,0 +1,26 @@ +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import cmake_layout, CMake +import os + + +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") diff --git a/recipes/fmilibrary/all/test_package/test_package.c b/recipes/fmilibrary/all/test_package/test_package.c new file mode 100644 index 0000000000000..a1f640d88c5c5 --- /dev/null +++ b/recipes/fmilibrary/all/test_package/test_package.c @@ -0,0 +1,8 @@ +#include + +int main() { + fmi_import_context_t* c = fmi_import_allocate_context(jm_get_default_callbacks()); + int e = (c == NULL) ? 1 : 0; + fmi_import_free_context(c); + return e; +} diff --git a/recipes/fmilibrary/config.yml b/recipes/fmilibrary/config.yml new file mode 100644 index 0000000000000..3dd5d6d4b289d --- /dev/null +++ b/recipes/fmilibrary/config.yml @@ -0,0 +1,3 @@ +versions: + "2.4.1": + folder: all From 8e699858a7fee3d2f1982bb03b104a13c545a39d Mon Sep 17 00:00:00 2001 From: Joakim Haugen Date: Mon, 2 Oct 2023 11:01:06 +0200 Subject: [PATCH 02/17] Remove alpha version remnants --- recipes/fmilibrary/all/conanfile.py | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/recipes/fmilibrary/all/conanfile.py b/recipes/fmilibrary/all/conanfile.py index 0a0f0dfa6c884..22967532393db 100644 --- a/recipes/fmilibrary/all/conanfile.py +++ b/recipes/fmilibrary/all/conanfile.py @@ -1,10 +1,9 @@ from os import path import posixpath from conan import ConanFile -from conan.errors import ConanInvalidConfiguration -from conan.tools.build import check_min_cppstd from conan.tools.microsoft import is_msvc_static_runtime, is_msvc -from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy, rmdir +from conan.tools.files import ( + apply_conandata_patches, export_conandata_patches, get, copy, rmdir) from conan.tools.scm import Version from conan.tools.env import Environment from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout @@ -59,15 +58,6 @@ def requirements(self): self.requires("minizip/1.2.13") # c99_snprintf -> should be externalised - def build_requirements(self): - if self.version >= Version("3.0a2") and self.options.with_fmus: - self.test_requires("catch2/2.13.10") - - def validate(self): - if self.version >= Version("3.0a2") and self.options.with_fmus: - if self.settings.compiler.get_safe("cppstd"): - check_min_cppstd(self, 11) - def source(self): get(self, **self.conan_data["sources"][self.version], strip_root=True) From eed1b95459b33652c3912bfd960c36c76d24d4df Mon Sep 17 00:00:00 2001 From: Joakim Haugen Date: Wed, 25 Oct 2023 14:00:42 +0200 Subject: [PATCH 03/17] Add missing include and reviewer suggestion --- recipes/fmilibrary/all/conandata.yml | 3 +++ recipes/fmilibrary/all/conanfile.py | 4 ++++ ...4.1-008-add-missing-stdlib.h-include.patch | 23 +++++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 recipes/fmilibrary/all/patches/2.4.1-008-add-missing-stdlib.h-include.patch diff --git a/recipes/fmilibrary/all/conandata.yml b/recipes/fmilibrary/all/conandata.yml index 016f145b8a4c9..e6c5306aebe0e 100644 --- a/recipes/fmilibrary/all/conandata.yml +++ b/recipes/fmilibrary/all/conandata.yml @@ -27,3 +27,6 @@ patches: - patch_file: "patches/2.4.1-007-enable-testing.patch" patch_description: "Ensure that tests can be run with cmake" patch_type: "conan" + - patch_file: "patches/2.4.1-008-add-missing-stdlib.h-include.patch" + patch_description: "exit() is defined in stdlib.h" + patch_type: "conan" diff --git a/recipes/fmilibrary/all/conanfile.py b/recipes/fmilibrary/all/conanfile.py index 22967532393db..8bf987f0c188b 100644 --- a/recipes/fmilibrary/all/conanfile.py +++ b/recipes/fmilibrary/all/conanfile.py @@ -79,6 +79,10 @@ def generate(self): tc.variables["FMILIB_FMI_STANDARD_HEADERS"] = posixpath.join(self.build_folder, "fmis").replace("\\", "/") tc.variables["FMILIB_GENERATE_DOXYGEN_DOC"] = False + # The variable is an option only if the following condition is true + if not self.options.shared and not self.settings.os in ["Windows", "Macos"]: + tc.variables["FMILIB_BUILD_FOR_SHARED_LIBS"] = self.options.get_safe("fPIC", False) + if is_msvc(self): tc.variables["FMILIB_BUILD_WITH_STATIC_RTLIB"] = is_msvc_static_runtime(self) diff --git a/recipes/fmilibrary/all/patches/2.4.1-008-add-missing-stdlib.h-include.patch b/recipes/fmilibrary/all/patches/2.4.1-008-add-missing-stdlib.h-include.patch new file mode 100644 index 0000000000000..17bc90b16df93 --- /dev/null +++ b/recipes/fmilibrary/all/patches/2.4.1-008-add-missing-stdlib.h-include.patch @@ -0,0 +1,23 @@ +From 79a37f7a6173f8bdd3324a0442ab377bcb6f238a Mon Sep 17 00:00:00 2001 +From: Joakim Haugen +Date: Wed, 25 Oct 2023 13:56:43 +0200 +Subject: [PATCH] Add missing stdlib.h include for exit + +--- + Test/jm_locale_test.c | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/Test/jm_locale_test.c b/Test/jm_locale_test.c +index 5970c65..40f711d 100644 +--- a/Test/jm_locale_test.c ++++ b/Test/jm_locale_test.c +@@ -1,5 +1,6 @@ + #include + #include ++#include + #include + #include + +-- +2.30.2 + From bfc74d2d36623b02caf1bff487bd55702e707aee Mon Sep 17 00:00:00 2001 From: Joakim Haugen Date: Mon, 30 Oct 2023 09:34:08 +0100 Subject: [PATCH 04/17] fmilibrary does not support armv8 Macos yet --- recipes/fmilibrary/all/conanfile.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/recipes/fmilibrary/all/conanfile.py b/recipes/fmilibrary/all/conanfile.py index 8bf987f0c188b..0d5733fef0ff8 100644 --- a/recipes/fmilibrary/all/conanfile.py +++ b/recipes/fmilibrary/all/conanfile.py @@ -1,6 +1,7 @@ from os import path import posixpath from conan import ConanFile +from conan.errors import ConanInvalidConfiguration from conan.tools.microsoft import is_msvc_static_runtime, is_msvc from conan.tools.files import ( apply_conandata_patches, export_conandata_patches, get, copy, rmdir) @@ -58,6 +59,12 @@ def requirements(self): self.requires("minizip/1.2.13") # c99_snprintf -> should be externalised + def validate(self): + if self.settings.os == "Macos" and self.settings.arch == "armv8": + raise ConanInvalidConfiguration( + f"{self.ref} does not support architecture " + f"'{self.settings.arch}' on {self.settings.os}") + def source(self): get(self, **self.conan_data["sources"][self.version], strip_root=True) From 0ef2f16b55814000b03dc89984657e6499f7a2c3 Mon Sep 17 00:00:00 2001 From: Joakim Haugen Date: Mon, 30 Oct 2023 12:02:50 +0100 Subject: [PATCH 05/17] Make zlib a direct dependency --- recipes/fmilibrary/all/conandata.yml | 3 ++ recipes/fmilibrary/all/conanfile.py | 1 + .../2.4.1-009-link-zlib-in-fmilib.patch | 28 +++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 recipes/fmilibrary/all/patches/2.4.1-009-link-zlib-in-fmilib.patch diff --git a/recipes/fmilibrary/all/conandata.yml b/recipes/fmilibrary/all/conandata.yml index e6c5306aebe0e..a9c91a2a64a90 100644 --- a/recipes/fmilibrary/all/conandata.yml +++ b/recipes/fmilibrary/all/conandata.yml @@ -30,3 +30,6 @@ patches: - patch_file: "patches/2.4.1-008-add-missing-stdlib.h-include.patch" patch_description: "exit() is defined in stdlib.h" patch_type: "conan" + - patch_file: "patches/2.4.1-009-link-zlib-in-fmilib.patch" + patch_description: "zlib must be linked explicitly due to minizip.c and miniunz.c inclusion" + patch_type: "conan" diff --git a/recipes/fmilibrary/all/conanfile.py b/recipes/fmilibrary/all/conanfile.py index 0d5733fef0ff8..3bdfaa3fdff3c 100644 --- a/recipes/fmilibrary/all/conanfile.py +++ b/recipes/fmilibrary/all/conanfile.py @@ -57,6 +57,7 @@ def requirements(self): self.requires("fmi3/3.0.1") self.requires("expat/2.4.9") self.requires("minizip/1.2.13") + self.requires("zlib/[>=1.2.11 <2]") # c99_snprintf -> should be externalised def validate(self): diff --git a/recipes/fmilibrary/all/patches/2.4.1-009-link-zlib-in-fmilib.patch b/recipes/fmilibrary/all/patches/2.4.1-009-link-zlib-in-fmilib.patch new file mode 100644 index 0000000000000..e26991de02048 --- /dev/null +++ b/recipes/fmilibrary/all/patches/2.4.1-009-link-zlib-in-fmilib.patch @@ -0,0 +1,28 @@ +From 9478e541f41e7c9df0fb37a459c093e41848ae2e Mon Sep 17 00:00:00 2001 +From: Joakim Haugen +Date: Mon, 30 Oct 2023 10:11:24 +0100 +Subject: [PATCH] Link zlib in a test + +--- + Config.cmake/fmizip.cmake | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/Config.cmake/fmizip.cmake b/Config.cmake/fmizip.cmake +index 7618d51..213b5f8 100644 +--- a/Config.cmake/fmizip.cmake ++++ b/Config.cmake/fmizip.cmake +@@ -42,9 +42,10 @@ set(FMIZIPHEADERS + #include_directories("${FMILIB_THIRDPARTYLIBS}/zlib/lib/VS2005/win32") + + find_package(minizip CONFIG REQUIRED) ++find_package(ZLIB CONFIG REQUIRED) + + add_library(fmizip ${FMILIBKIND} ${FMIZIPSOURCE} ${FMIZIPHEADERS}) + +-target_link_libraries(fmizip minizip::minizip jmutils) ++target_link_libraries(fmizip minizip::minizip ZLIB::ZLIB jmutils) + + endif(NOT FMIZIPDIR) +-- +2.30.2 + From 1cf10e7ad2d537d4c3d2a2d9bb07a5db937c435e Mon Sep 17 00:00:00 2001 From: Joakim Haugen Date: Mon, 30 Oct 2023 13:38:25 +0100 Subject: [PATCH 06/17] Fix shared build windows --- recipes/fmilibrary/all/conandata.yml | 3 +++ recipes/fmilibrary/all/conanfile.py | 5 +++- .../2.4.1-010-install-runtime-to-bin.patch | 25 +++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 recipes/fmilibrary/all/patches/2.4.1-010-install-runtime-to-bin.patch diff --git a/recipes/fmilibrary/all/conandata.yml b/recipes/fmilibrary/all/conandata.yml index a9c91a2a64a90..6f87db573474b 100644 --- a/recipes/fmilibrary/all/conandata.yml +++ b/recipes/fmilibrary/all/conandata.yml @@ -33,3 +33,6 @@ patches: - patch_file: "patches/2.4.1-009-link-zlib-in-fmilib.patch" patch_description: "zlib must be linked explicitly due to minizip.c and miniunz.c inclusion" patch_type: "conan" + - patch_file: "patches/2.4.1-010-install-runtime-to-bin.patch" + patch_description: "install runtime (dll) to bin instead of lib" + patch_type: "conan" diff --git a/recipes/fmilibrary/all/conanfile.py b/recipes/fmilibrary/all/conanfile.py index 3bdfaa3fdff3c..b0902c663ae69 100644 --- a/recipes/fmilibrary/all/conanfile.py +++ b/recipes/fmilibrary/all/conanfile.py @@ -6,7 +6,7 @@ from conan.tools.files import ( apply_conandata_patches, export_conandata_patches, get, copy, rmdir) from conan.tools.scm import Version -from conan.tools.env import Environment +from conan.tools.env import Environment, VirtualRunEnv from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout required_conan_version = ">=1.53.0" @@ -102,6 +102,9 @@ def generate(self): tc = CMakeDeps(self) tc.generate() + vre = VirtualRunEnv(self) + vre.generate(scope="build") + def build(self): apply_conandata_patches(self) cmake = CMake(self) diff --git a/recipes/fmilibrary/all/patches/2.4.1-010-install-runtime-to-bin.patch b/recipes/fmilibrary/all/patches/2.4.1-010-install-runtime-to-bin.patch new file mode 100644 index 0000000000000..169a5adee58a0 --- /dev/null +++ b/recipes/fmilibrary/all/patches/2.4.1-010-install-runtime-to-bin.patch @@ -0,0 +1,25 @@ +From 1c1fdb0d864682cb85433fc29cacbe829393eb1d Mon Sep 17 00:00:00 2001 +From: Joakim Haugen +Date: Mon, 30 Oct 2023 13:12:34 +0100 +Subject: [PATCH] Install runtime to bin + +--- + CMakeLists.txt | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/CMakeLists.txt b/CMakeLists.txt +index cc2a25c..0bb24f6 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -304,7 +304,7 @@ file(COPY "${FMILIBRARYHOME}/Config.cmake/fmilib.h" DESTINATION "${FMILibrary_BI + install(TARGETS ${FMILIB_TARGETS} + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib +- RUNTIME DESTINATION lib ++ RUNTIME DESTINATION bin + ) + install(FILES + "${FMILIBRARYHOME}/FMILIB_Readme.txt" +-- +2.30.2 + From 8b3f0f5d59ad18b2c5d45e14196b463a01e1a6a8 Mon Sep 17 00:00:00 2001 From: Joakim Haugen Date: Mon, 30 Oct 2023 14:20:13 +0100 Subject: [PATCH 07/17] Fix post package warnings --- recipes/fmilibrary/all/conanfile.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/recipes/fmilibrary/all/conanfile.py b/recipes/fmilibrary/all/conanfile.py index b0902c663ae69..7b99a38e8c3cb 100644 --- a/recipes/fmilibrary/all/conanfile.py +++ b/recipes/fmilibrary/all/conanfile.py @@ -2,6 +2,7 @@ import posixpath from conan import ConanFile from conan.errors import ConanInvalidConfiguration +from conan.tools.apple import fix_apple_shared_install_name from conan.tools.microsoft import is_msvc_static_runtime, is_msvc from conan.tools.files import ( apply_conandata_patches, export_conandata_patches, get, copy, rmdir) @@ -128,6 +129,7 @@ def package(self): cmake = CMake(self) cmake.install() + fix_apple_shared_install_name(self) rmdir(self, path.join(self.package_folder, "doc")) @@ -141,6 +143,6 @@ def package_info(self): self.cpp_info.system_libs.append("dl") if self.settings.os in ["Windows"]: - self.cpp_info.system_libs.append("Shlwapi") + self.cpp_info.system_libs.append("shlwapi") self.cpp_info.resdirs = ["res"] From ed70246e44b3e1152cd62c95804180dfed9d3c12 Mon Sep 17 00:00:00 2001 From: Joakim Haugen Date: Tue, 31 Oct 2023 09:20:36 +0100 Subject: [PATCH 08/17] Apply suggestions from code review Co-authored-by: Uilian Ries --- recipes/fmilibrary/all/conanfile.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/recipes/fmilibrary/all/conanfile.py b/recipes/fmilibrary/all/conanfile.py index 7b99a38e8c3cb..fd5ff00e3f81f 100644 --- a/recipes/fmilibrary/all/conanfile.py +++ b/recipes/fmilibrary/all/conanfile.py @@ -44,10 +44,6 @@ def configure(self): if self.options.shared: self.options.rm_safe("fPIC") - self.options["expat"].shared = self.options.shared - self.options["minizip"].shared = self.options.shared - self.options["zlib"].shared = self.options.shared - def layout(self): cmake_layout(self, src_folder="src") @@ -112,12 +108,6 @@ def build(self): cmake.configure() cmake.build() - if not self.conf.get("tools.build:skip_test", default=True): - env = Environment() - env.define("CTEST_OUTPUT_ON_FAILURE", "ON") - with env.vars(self).apply(): - cmake.test() - def package(self): copy(self, pattern="LICENSE.md", dst=path.join(self.package_folder, "licenses"), src=self.source_folder) From c3255d75658e172f8bd679bda3cdf46bf99e1e06 Mon Sep 17 00:00:00 2001 From: Joakim Haugen Date: Tue, 31 Oct 2023 10:05:47 +0100 Subject: [PATCH 09/17] Move fmi copy to build and bump expat to 2.5.0 --- recipes/fmilibrary/all/conanfile.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/recipes/fmilibrary/all/conanfile.py b/recipes/fmilibrary/all/conanfile.py index fd5ff00e3f81f..079a95cdb6571 100644 --- a/recipes/fmilibrary/all/conanfile.py +++ b/recipes/fmilibrary/all/conanfile.py @@ -7,7 +7,7 @@ from conan.tools.files import ( apply_conandata_patches, export_conandata_patches, get, copy, rmdir) from conan.tools.scm import Version -from conan.tools.env import Environment, VirtualRunEnv +from conan.tools.env import VirtualRunEnv from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout required_conan_version = ">=1.53.0" @@ -52,13 +52,14 @@ def requirements(self): self.requires("fmi2/2.0.4") if self.version >= Version("3.0a2"): self.requires("fmi3/3.0.1") - self.requires("expat/2.4.9") + self.requires("expat/2.5.0") self.requires("minizip/1.2.13") self.requires("zlib/[>=1.2.11 <2]") # c99_snprintf -> should be externalised def validate(self): - if self.settings.os == "Macos" and self.settings.arch == "armv8": + # https://github.com/modelon-community/fmi-library/issues/93 + if self.settings.arch not in ["x86", "x86_64"] and Version(self.version).major < 3: raise ConanInvalidConfiguration( f"{self.ref} does not support architecture " f"'{self.settings.arch}' on {self.settings.os}") @@ -68,15 +69,6 @@ def source(self): def generate(self): - copy(self, "fmiModel*.h", self.dependencies["fmi1"].cpp_info.components["modex"].includedirs[0], - path.join(self.build_folder, "fmis", "FMI1")) - copy(self, "fmiPlatformTypes.h", self.dependencies["fmi1"].cpp_info.components["cosim"].includedirs[0], - path.join(self.build_folder, "fmis", "FMI1")) - copy(self, "fmiFunctions.h", self.dependencies["fmi1"].cpp_info.components["cosim"].includedirs[0], - path.join(self.build_folder, "fmis", "FMI1")) - copy(self, "*.h", self.dependencies["fmi2"].cpp_info.includedirs[0], - path.join(self.build_folder, "fmis", "FMI2")) - tc = CMakeToolchain(self) tc.variables["FMILIB_BUILD_STATIC_LIB"] = not self.options.shared tc.variables["FMILIB_BUILD_SHARED_LIB"] = self.options.shared @@ -104,6 +96,16 @@ def generate(self): def build(self): apply_conandata_patches(self) + + copy(self, "fmiModel*.h", self.dependencies["fmi1"].cpp_info.components["modex"].includedirs[0], + path.join(self.build_folder, "fmis", "FMI1")) + copy(self, "fmiPlatformTypes.h", self.dependencies["fmi1"].cpp_info.components["cosim"].includedirs[0], + path.join(self.build_folder, "fmis", "FMI1")) + copy(self, "fmiFunctions.h", self.dependencies["fmi1"].cpp_info.components["cosim"].includedirs[0], + path.join(self.build_folder, "fmis", "FMI1")) + copy(self, "*.h", self.dependencies["fmi2"].cpp_info.includedirs[0], + path.join(self.build_folder, "fmis", "FMI2")) + cmake = CMake(self) cmake.configure() cmake.build() From a616a6dd69f29d2b60676e41111b57433ea1b11d Mon Sep 17 00:00:00 2001 From: Joakim Haugen Date: Wed, 8 Nov 2023 09:23:35 +0100 Subject: [PATCH 10/17] Address reviewer suggestions - rename to fmilib - remove unecessary patches - move dll in recipe instead --- .../{fmilibrary => fmilib}/all/conandata.yml | 13 +++------- .../{fmilibrary => fmilib}/all/conanfile.py | 15 ++++++++--- .../2.4.1-001-static-c99snprintf.patch | 0 ...1-002-add-minizip-tools-as-functions.patch | 0 .../2.4.1-003-use-expat-from-conan.patch | 0 ...-004-use-minizip-and-zlib-from-conan.patch | 0 ...005-ensure-conan-friendly-cmakelists.patch | 0 .../2.4.1-006-link-external-targets.patch | 0 ....1-007-add-missing-stdlib.h-include.patch} | 0 .../2.4.1-008-link-zlib-in-fmilib.patch} | 0 .../all/test_package/CMakeLists.txt | 2 +- .../all/test_package/conanfile.py | 0 .../all/test_package/test_package.c | 0 recipes/{fmilibrary => fmilib}/config.yml | 0 .../patches/2.4.1-007-enable-testing.patch | 24 ------------------ .../2.4.1-010-install-runtime-to-bin.patch | 25 ------------------- 16 files changed, 16 insertions(+), 63 deletions(-) rename recipes/{fmilibrary => fmilib}/all/conandata.yml (77%) rename recipes/{fmilibrary => fmilib}/all/conanfile.py (93%) rename recipes/{fmilibrary => fmilib}/all/patches/2.4.1-001-static-c99snprintf.patch (100%) rename recipes/{fmilibrary => fmilib}/all/patches/2.4.1-002-add-minizip-tools-as-functions.patch (100%) rename recipes/{fmilibrary => fmilib}/all/patches/2.4.1-003-use-expat-from-conan.patch (100%) rename recipes/{fmilibrary => fmilib}/all/patches/2.4.1-004-use-minizip-and-zlib-from-conan.patch (100%) rename recipes/{fmilibrary => fmilib}/all/patches/2.4.1-005-ensure-conan-friendly-cmakelists.patch (100%) rename recipes/{fmilibrary => fmilib}/all/patches/2.4.1-006-link-external-targets.patch (100%) rename recipes/{fmilibrary/all/patches/2.4.1-008-add-missing-stdlib.h-include.patch => fmilib/all/patches/2.4.1-007-add-missing-stdlib.h-include.patch} (100%) rename recipes/{fmilibrary/all/patches/2.4.1-009-link-zlib-in-fmilib.patch => fmilib/all/patches/2.4.1-008-link-zlib-in-fmilib.patch} (100%) rename recipes/{fmilibrary => fmilib}/all/test_package/CMakeLists.txt (82%) rename recipes/{fmilibrary => fmilib}/all/test_package/conanfile.py (100%) rename recipes/{fmilibrary => fmilib}/all/test_package/test_package.c (100%) rename recipes/{fmilibrary => fmilib}/config.yml (100%) delete mode 100644 recipes/fmilibrary/all/patches/2.4.1-007-enable-testing.patch delete mode 100644 recipes/fmilibrary/all/patches/2.4.1-010-install-runtime-to-bin.patch diff --git a/recipes/fmilibrary/all/conandata.yml b/recipes/fmilib/all/conandata.yml similarity index 77% rename from recipes/fmilibrary/all/conandata.yml rename to recipes/fmilib/all/conandata.yml index 6f87db573474b..7578a53b54e64 100644 --- a/recipes/fmilibrary/all/conandata.yml +++ b/recipes/fmilib/all/conandata.yml @@ -24,15 +24,10 @@ patches: - patch_file: "patches/2.4.1-006-link-external-targets.patch" patch_description: "Link external targets no longer merged in fmilib" patch_type: "conan" - - patch_file: "patches/2.4.1-007-enable-testing.patch" - patch_description: "Ensure that tests can be run with cmake" - patch_type: "conan" - - patch_file: "patches/2.4.1-008-add-missing-stdlib.h-include.patch" + - patch_file: "patches/2.4.1-007-add-missing-stdlib.h-include.patch" patch_description: "exit() is defined in stdlib.h" - patch_type: "conan" - - patch_file: "patches/2.4.1-009-link-zlib-in-fmilib.patch" + patch_type: "bugfix" + patch_source: "https://github.com/modelon-community/fmi-library/issues/95" + - patch_file: "patches/2.4.1-008-link-zlib-in-fmilib.patch" patch_description: "zlib must be linked explicitly due to minizip.c and miniunz.c inclusion" patch_type: "conan" - - patch_file: "patches/2.4.1-010-install-runtime-to-bin.patch" - patch_description: "install runtime (dll) to bin instead of lib" - patch_type: "conan" diff --git a/recipes/fmilibrary/all/conanfile.py b/recipes/fmilib/all/conanfile.py similarity index 93% rename from recipes/fmilibrary/all/conanfile.py rename to recipes/fmilib/all/conanfile.py index 079a95cdb6571..50be0b95c4332 100644 --- a/recipes/fmilibrary/all/conanfile.py +++ b/recipes/fmilib/all/conanfile.py @@ -5,7 +5,7 @@ from conan.tools.apple import fix_apple_shared_install_name from conan.tools.microsoft import is_msvc_static_runtime, is_msvc from conan.tools.files import ( - apply_conandata_patches, export_conandata_patches, get, copy, rmdir) + apply_conandata_patches, export_conandata_patches, get, copy, rm, rmdir) from conan.tools.scm import Version from conan.tools.env import VirtualRunEnv from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout @@ -14,7 +14,7 @@ class PackageConan(ConanFile): - name = "fmilibrary" + name = "fmilib" description = "C library for importing FMUs" license = "BSD-3-Clause" url = "https://github.com/conan-io/conan-center-index" @@ -88,8 +88,9 @@ def generate(self): tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0046"] = "OLD" tc.generate() - tc = CMakeDeps(self) - tc.generate() + + cd = CMakeDeps(self) + cd.generate() vre = VirtualRunEnv(self) vre.generate(scope="build") @@ -121,6 +122,11 @@ def package(self): cmake = CMake(self) cmake.install() + + copy(self, pattern="*.dll", dst=path.join(self.package_folder, "bin"), + src=path.join(self.package_folder, "lib"), keep_path=False) + rm(self, "*.dll", path.join(self.package_folder, "lib")) + fix_apple_shared_install_name(self) rmdir(self, path.join(self.package_folder, "doc")) @@ -138,3 +144,4 @@ def package_info(self): self.cpp_info.system_libs.append("shlwapi") self.cpp_info.resdirs = ["res"] + self.cpp_info.set_property("cmake_target_aliases", ["fmilibrary::fmilibrary"]) diff --git a/recipes/fmilibrary/all/patches/2.4.1-001-static-c99snprintf.patch b/recipes/fmilib/all/patches/2.4.1-001-static-c99snprintf.patch similarity index 100% rename from recipes/fmilibrary/all/patches/2.4.1-001-static-c99snprintf.patch rename to recipes/fmilib/all/patches/2.4.1-001-static-c99snprintf.patch diff --git a/recipes/fmilibrary/all/patches/2.4.1-002-add-minizip-tools-as-functions.patch b/recipes/fmilib/all/patches/2.4.1-002-add-minizip-tools-as-functions.patch similarity index 100% rename from recipes/fmilibrary/all/patches/2.4.1-002-add-minizip-tools-as-functions.patch rename to recipes/fmilib/all/patches/2.4.1-002-add-minizip-tools-as-functions.patch diff --git a/recipes/fmilibrary/all/patches/2.4.1-003-use-expat-from-conan.patch b/recipes/fmilib/all/patches/2.4.1-003-use-expat-from-conan.patch similarity index 100% rename from recipes/fmilibrary/all/patches/2.4.1-003-use-expat-from-conan.patch rename to recipes/fmilib/all/patches/2.4.1-003-use-expat-from-conan.patch diff --git a/recipes/fmilibrary/all/patches/2.4.1-004-use-minizip-and-zlib-from-conan.patch b/recipes/fmilib/all/patches/2.4.1-004-use-minizip-and-zlib-from-conan.patch similarity index 100% rename from recipes/fmilibrary/all/patches/2.4.1-004-use-minizip-and-zlib-from-conan.patch rename to recipes/fmilib/all/patches/2.4.1-004-use-minizip-and-zlib-from-conan.patch diff --git a/recipes/fmilibrary/all/patches/2.4.1-005-ensure-conan-friendly-cmakelists.patch b/recipes/fmilib/all/patches/2.4.1-005-ensure-conan-friendly-cmakelists.patch similarity index 100% rename from recipes/fmilibrary/all/patches/2.4.1-005-ensure-conan-friendly-cmakelists.patch rename to recipes/fmilib/all/patches/2.4.1-005-ensure-conan-friendly-cmakelists.patch diff --git a/recipes/fmilibrary/all/patches/2.4.1-006-link-external-targets.patch b/recipes/fmilib/all/patches/2.4.1-006-link-external-targets.patch similarity index 100% rename from recipes/fmilibrary/all/patches/2.4.1-006-link-external-targets.patch rename to recipes/fmilib/all/patches/2.4.1-006-link-external-targets.patch diff --git a/recipes/fmilibrary/all/patches/2.4.1-008-add-missing-stdlib.h-include.patch b/recipes/fmilib/all/patches/2.4.1-007-add-missing-stdlib.h-include.patch similarity index 100% rename from recipes/fmilibrary/all/patches/2.4.1-008-add-missing-stdlib.h-include.patch rename to recipes/fmilib/all/patches/2.4.1-007-add-missing-stdlib.h-include.patch diff --git a/recipes/fmilibrary/all/patches/2.4.1-009-link-zlib-in-fmilib.patch b/recipes/fmilib/all/patches/2.4.1-008-link-zlib-in-fmilib.patch similarity index 100% rename from recipes/fmilibrary/all/patches/2.4.1-009-link-zlib-in-fmilib.patch rename to recipes/fmilib/all/patches/2.4.1-008-link-zlib-in-fmilib.patch diff --git a/recipes/fmilibrary/all/test_package/CMakeLists.txt b/recipes/fmilib/all/test_package/CMakeLists.txt similarity index 82% rename from recipes/fmilibrary/all/test_package/CMakeLists.txt rename to recipes/fmilib/all/test_package/CMakeLists.txt index acc92b4852be4..c2ddba84ccd74 100644 --- a/recipes/fmilibrary/all/test_package/CMakeLists.txt +++ b/recipes/fmilib/all/test_package/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.15) project(test_package LANGUAGES C) -find_package(fmilibrary REQUIRED CONFIG) +find_package(fmilib REQUIRED CONFIG) add_executable(${PROJECT_NAME} test_package.c) target_link_libraries(${PROJECT_NAME} PRIVATE fmilibrary::fmilibrary) diff --git a/recipes/fmilibrary/all/test_package/conanfile.py b/recipes/fmilib/all/test_package/conanfile.py similarity index 100% rename from recipes/fmilibrary/all/test_package/conanfile.py rename to recipes/fmilib/all/test_package/conanfile.py diff --git a/recipes/fmilibrary/all/test_package/test_package.c b/recipes/fmilib/all/test_package/test_package.c similarity index 100% rename from recipes/fmilibrary/all/test_package/test_package.c rename to recipes/fmilib/all/test_package/test_package.c diff --git a/recipes/fmilibrary/config.yml b/recipes/fmilib/config.yml similarity index 100% rename from recipes/fmilibrary/config.yml rename to recipes/fmilib/config.yml diff --git a/recipes/fmilibrary/all/patches/2.4.1-007-enable-testing.patch b/recipes/fmilibrary/all/patches/2.4.1-007-enable-testing.patch deleted file mode 100644 index 3f1a600ca7316..0000000000000 --- a/recipes/fmilibrary/all/patches/2.4.1-007-enable-testing.patch +++ /dev/null @@ -1,24 +0,0 @@ -From c70876cb1159ecc757d460102d42ed6b6daac66f Mon Sep 17 00:00:00 2001 -From: Joakim Haugen -Date: Fri, 15 Sep 2023 15:26:38 +0200 -Subject: [PATCH] Enable testing - ---- - CMakeLists.txt | 1 + - 1 file changed, 1 insertion(+) - -diff --git a/CMakeLists.txt b/CMakeLists.txt -index b01aba5..eff4b40 100644 ---- a/CMakeLists.txt -+++ b/CMakeLists.txt -@@ -291,6 +291,7 @@ if(FMILIB_BUILD_SHARED_LIB) - endif() - - if(FMILIB_BUILD_TESTS) -+ enable_testing() - include(runtime_test) - configure_file ( - "${FMILibrary_SOURCE_DIR}/Config.cmake/config_test.h.cmake" --- -2.30.2 - diff --git a/recipes/fmilibrary/all/patches/2.4.1-010-install-runtime-to-bin.patch b/recipes/fmilibrary/all/patches/2.4.1-010-install-runtime-to-bin.patch deleted file mode 100644 index 169a5adee58a0..0000000000000 --- a/recipes/fmilibrary/all/patches/2.4.1-010-install-runtime-to-bin.patch +++ /dev/null @@ -1,25 +0,0 @@ -From 1c1fdb0d864682cb85433fc29cacbe829393eb1d Mon Sep 17 00:00:00 2001 -From: Joakim Haugen -Date: Mon, 30 Oct 2023 13:12:34 +0100 -Subject: [PATCH] Install runtime to bin - ---- - CMakeLists.txt | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/CMakeLists.txt b/CMakeLists.txt -index cc2a25c..0bb24f6 100644 ---- a/CMakeLists.txt -+++ b/CMakeLists.txt -@@ -304,7 +304,7 @@ file(COPY "${FMILIBRARYHOME}/Config.cmake/fmilib.h" DESTINATION "${FMILibrary_BI - install(TARGETS ${FMILIB_TARGETS} - ARCHIVE DESTINATION lib - LIBRARY DESTINATION lib -- RUNTIME DESTINATION lib -+ RUNTIME DESTINATION bin - ) - install(FILES - "${FMILIBRARYHOME}/FMILIB_Readme.txt" --- -2.30.2 - From 94483e4e2f1134dc712b50a59a02e8174c022617 Mon Sep 17 00:00:00 2001 From: Joakim Haugen Date: Wed, 8 Nov 2023 13:11:50 +0100 Subject: [PATCH 11/17] enforce that fmilib is pure C --- recipes/fmilib/all/conandata.yml | 3 + recipes/fmilib/all/conanfile.py | 12 ++- .../2.4.1-003-use-expat-from-conan.patch | 101 +++++++++++++++--- .../2.4.1-009-make-project-pure-c.patch | 39 +++++++ 4 files changed, 137 insertions(+), 18 deletions(-) create mode 100644 recipes/fmilib/all/patches/2.4.1-009-make-project-pure-c.patch diff --git a/recipes/fmilib/all/conandata.yml b/recipes/fmilib/all/conandata.yml index 7578a53b54e64..03bd6d4b9b4a6 100644 --- a/recipes/fmilib/all/conandata.yml +++ b/recipes/fmilib/all/conandata.yml @@ -31,3 +31,6 @@ patches: - patch_file: "patches/2.4.1-008-link-zlib-in-fmilib.patch" patch_description: "zlib must be linked explicitly due to minizip.c and miniunz.c inclusion" patch_type: "conan" + - patch_file: "patches/2.4.1-009-make-project-pure-c.patch" + patch_description: "Project is pure C when not compiling external dependencies" + patch_type: "conan" diff --git a/recipes/fmilib/all/conanfile.py b/recipes/fmilib/all/conanfile.py index 50be0b95c4332..8f355515f6657 100644 --- a/recipes/fmilib/all/conanfile.py +++ b/recipes/fmilib/all/conanfile.py @@ -5,7 +5,9 @@ from conan.tools.apple import fix_apple_shared_install_name from conan.tools.microsoft import is_msvc_static_runtime, is_msvc from conan.tools.files import ( - apply_conandata_patches, export_conandata_patches, get, copy, rm, rmdir) + apply_conandata_patches, export_conandata_patches, + get, copy, rename, rm, rmdir + ) from conan.tools.scm import Version from conan.tools.env import VirtualRunEnv from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout @@ -44,6 +46,9 @@ def configure(self): if self.options.shared: self.options.rm_safe("fPIC") + self.settings.rm_safe("compiler.libcxx") + self.settings.rm_safe("compiler.cppstd") + def layout(self): cmake_layout(self, src_folder="src") @@ -98,6 +103,11 @@ def generate(self): def build(self): apply_conandata_patches(self) + # Rename c++ suffix to c to avoid CMake's confusion + fmi2_folder = path.join(self.source_folder, "Test", "FMI2") + rename(self, path.join(fmi2_folder, "fmi2_import_xml_test.cc"), + path.join(fmi2_folder, "fmi2_import_xml_test.c")) + copy(self, "fmiModel*.h", self.dependencies["fmi1"].cpp_info.components["modex"].includedirs[0], path.join(self.build_folder, "fmis", "FMI1")) copy(self, "fmiPlatformTypes.h", self.dependencies["fmi1"].cpp_info.components["cosim"].includedirs[0], diff --git a/recipes/fmilib/all/patches/2.4.1-003-use-expat-from-conan.patch b/recipes/fmilib/all/patches/2.4.1-003-use-expat-from-conan.patch index 0275aa7884759..2daee074a055f 100644 --- a/recipes/fmilib/all/patches/2.4.1-003-use-expat-from-conan.patch +++ b/recipes/fmilib/all/patches/2.4.1-003-use-expat-from-conan.patch @@ -1,36 +1,103 @@ -From b7d707b76a5c447d30ef67bd4eb9f3a9e9faffd7 Mon Sep 17 00:00:00 2001 +From c19a6b34a9f406e17da642f30e2507a5cc6b1519 Mon Sep 17 00:00:00 2001 From: Joakim Haugen -Date: Wed, 24 May 2023 16:23:04 +0200 -Subject: [PATCH 1/3] Use expat from conan +Date: Wed, 8 Nov 2023 12:16:23 +0100 +Subject: [PATCH] Do not add expat as external project --- - Config.cmake/fmixml.cmake | 7 +++++-- - 1 file changed, 5 insertions(+), 2 deletions(-) + Config.cmake/fmixml.cmake | 81 ++------------------------------------- + 1 file changed, 3 insertions(+), 78 deletions(-) diff --git a/Config.cmake/fmixml.cmake b/Config.cmake/fmixml.cmake -index ddd3c1f..c60322c 100644 +index ddd3c1f..7aa7ffa 100644 --- a/Config.cmake/fmixml.cmake +++ b/Config.cmake/fmixml.cmake -@@ -137,6 +137,7 @@ set(FMIXMLSOURCE +@@ -137,83 +137,8 @@ set(FMIXMLSOURCE src/FMI2/fmi2_xml_variable.c ) -+if(FALSE) - include(ExternalProject) - - # The *_POSTFIX variables are set because it makes it easier to determine the name of -@@ -213,7 +214,9 @@ endif() - - set(EXPAT_INCLUDE_DIRS ${CMAKE_BINARY_DIR}/ExpatEx/install/include) - +-include(ExternalProject) +- +-# The *_POSTFIX variables are set because it makes it easier to determine the name of +-# the lib expat will produce at configure time. Note that Expat has some special handling +-# for it for MSVC which this in effect negates. https://github.com/libexpat/libexpat/pull/316 +-set(EXPAT_SETTINGS +- -DEXPAT_BUILD_TOOLS:BOOLEAN=OFF +- -DEXPAT_BUILD_EXAMPLES:BOOLEAN=OFF +- -DEXPAT_BUILD_TESTS:BOOLEAN=OFF +- -DEXPAT_SHARED_LIBS:BOOLEAN=OFF +- -DEXPAT_DTD:BOOLEAN=OFF +- -DEXPAT_NS:BOOLEAN=OFF +- -DEXPAT_MSVC_STATIC_CRT:BOOLEAN=${FMILIB_BUILD_WITH_STATIC_RTLIB} +- -DCMAKE_DEBUG_POSTFIX:STRING= +- -DCMAKE_RELEASE_POSTFIX:STRING= +- -DCMAKE_MINSIZEREL_POSTFIX:STRING= +- -DCMAKE_RELWITHDEBINFO_POSTFIX:STRING= +- -DCMAKE_POSITION_INDEPENDENT_CODE:BOOLEAN=ON +- -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} +- -DCMAKE_EXE_LINKER_FLAGS:STRING=${CMAKE_EXE_LINKER_FLAGS} +- -DCMAKE_LINK_LIBRARY_FLAG:STRING=${CMAKE_LINK_LIBRARY_FLAG} +- -DCMAKE_MODULE_LINKER_FLAGS:STRING=${CMAKE_MODULE_LINKER_FLAGS} +- -DCMAKE_SHARED_LINKER_FLAGS:STRING=${CMAKE_SHARED_LINKER_FLAGS} +- -DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_BINARY_DIR}/ExpatEx/install +-) +- +-ExternalProject_Add( +- expatex +- PREFIX "${FMIXML_EXPAT_DIR}" +- SOURCE_DIR "${FMIXML_EXPAT_DIR}" +- CMAKE_CACHE_ARGS ${EXPAT_SETTINGS} +- BINARY_DIR ${CMAKE_BINARY_DIR}/ExpatEx +- INSTALL_DIR ${CMAKE_BINARY_DIR}/ExpatEx/install +- TMP_DIR ${CMAKE_BINARY_DIR}/ExpatEx/tmp +- STAMP_DIR ${CMAKE_BINARY_DIR}/ExpatEx/stamp +-) +- +-ExternalProject_Add_Step( +- expatex dependent_reconfigure +- DEPENDEES configure +- DEPENDERS build +- COMMAND ${CMAKE_COMMAND} -E echo "Running: ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" ${EXPAT_SETTINGS} ${FMIXML_EXPAT_DIR}" +- COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" ${EXPAT_SETTINGS} "${FMIXML_EXPAT_DIR}" +- DEPENDS ${CMAKE_BINARY_DIR}/CMakeCache.txt +- WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/ExpatEx +-) +- +-add_dependencies(expatex ${CMAKE_BINARY_DIR}/CMakeCache.txt ${FMILIBRARYHOME}/CMakeLists.txt) +- +- +-if(MSVC) +- # Expat uses special naming with MSVC, which is mirrored here. +- set(EXPAT_LIB_PREFIX lib) +-else() +- set(EXPAT_LIB_PREFIX ${CMAKE_STATIC_LIBRARY_PREFIX}) +-endif() +- +-set(expatlib "${CMAKE_BINARY_DIR}/ExpatEx/${CMAKE_CFG_INTDIR}/${EXPAT_LIB_PREFIX}expat${CMAKE_STATIC_LIBRARY_SUFFIX}") +- +-add_library(expat STATIC IMPORTED) +- +-set_target_properties( +- expat PROPERTIES +- IMPORTED_LOCATION "${expatlib}" +-) +- +-add_dependencies(expat expatex) +- +-if(FMILIB_INSTALL_SUBLIBS) +- install(FILES +- "${CMAKE_BINARY_DIR}/ExpatEx/install/lib/${CMAKE_STATIC_LIBRARY_PREFIX}expat${CMAKE_STATIC_LIBRARY_SUFFIX}" +- DESTINATION lib) +-endif() +- +-set(EXPAT_INCLUDE_DIRS ${CMAKE_BINARY_DIR}/ExpatEx/install/include) +- -include_directories("${EXPAT_INCLUDE_DIRS}" "${FMILIB_THIRDPARTYLIBS}/FMI/" "${FMIXMLGENDIR}/FMI1" "${FMIXMLGENDIR}/FMI2") -+endif() +find_package(expat CONFIG REQUIRED) +include_directories("${FMILIB_THIRDPARTYLIBS}/FMI/" "${FMIXMLGENDIR}/FMI1" "${FMIXMLGENDIR}/FMI2") PREFIXLIST(FMIXMLSOURCE ${FMIXMLDIR}/) PREFIXLIST(FMIXMLHEADERS ${FMIXMLDIR}/) -@@ -232,6 +235,6 @@ if(MSVC) +@@ -232,6 +157,6 @@ if(MSVC) target_compile_definitions(fmixml PUBLIC XML_STATIC) endif() diff --git a/recipes/fmilib/all/patches/2.4.1-009-make-project-pure-c.patch b/recipes/fmilib/all/patches/2.4.1-009-make-project-pure-c.patch new file mode 100644 index 0000000000000..670becc04576f --- /dev/null +++ b/recipes/fmilib/all/patches/2.4.1-009-make-project-pure-c.patch @@ -0,0 +1,39 @@ +From dcf9863528e64edcad83ff0f9242b94b14df1705 Mon Sep 17 00:00:00 2001 +From: Joakim Haugen +Date: Wed, 8 Nov 2023 12:59:01 +0100 +Subject: [PATCH] Make project pure C + +--- + CMakeLists.txt | 2 +- + Config.cmake/test_fmi2.cmake | 2 +- + 2 files changed, 2 insertions(+), 2 deletions(-) + +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 56ca3ee..01cf54d 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -20,7 +20,7 @@ cmake_minimum_required (VERSION 2.8.6 FATAL_ERROR) + IF("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}") + message(FATAL_ERROR "In-source build is not supported. Please, use an empty directory for building the project.") + ENDIF() +-project (FMILibrary) ++project (FMILibrary LANGUAGES C) + set_property(GLOBAL PROPERTY PROPERTYPREDEFINED_TARGETS_FOLDER Global) + set(FMILIBRARYHOME ${FMILibrary_SOURCE_DIR}) + set(FMILIBRARYBUILD ${FMILibrary_BINARY_DIR}) +diff --git a/Config.cmake/test_fmi2.cmake b/Config.cmake/test_fmi2.cmake +index 2885d4e..e9b49e6 100644 +--- a/Config.cmake/test_fmi2.cmake ++++ b/Config.cmake/test_fmi2.cmake +@@ -81,7 +81,7 @@ if(FMILIB_TEST_LOCALE) + target_compile_definitions(fmi2_xml_parsing_test PRIVATE -DFMILIB_TEST_LOCALE) + endif() + +-add_executable (fmi2_import_xml_test ${RTTESTDIR}/FMI2/fmi2_import_xml_test.cc) ++add_executable (fmi2_import_xml_test ${RTTESTDIR}/FMI2/fmi2_import_xml_test.c) + target_link_libraries (fmi2_import_xml_test ${FMILIBFORTEST}) + add_executable (fmi2_import_me_test ${RTTESTDIR}/FMI2/fmi2_import_me_test.c) + target_link_libraries (fmi2_import_me_test ${FMILIBFORTEST}) +-- +2.30.2 + From d918a85a7261234dd1c80ad4dda4f13da9abd932 Mon Sep 17 00:00:00 2001 From: Joakim Haugen Date: Mon, 4 Dec 2023 11:22:41 +0100 Subject: [PATCH 12/17] Remove unneeded patch --- recipes/fmilib/all/conandata.yml | 3 -- recipes/fmilib/all/conanfile.py | 5 --- .../2.4.1-009-make-project-pure-c.patch | 39 ------------------- 3 files changed, 47 deletions(-) delete mode 100644 recipes/fmilib/all/patches/2.4.1-009-make-project-pure-c.patch diff --git a/recipes/fmilib/all/conandata.yml b/recipes/fmilib/all/conandata.yml index 03bd6d4b9b4a6..7578a53b54e64 100644 --- a/recipes/fmilib/all/conandata.yml +++ b/recipes/fmilib/all/conandata.yml @@ -31,6 +31,3 @@ patches: - patch_file: "patches/2.4.1-008-link-zlib-in-fmilib.patch" patch_description: "zlib must be linked explicitly due to minizip.c and miniunz.c inclusion" patch_type: "conan" - - patch_file: "patches/2.4.1-009-make-project-pure-c.patch" - patch_description: "Project is pure C when not compiling external dependencies" - patch_type: "conan" diff --git a/recipes/fmilib/all/conanfile.py b/recipes/fmilib/all/conanfile.py index 8f355515f6657..3476c6844331a 100644 --- a/recipes/fmilib/all/conanfile.py +++ b/recipes/fmilib/all/conanfile.py @@ -103,11 +103,6 @@ def generate(self): def build(self): apply_conandata_patches(self) - # Rename c++ suffix to c to avoid CMake's confusion - fmi2_folder = path.join(self.source_folder, "Test", "FMI2") - rename(self, path.join(fmi2_folder, "fmi2_import_xml_test.cc"), - path.join(fmi2_folder, "fmi2_import_xml_test.c")) - copy(self, "fmiModel*.h", self.dependencies["fmi1"].cpp_info.components["modex"].includedirs[0], path.join(self.build_folder, "fmis", "FMI1")) copy(self, "fmiPlatformTypes.h", self.dependencies["fmi1"].cpp_info.components["cosim"].includedirs[0], diff --git a/recipes/fmilib/all/patches/2.4.1-009-make-project-pure-c.patch b/recipes/fmilib/all/patches/2.4.1-009-make-project-pure-c.patch deleted file mode 100644 index 670becc04576f..0000000000000 --- a/recipes/fmilib/all/patches/2.4.1-009-make-project-pure-c.patch +++ /dev/null @@ -1,39 +0,0 @@ -From dcf9863528e64edcad83ff0f9242b94b14df1705 Mon Sep 17 00:00:00 2001 -From: Joakim Haugen -Date: Wed, 8 Nov 2023 12:59:01 +0100 -Subject: [PATCH] Make project pure C - ---- - CMakeLists.txt | 2 +- - Config.cmake/test_fmi2.cmake | 2 +- - 2 files changed, 2 insertions(+), 2 deletions(-) - -diff --git a/CMakeLists.txt b/CMakeLists.txt -index 56ca3ee..01cf54d 100644 ---- a/CMakeLists.txt -+++ b/CMakeLists.txt -@@ -20,7 +20,7 @@ cmake_minimum_required (VERSION 2.8.6 FATAL_ERROR) - IF("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}") - message(FATAL_ERROR "In-source build is not supported. Please, use an empty directory for building the project.") - ENDIF() --project (FMILibrary) -+project (FMILibrary LANGUAGES C) - set_property(GLOBAL PROPERTY PROPERTYPREDEFINED_TARGETS_FOLDER Global) - set(FMILIBRARYHOME ${FMILibrary_SOURCE_DIR}) - set(FMILIBRARYBUILD ${FMILibrary_BINARY_DIR}) -diff --git a/Config.cmake/test_fmi2.cmake b/Config.cmake/test_fmi2.cmake -index 2885d4e..e9b49e6 100644 ---- a/Config.cmake/test_fmi2.cmake -+++ b/Config.cmake/test_fmi2.cmake -@@ -81,7 +81,7 @@ if(FMILIB_TEST_LOCALE) - target_compile_definitions(fmi2_xml_parsing_test PRIVATE -DFMILIB_TEST_LOCALE) - endif() - --add_executable (fmi2_import_xml_test ${RTTESTDIR}/FMI2/fmi2_import_xml_test.cc) -+add_executable (fmi2_import_xml_test ${RTTESTDIR}/FMI2/fmi2_import_xml_test.c) - target_link_libraries (fmi2_import_xml_test ${FMILIBFORTEST}) - add_executable (fmi2_import_me_test ${RTTESTDIR}/FMI2/fmi2_import_me_test.c) - target_link_libraries (fmi2_import_me_test ${FMILIBFORTEST}) --- -2.30.2 - From 0a602198d40cc5d2de1c5b36f687ac8153e1532e Mon Sep 17 00:00:00 2001 From: Joakim Haugen Date: Thu, 7 Dec 2023 15:52:53 +0100 Subject: [PATCH 13/17] Combine two patches working on same issue and file --- recipes/fmilib/all/conandata.yml | 3 -- ...1-002-add-minizip-tools-as-functions.patch | 6 ++-- .../2.4.1-003-use-expat-from-conan.patch | 6 ++-- ...-004-use-minizip-and-zlib-from-conan.patch | 17 +++++------ ...005-ensure-conan-friendly-cmakelists.patch | 6 ++-- .../2.4.1-006-link-external-targets.patch | 6 ++-- ...4.1-007-add-missing-stdlib.h-include.patch | 6 ++-- .../2.4.1-008-link-zlib-in-fmilib.patch | 28 ------------------- 8 files changed, 24 insertions(+), 54 deletions(-) delete mode 100644 recipes/fmilib/all/patches/2.4.1-008-link-zlib-in-fmilib.patch diff --git a/recipes/fmilib/all/conandata.yml b/recipes/fmilib/all/conandata.yml index 7578a53b54e64..3d742017fb100 100644 --- a/recipes/fmilib/all/conandata.yml +++ b/recipes/fmilib/all/conandata.yml @@ -28,6 +28,3 @@ patches: patch_description: "exit() is defined in stdlib.h" patch_type: "bugfix" patch_source: "https://github.com/modelon-community/fmi-library/issues/95" - - patch_file: "patches/2.4.1-008-link-zlib-in-fmilib.patch" - patch_description: "zlib must be linked explicitly due to minizip.c and miniunz.c inclusion" - patch_type: "conan" diff --git a/recipes/fmilib/all/patches/2.4.1-002-add-minizip-tools-as-functions.patch b/recipes/fmilib/all/patches/2.4.1-002-add-minizip-tools-as-functions.patch index 3177371f59953..e858d7131f46e 100644 --- a/recipes/fmilib/all/patches/2.4.1-002-add-minizip-tools-as-functions.patch +++ b/recipes/fmilib/all/patches/2.4.1-002-add-minizip-tools-as-functions.patch @@ -1,7 +1,7 @@ -From ebe6fc7a2d4ef78b2e421c8fa23a30d28079319b Mon Sep 17 00:00:00 2001 +From 150530fed42e0193f0ccac73971bdce2d277b368 Mon Sep 17 00:00:00 2001 From: Joakim Haugen -Date: Wed, 24 May 2023 15:27:49 +0200 -Subject: [PATCH] Add minizip tools as functions +Date: Thu, 7 Dec 2023 15:42:49 +0100 +Subject: [PATCH 1/6] add minizip tools as functions --- src/ZIP/include/miniunz.h | 11 + diff --git a/recipes/fmilib/all/patches/2.4.1-003-use-expat-from-conan.patch b/recipes/fmilib/all/patches/2.4.1-003-use-expat-from-conan.patch index 2daee074a055f..054b820d74595 100644 --- a/recipes/fmilib/all/patches/2.4.1-003-use-expat-from-conan.patch +++ b/recipes/fmilib/all/patches/2.4.1-003-use-expat-from-conan.patch @@ -1,7 +1,7 @@ -From c19a6b34a9f406e17da642f30e2507a5cc6b1519 Mon Sep 17 00:00:00 2001 +From e35f4b274bf51228e3928491d7205350a0593280 Mon Sep 17 00:00:00 2001 From: Joakim Haugen -Date: Wed, 8 Nov 2023 12:16:23 +0100 -Subject: [PATCH] Do not add expat as external project +Date: Thu, 7 Dec 2023 15:43:28 +0100 +Subject: [PATCH 2/6] use expat from conan --- Config.cmake/fmixml.cmake | 81 ++------------------------------------- diff --git a/recipes/fmilib/all/patches/2.4.1-004-use-minizip-and-zlib-from-conan.patch b/recipes/fmilib/all/patches/2.4.1-004-use-minizip-and-zlib-from-conan.patch index ef76b6103b52e..05a8c569790d3 100644 --- a/recipes/fmilib/all/patches/2.4.1-004-use-minizip-and-zlib-from-conan.patch +++ b/recipes/fmilib/all/patches/2.4.1-004-use-minizip-and-zlib-from-conan.patch @@ -1,17 +1,17 @@ -From 3195c7ee77f40cde7231357e6f6e8cf247fc3452 Mon Sep 17 00:00:00 2001 +From e006938706d06379f899edbe3fc8fe2367fec1f6 Mon Sep 17 00:00:00 2001 From: Joakim Haugen -Date: Wed, 24 May 2023 16:26:15 +0200 -Subject: [PATCH 2/3] Use minizip and zlib from conan +Date: Thu, 7 Dec 2023 15:44:54 +0100 +Subject: [PATCH 3/6] use minizip and zlib from conan --- - Config.cmake/fmizip.cmake | 16 ++++++++++------ - 1 file changed, 10 insertions(+), 6 deletions(-) + Config.cmake/fmizip.cmake | 17 +++++++++++------ + 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Config.cmake/fmizip.cmake b/Config.cmake/fmizip.cmake -index 091fc4d..7618d51 100644 +index 091fc4d..213b5f8 100644 --- a/Config.cmake/fmizip.cmake +++ b/Config.cmake/fmizip.cmake -@@ -19,28 +19,32 @@ if(NOT FMIZIPDIR) +@@ -19,28 +19,33 @@ if(NOT FMIZIPDIR) # set(DOXYFILE_EXTRA_SOURCES "${DOXYFILE_EXTRA_SOURCES} \"${FMIZIPDIR}/include\"") set(FMIZIP_LIBRARIES fmizip) @@ -43,11 +43,12 @@ index 091fc4d..7618d51 100644 -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DZLIB_STATIC") +find_package(minizip CONFIG REQUIRED) ++find_package(ZLIB CONFIG REQUIRED) add_library(fmizip ${FMILIBKIND} ${FMIZIPSOURCE} ${FMIZIPHEADERS}) -target_link_libraries(fmizip minizip jmutils) -+target_link_libraries(fmizip minizip::minizip jmutils) ++target_link_libraries(fmizip minizip::minizip ZLIB::ZLIB jmutils) endif(NOT FMIZIPDIR) -- diff --git a/recipes/fmilib/all/patches/2.4.1-005-ensure-conan-friendly-cmakelists.patch b/recipes/fmilib/all/patches/2.4.1-005-ensure-conan-friendly-cmakelists.patch index 42a41f5049e61..5aceb3534d9ab 100644 --- a/recipes/fmilib/all/patches/2.4.1-005-ensure-conan-friendly-cmakelists.patch +++ b/recipes/fmilib/all/patches/2.4.1-005-ensure-conan-friendly-cmakelists.patch @@ -1,7 +1,7 @@ -From dc7777f1212cc64c46a12cfd55ab76276a77ac56 Mon Sep 17 00:00:00 2001 +From 698a0134e382e3f82d8ae3f06cbbeb3ad7fc9873 Mon Sep 17 00:00:00 2001 From: Joakim Haugen -Date: Wed, 24 May 2023 16:28:20 +0200 -Subject: [PATCH 3/3] Ensure conan friendly cmakelists +Date: Thu, 7 Dec 2023 15:45:38 +0100 +Subject: [PATCH 4/6] ensure conan friendly cmakelists --- CMakeLists.txt | 4 ++-- diff --git a/recipes/fmilib/all/patches/2.4.1-006-link-external-targets.patch b/recipes/fmilib/all/patches/2.4.1-006-link-external-targets.patch index 3c95d27adba6f..c28f79b5fc92f 100644 --- a/recipes/fmilib/all/patches/2.4.1-006-link-external-targets.patch +++ b/recipes/fmilib/all/patches/2.4.1-006-link-external-targets.patch @@ -1,7 +1,7 @@ -From df411a1782a608cbfdc46c9ecafb0a4faae0151f Mon Sep 17 00:00:00 2001 +From 306cb206e8a62c82e6cb66e6c2e545980e1a2546 Mon Sep 17 00:00:00 2001 From: Joakim Haugen -Date: Wed, 24 May 2023 16:46:58 +0200 -Subject: [PATCH] Debug testing +Date: Thu, 7 Dec 2023 15:46:12 +0100 +Subject: [PATCH 5/6] link external targets --- Config.cmake/runtime_test.cmake | 8 ++++---- diff --git a/recipes/fmilib/all/patches/2.4.1-007-add-missing-stdlib.h-include.patch b/recipes/fmilib/all/patches/2.4.1-007-add-missing-stdlib.h-include.patch index 17bc90b16df93..8d8ce9b7910c1 100644 --- a/recipes/fmilib/all/patches/2.4.1-007-add-missing-stdlib.h-include.patch +++ b/recipes/fmilib/all/patches/2.4.1-007-add-missing-stdlib.h-include.patch @@ -1,7 +1,7 @@ -From 79a37f7a6173f8bdd3324a0442ab377bcb6f238a Mon Sep 17 00:00:00 2001 +From af5133fa4eba5c9eb8338bb4284383183d1ef3cd Mon Sep 17 00:00:00 2001 From: Joakim Haugen -Date: Wed, 25 Oct 2023 13:56:43 +0200 -Subject: [PATCH] Add missing stdlib.h include for exit +Date: Thu, 7 Dec 2023 15:46:39 +0100 +Subject: [PATCH 6/6] add missing stdlib.h include --- Test/jm_locale_test.c | 1 + diff --git a/recipes/fmilib/all/patches/2.4.1-008-link-zlib-in-fmilib.patch b/recipes/fmilib/all/patches/2.4.1-008-link-zlib-in-fmilib.patch deleted file mode 100644 index e26991de02048..0000000000000 --- a/recipes/fmilib/all/patches/2.4.1-008-link-zlib-in-fmilib.patch +++ /dev/null @@ -1,28 +0,0 @@ -From 9478e541f41e7c9df0fb37a459c093e41848ae2e Mon Sep 17 00:00:00 2001 -From: Joakim Haugen -Date: Mon, 30 Oct 2023 10:11:24 +0100 -Subject: [PATCH] Link zlib in a test - ---- - Config.cmake/fmizip.cmake | 3 ++- - 1 file changed, 2 insertions(+), 1 deletion(-) - -diff --git a/Config.cmake/fmizip.cmake b/Config.cmake/fmizip.cmake -index 7618d51..213b5f8 100644 ---- a/Config.cmake/fmizip.cmake -+++ b/Config.cmake/fmizip.cmake -@@ -42,9 +42,10 @@ set(FMIZIPHEADERS - #include_directories("${FMILIB_THIRDPARTYLIBS}/zlib/lib/VS2005/win32") - - find_package(minizip CONFIG REQUIRED) -+find_package(ZLIB CONFIG REQUIRED) - - add_library(fmizip ${FMILIBKIND} ${FMIZIPSOURCE} ${FMIZIPHEADERS}) - --target_link_libraries(fmizip minizip::minizip jmutils) -+target_link_libraries(fmizip minizip::minizip ZLIB::ZLIB jmutils) - - endif(NOT FMIZIPDIR) --- -2.30.2 - From 20705511cbf468ae29bba39049dfc42f2e0a161c Mon Sep 17 00:00:00 2001 From: Joakim Haugen Date: Thu, 7 Dec 2023 15:55:15 +0100 Subject: [PATCH 14/17] Let `with_fmus` option be False by default --- recipes/fmilib/all/conanfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/fmilib/all/conanfile.py b/recipes/fmilib/all/conanfile.py index 3476c6844331a..458c197cc2fa0 100644 --- a/recipes/fmilib/all/conanfile.py +++ b/recipes/fmilib/all/conanfile.py @@ -32,7 +32,7 @@ class PackageConan(ConanFile): default_options = { "shared": False, "fPIC": True, - "with_fmus": True + "with_fmus": False } def export_sources(self): From 90bb8b370bea4296e18d48a18d167d8f2ed0c8bd Mon Sep 17 00:00:00 2001 From: Joakim Haugen Date: Wed, 19 Jun 2024 13:26:17 +0200 Subject: [PATCH 15/17] Address review comments - Simplify patches - Download minizip sources instead of patch - Write replace in file for a few minizip versions, 1.2.13 and 1.3.1 - Use CMakeDeps cmake_target_property instead of patching dependency target names --- recipes/fmilib/all/conanfile.py | 55 +- ...1-002-add-minizip-tools-as-functions.patch | 1217 +---------------- .../2.4.1-003-use-expat-from-conan.patch | 112 +- ...-004-use-minizip-and-zlib-from-conan.patch | 13 +- .../2.4.1-006-link-external-targets.patch | 8 +- 5 files changed, 78 insertions(+), 1327 deletions(-) diff --git a/recipes/fmilib/all/conanfile.py b/recipes/fmilib/all/conanfile.py index 458c197cc2fa0..b1d2d4fff86b2 100644 --- a/recipes/fmilib/all/conanfile.py +++ b/recipes/fmilib/all/conanfile.py @@ -6,7 +6,7 @@ from conan.tools.microsoft import is_msvc_static_runtime, is_msvc from conan.tools.files import ( apply_conandata_patches, export_conandata_patches, - get, copy, rename, rm, rmdir + get, copy, rename, rm, rmdir, replace_in_file ) from conan.tools.scm import Version from conan.tools.env import VirtualRunEnv @@ -57,9 +57,9 @@ def requirements(self): self.requires("fmi2/2.0.4") if self.version >= Version("3.0a2"): self.requires("fmi3/3.0.1") - self.requires("expat/2.5.0") - self.requires("minizip/1.2.13") - self.requires("zlib/[>=1.2.11 <2]") + self.requires("expat/2.6.2") + self.requires("minizip/[>1.2.13 <=1.3.1]") + self.requires("zlib/[>=1.2.13 <2]") # c99_snprintf -> should be externalised def validate(self): @@ -91,17 +91,62 @@ def generate(self): tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0026"] = "OLD" tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0045"] = "OLD" tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0046"] = "OLD" + tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0077"] = "NEW" tc.generate() cd = CMakeDeps(self) + cd.set_property("expat", "cmake_target_name", "expat") + cd.set_property("minizip", "cmake_target_name", "minizip") cd.generate() + # This is needed if with_fmus=True vre = VirtualRunEnv(self) vre.generate(scope="build") - def build(self): + minizip_code = { + "1.3.1": + { + "url": "https://zlib.net/fossils/zlib-1.3.1.tar.gz", + "sha256": "9a93b2b7dfdac77ceba5a558a580e74667dd6fede4585b91eefb60f03b72df23" + }, + "1.2.13": + { + "url": "https://zlib.net/fossils/zlib-1.2.13.tar.gz", + "sha256": "b3a24de97a8fdbc835b9833169501030b8977031bcb54b3b3ac13740f846ab30" + } + } + get(self, + **minizip_code[str(self.dependencies["minizip"].ref.version)], + pattern="*/minizip/*", + strip_root=True, destination=path.join(self.build_folder)) + minizip_src = path.join(self.build_folder, "contrib", "minizip") + minizip_dest = path.join(self.source_folder, "src", "ZIP", "src") + copy(self, "minizip.c", minizip_src, minizip_dest) + copy(self, "miniunz.c", minizip_src, minizip_dest) + + def _patch_sources(self): apply_conandata_patches(self) + minizip = path.join(self.source_folder, "src", "ZIP", "src", "minizip.c") + miniunz = path.join(self.source_folder, "src", "ZIP", "src", "miniunz.c") + replace_in_file(self, minizip, "printf", "minizip_printf") + replace_in_file(self, minizip, "// In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions", "") + replace_in_file(self, minizip, "// base filename follows last slash.", "") + replace_in_file(self, miniunz, "printf", "minizip_printf") + replace_in_file(self, minizip, '#include "zip.h"', + '#include "zip.h"\n static int minizip_printf( const char * format, ... ){ return 1; }') + replace_in_file(self, miniunz, '#include "unzip.h"', + '#include "unzip.h"\n static int minizip_printf( const char * format, ... ){ return 1; }') + + if Version(self.dependencies["minizip"].ref.version) < Version("1.3.0"): + replace_in_file(self, minizip, "main(argc,argv)", "minizip(argc, argv)") + replace_in_file(self, miniunz, "main(argc,argv)", "miniunz(argc, argv)") + else: + replace_in_file(self, minizip, "main(int argc", "minizip(int argc") + replace_in_file(self, miniunz, "main(int argc", "miniunz(int argc") + + def build(self): + self._patch_sources() copy(self, "fmiModel*.h", self.dependencies["fmi1"].cpp_info.components["modex"].includedirs[0], path.join(self.build_folder, "fmis", "FMI1")) diff --git a/recipes/fmilib/all/patches/2.4.1-002-add-minizip-tools-as-functions.patch b/recipes/fmilib/all/patches/2.4.1-002-add-minizip-tools-as-functions.patch index e858d7131f46e..688ca2bf8c98a 100644 --- a/recipes/fmilib/all/patches/2.4.1-002-add-minizip-tools-as-functions.patch +++ b/recipes/fmilib/all/patches/2.4.1-002-add-minizip-tools-as-functions.patch @@ -6,13 +6,9 @@ Subject: [PATCH 1/6] add minizip tools as functions --- src/ZIP/include/miniunz.h | 11 + src/ZIP/include/minizip.h | 12 + - src/ZIP/src/miniunz.c | 670 ++++++++++++++++++++++++++++++++++++++ - src/ZIP/src/minizip.c | 529 ++++++++++++++++++++++++++++++ - 4 files changed, 1222 insertions(+) + 2 files changed, 23 insertions(+) create mode 100644 src/ZIP/include/miniunz.h create mode 100644 src/ZIP/include/minizip.h - create mode 100644 src/ZIP/src/miniunz.c - create mode 100644 src/ZIP/src/minizip.c diff --git a/src/ZIP/include/miniunz.h b/src/ZIP/include/miniunz.h new file mode 100644 @@ -49,1217 +45,6 @@ index 0000000..767dbde +} +#endif +#endif /* End of header file MINIZIP_H */ -diff --git a/src/ZIP/src/miniunz.c b/src/ZIP/src/miniunz.c -new file mode 100644 -index 0000000..7a73f6a ---- /dev/null -+++ b/src/ZIP/src/miniunz.c -@@ -0,0 +1,670 @@ -+/* -+ miniunz.c -+ Version 1.1, February 14h, 2010 -+ sample part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) -+ -+ Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) -+ -+ Modifications of Unzip for Zip64 -+ Copyright (C) 2007-2008 Even Rouault -+ -+ Modifications for Zip64 support on both zip and unzip -+ Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) -+*/ -+ -+#if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__)) -+ #ifndef __USE_FILE_OFFSET64 -+ #define __USE_FILE_OFFSET64 -+ #endif -+ #ifndef __USE_LARGEFILE64 -+ #define __USE_LARGEFILE64 -+ #endif -+ #ifndef _LARGEFILE64_SOURCE -+ #define _LARGEFILE64_SOURCE -+ #endif -+ #ifndef _FILE_OFFSET_BIT -+ #define _FILE_OFFSET_BIT 64 -+ #endif -+#endif -+ -+#ifdef __APPLE__ -+// In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions -+#define FOPEN_FUNC(filename, mode) fopen(filename, mode) -+#define FTELLO_FUNC(stream) ftello(stream) -+#define FSEEKO_FUNC(stream, offset, origin) fseeko(stream, offset, origin) -+#else -+#define FOPEN_FUNC(filename, mode) fopen64(filename, mode) -+#define FTELLO_FUNC(stream) ftello64(stream) -+#define FSEEKO_FUNC(stream, offset, origin) fseeko64(stream, offset, origin) -+#endif -+ -+ -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+ -+#ifdef _WIN32 -+# include -+# include -+#else -+# include -+# include -+#include -+#include -+#endif -+ -+ -+#include "unzip.h" -+ -+#define CASESENSITIVITY (0) -+#define WRITEBUFFERSIZE (8192) -+#define MAXFILENAME (256) -+ -+#ifdef _WIN32 -+#define USEWIN32IOAPI -+#include "iowin32.h" -+#endif -+ -+/* MODIFICATION Replace all stdout prints with this function for better control */ -+static int minizip_printf( const char * format, ... ) -+{ -+ return 1; -+} -+ -+/* -+ mini unzip, demo of unzip package -+ -+ usage : -+ Usage : miniunz [-exvlo] file.zip [file_to_extract] [-d extractdir] -+ -+ list the file in the zipfile, and print the content of FILE_ID.ZIP or README.TXT -+ if it exists -+*/ -+ -+ -+/* change_file_date : change the date/time of a file -+ filename : the filename of the file where date/time must be modified -+ dosdate : the new date at the MSDos format (4 bytes) -+ tmu_date : the SAME new date at the tm_unz format */ -+void change_file_date(filename,dosdate,tmu_date) -+ const char *filename; -+ uLong dosdate; -+ tm_unz tmu_date; -+{ -+#ifdef _WIN32 -+ HANDLE hFile; -+ FILETIME ftm,ftLocal,ftCreate,ftLastAcc,ftLastWrite; -+ -+ hFile = CreateFileA(filename,GENERIC_READ | GENERIC_WRITE, -+ 0,NULL,OPEN_EXISTING,0,NULL); -+ GetFileTime(hFile,&ftCreate,&ftLastAcc,&ftLastWrite); -+ DosDateTimeToFileTime((WORD)(dosdate>>16),(WORD)dosdate,&ftLocal); -+ LocalFileTimeToFileTime(&ftLocal,&ftm); -+ SetFileTime(hFile,&ftm,&ftLastAcc,&ftm); -+ CloseHandle(hFile); -+#else -+#if defined(__unix) || defined(__APPLE__) -+ (void)dosdate; -+ struct utimbuf ut; -+ struct tm newdate; -+ newdate.tm_sec = tmu_date.tm_sec; -+ newdate.tm_min=tmu_date.tm_min; -+ newdate.tm_hour=tmu_date.tm_hour; -+ newdate.tm_mday=tmu_date.tm_mday; -+ newdate.tm_mon=tmu_date.tm_mon; -+ if (tmu_date.tm_year > 1900) -+ newdate.tm_year=tmu_date.tm_year - 1900; -+ else -+ newdate.tm_year=tmu_date.tm_year ; -+ newdate.tm_isdst=-1; -+ -+ ut.actime=ut.modtime=mktime(&newdate); -+ utime(filename,&ut); -+#endif -+#endif -+} -+ -+ -+/* mymkdir and change_file_date are not 100 % portable -+ As I don't know well Unix, I wait feedback for the unix portion */ -+ -+int mymkdir(dirname) -+ const char* dirname; -+{ -+ int ret=0; -+#ifdef _WIN32 -+ ret = _mkdir(dirname); -+#elif __unix -+ ret = mkdir (dirname,0775); -+#elif __APPLE__ -+ ret = mkdir (dirname,0775); -+#else -+#error Unknown platform -+#endif -+ return ret; -+} -+ -+int makedir (newdir) -+ char *newdir; -+{ -+ char *buffer ; -+ char *p; -+ size_t len = strlen(newdir); -+ -+ if (len == 0) -+ return 0; -+ -+ buffer = (char*)malloc(len+1); -+ if (buffer==NULL) -+ { -+ minizip_printf("Error allocating memory\n"); -+ return UNZ_INTERNALERROR; -+ } -+ strcpy(buffer,newdir); -+ -+ if (buffer[len-1] == '/') { -+ buffer[len-1] = '\0'; -+ } -+ if (mymkdir(buffer) == 0) -+ { -+ free(buffer); -+ return 1; -+ } -+ -+ p = buffer+1; -+ while (1) -+ { -+ char hold; -+ -+ while(*p && *p != '\\' && *p != '/') -+ p++; -+ hold = *p; -+ *p = 0; -+ if ((mymkdir(buffer) == -1) && (errno == ENOENT)) -+ { -+ minizip_printf("couldn't create directory %s\n",buffer); -+ free(buffer); -+ return 0; -+ } -+ if (hold == 0) -+ break; -+ *p++ = hold; -+ } -+ free(buffer); -+ return 1; -+} -+ -+static void do_banner() -+{ -+ /*printf("MiniUnz 1.01b, demo of zLib + Unz package written by Gilles Vollant\n"); -+ printf("more info at http://www.winimage.com/zLibDll/unzip.html\n\n");*/ -+} -+ -+static void do_help() -+{ -+ printf("Usage : miniunz [-e] [-x] [-v] [-l] [-o] [-p password] file.zip [file_to_extr.] [-d extractdir]\n\n" \ -+ " -e Extract without pathname (junk paths)\n" \ -+ " -x Extract with pathname\n" \ -+ " -v list files\n" \ -+ " -l list files\n" \ -+ " -d directory to extract into\n" \ -+ " -o overwrite files without prompting\n" \ -+ " -p extract crypted file using password\n\n"); -+} -+ -+static void Display64BitsSize(ZPOS64_T n, int size_char) -+{ -+ /* to avoid compatibility problem , we do here the conversion */ -+ char number[21]; -+ int offset=19; -+ int pos_string = 19; -+ number[20]=0; -+ for (;;) { -+ number[offset]=(char)((n%10)+'0'); -+ if (number[offset] != '0') -+ pos_string=offset; -+ n/=10; -+ if (offset==0) -+ break; -+ offset--; -+ } -+ { -+ int size_display_string = 19-pos_string; -+ while (size_char > size_display_string) -+ { -+ size_char--; -+ minizip_printf(" "); -+ } -+ } -+ -+ minizip_printf("%s",&number[pos_string]); -+} -+ -+static int do_list(uf) -+ unzFile uf; -+{ -+ uLong i; -+ unz_global_info64 gi; -+ int err; -+ -+ err = unzGetGlobalInfo64(uf,&gi); -+ if (err!=UNZ_OK) -+ minizip_printf("error %d with zipfile in unzGetGlobalInfo \n",err); -+ minizip_printf(" Length Method Size Ratio Date Time CRC-32 Name\n"); -+ minizip_printf(" ------ ------ ---- ----- ---- ---- ------ ----\n"); -+ for (i=0;i0) -+ ratio = (uLong)((file_info.compressed_size*100)/file_info.uncompressed_size); -+ -+ /* display a '*' if the file is crypted */ -+ if ((file_info.flag & 1) != 0) -+ charCrypt='*'; -+ -+ if (file_info.compression_method==0) -+ string_method="Stored"; -+ else -+ if (file_info.compression_method==Z_DEFLATED) -+ { -+ uInt iLevel=(uInt)((file_info.flag & 0x6)/2); -+ if (iLevel==0) -+ string_method="Defl:N"; -+ else if (iLevel==1) -+ string_method="Defl:X"; -+ else if ((iLevel==2) || (iLevel==3)) -+ string_method="Defl:F"; /* 2:fast , 3 : extra fast*/ -+ } -+ else -+ if (file_info.compression_method==Z_BZIP2ED) -+ { -+ string_method="BZip2 "; -+ } -+ else -+ string_method="Unkn. "; -+ -+ Display64BitsSize(file_info.uncompressed_size,7); -+ minizip_printf(" %6s%c",string_method,charCrypt); -+ Display64BitsSize(file_info.compressed_size,7); -+ minizip_printf(" %3lu%% %2.2lu-%2.2lu-%2.2lu %2.2lu:%2.2lu %8.8lx %s\n", -+ ratio, -+ (uLong)file_info.tmu_date.tm_mon + 1, -+ (uLong)file_info.tmu_date.tm_mday, -+ (uLong)file_info.tmu_date.tm_year % 100, -+ (uLong)file_info.tmu_date.tm_hour,(uLong)file_info.tmu_date.tm_min, -+ (uLong)file_info.crc,filename_inzip); -+ if ((i+1)='a') && (rep<='z')) -+ rep -= 0x20; -+ } -+ while ((rep!='Y') && (rep!='N') && (rep!='A')); -+ } -+ -+ if (rep == 'N') -+ skip = 1; -+ -+ if (rep == 'A') -+ *popt_overwrite=1; -+ } -+ -+ if ((skip==0) && (err==UNZ_OK)) -+ { -+ fout=FOPEN_FUNC(write_filename,"wb"); -+ /* some zipfile don't contain directory alone before file */ -+ if ((fout==NULL) && ((*popt_extract_without_path)==0) && -+ (filename_withoutpath!=(char*)filename_inzip)) -+ { -+ char c=*(filename_withoutpath-1); -+ *(filename_withoutpath-1)='\0'; -+ makedir(write_filename); -+ *(filename_withoutpath-1)=c; -+ fout=FOPEN_FUNC(write_filename,"wb"); -+ } -+ -+ if (fout==NULL) -+ { -+ minizip_printf("error opening %s\n",write_filename); -+ } -+ } -+ -+ if (fout!=NULL) -+ { -+ minizip_printf(" extracting: %s\n",write_filename); -+ -+ do -+ { -+ err = unzReadCurrentFile(uf,buf,size_buf); -+ if (err<0) -+ { -+ minizip_printf("error %d with zipfile in unzReadCurrentFile\n",err); -+ break; -+ } -+ if (err>0) -+ if (fwrite(buf,(unsigned)err,1,fout)!=1) -+ { -+ minizip_printf("error in writing extracted file\n"); -+ err=UNZ_ERRNO; -+ break; -+ } -+ } -+ while (err>0); -+ if (fout) -+ fclose(fout); -+ -+ if (err==0) -+ change_file_date(write_filename,file_info.dosDate, -+ file_info.tmu_date); -+ } -+ -+ if (err==UNZ_OK) -+ { -+ err = unzCloseCurrentFile (uf); -+ if (err!=UNZ_OK) -+ { -+ minizip_printf("error %d with zipfile in unzCloseCurrentFile\n",err); -+ } -+ } -+ else -+ unzCloseCurrentFile(uf); /* don't lose the error */ -+ } -+ -+ free(buf); -+ return err; -+} -+ -+ -+int do_extract(uf,opt_extract_without_path,opt_overwrite,password) -+ unzFile uf; -+ int opt_extract_without_path; -+ int opt_overwrite; -+ const char* password; -+{ -+ uLong i; -+ unz_global_info64 gi; -+ int err; -+ -+ err = unzGetGlobalInfo64(uf,&gi); -+ if (err!=UNZ_OK) -+ minizip_printf("error %d with zipfile in unzGetGlobalInfo \n",err); -+ -+ for (i=0;i -+#include -+#include -+#include -+#include -+#include -+ -+#ifdef _WIN32 -+# include -+# include -+#else -+# include -+# include -+# include -+# include -+#endif -+ -+#include "zip.h" -+ -+#ifdef _WIN32 -+ #define USEWIN32IOAPI -+ #include "iowin32.h" -+#endif -+ -+ -+ -+#define WRITEBUFFERSIZE (16384) -+#define MAXFILENAME (256) -+ -+/* MODIFICATION Replace all stdout prints with this function for better control */ -+static int minizip_printf( const char * format, ... ) -+{ -+ return 1; -+} -+ -+#ifdef _WIN32 -+int filetime(f, tmzip, dt) -+ const char *f; /* name of file to get info on */ -+ tm_zip *tmzip; /* return value: access, modific. and creation times */ -+ uLong *dt; /* dostime */ -+{ -+ int ret = 0; -+ { -+ FILETIME ftLocal; -+ HANDLE hFind; -+ WIN32_FIND_DATAA ff32; -+ -+ hFind = FindFirstFileA(f,&ff32); -+ if (hFind != INVALID_HANDLE_VALUE) -+ { -+ FileTimeToLocalFileTime(&(ff32.ftLastWriteTime),&ftLocal); -+ FileTimeToDosDateTime(&ftLocal,((LPWORD)dt)+1,((LPWORD)dt)+0); -+ FindClose(hFind); -+ ret = 1; -+ } -+ } -+ return ret; -+} -+#else -+#if defined(__unix) || defined(__APPLE__) -+int filetime(f, tmzip, dt) -+ const char *f; /* name of file to get info on */ -+ tm_zip *tmzip; /* return value: access, modific. and creation times */ -+ uLong *dt; /* dostime */ -+{ -+ (void)dt; -+ int ret=0; -+ struct stat s; /* results of stat() */ -+ struct tm* filedate; -+ time_t tm_t=0; -+ -+ if (strcmp(f,"-")!=0) -+ { -+ char name[MAXFILENAME+1]; -+ size_t len = strlen(f); -+ if (len > MAXFILENAME) -+ len = MAXFILENAME; -+ -+ strncpy(name, f,MAXFILENAME-1); -+ /* strncpy doesnt append the trailing NULL, of the string is too long. */ -+ name[ MAXFILENAME ] = '\0'; -+ -+ if (name[len - 1] == '/') -+ name[len - 1] = '\0'; -+ /* not all systems allow stat'ing a file with / appended */ -+ if (stat(name,&s)==0) -+ { -+ tm_t = s.st_mtime; -+ ret = 1; -+ } -+ } -+ filedate = localtime(&tm_t); -+ -+ tmzip->tm_sec = filedate->tm_sec; -+ tmzip->tm_min = filedate->tm_min; -+ tmzip->tm_hour = filedate->tm_hour; -+ tmzip->tm_mday = filedate->tm_mday; -+ tmzip->tm_mon = filedate->tm_mon ; -+ tmzip->tm_year = filedate->tm_year; -+ -+ return ret; -+} -+#else -+uLong filetime(f, tmzip, dt) -+ const char *f; /* name of file to get info on */ -+ tm_zip *tmzip; /* return value: access, modific. and creation times */ -+ uLong *dt; /* dostime */ -+{ -+ return 0; -+} -+#endif -+#endif -+ -+ -+ -+ -+static int check_exist_file(filename) -+ const char* filename; -+{ -+ FILE* ftestexist; -+ int ret = 1; -+ ftestexist = FOPEN_FUNC(filename,"rb"); -+ if (ftestexist==NULL) -+ ret = 0; -+ else -+ fclose(ftestexist); -+ return ret; -+} -+ -+static void do_banner() -+{ -+ /* -+ minizip_printf("MiniZip 1.1, demo of zLib + MiniZip64 package, written by Gilles Vollant\n"); -+ minizip_printf("more info on MiniZip at http://www.winimage.com/zLibDll/minizip.html\n\n"); -+ */ -+} -+ -+static void do_help() -+{ -+ minizip_printf("Usage : minizip [-o] [-a] [-0 to -9] [-p password] [-j] file.zip [files_to_add]\n\n" \ -+ " -o Overwrite existing file.zip\n" \ -+ " -a Append to existing file.zip\n" \ -+ " -0 Store only\n" \ -+ " -1 Compress faster\n" \ -+ " -9 Compress better\n\n" \ -+ " -j exclude path. store only the file name.\n\n"); -+} -+ -+/* calculate the CRC32 of a file, -+ because to encrypt a file, we need known the CRC32 of the file before */ -+int getFileCrc(const char* filenameinzip,void*buf,unsigned long size_buf,unsigned long* result_crc) -+{ -+ unsigned long calculate_crc=0; -+ int err=ZIP_OK; -+ FILE * fin = FOPEN_FUNC(filenameinzip,"rb"); -+ -+ unsigned long size_read = 0; -+ /* unsigned long total_read = 0; */ -+ if (fin==NULL) -+ { -+ err = ZIP_ERRNO; -+ } -+ -+ if (err == ZIP_OK) -+ do -+ { -+ err = ZIP_OK; -+ size_read = fread(buf,1,size_buf,fin); -+ if (size_read < size_buf) -+ if (feof(fin)==0) -+ { -+ minizip_printf("error in reading %s\n",filenameinzip); -+ err = ZIP_ERRNO; -+ } -+ -+ if (size_read>0) -+ calculate_crc = crc32_z(calculate_crc,buf,size_read); -+ /* total_read += size_read; */ -+ -+ } while ((err == ZIP_OK) && (size_read>0)); -+ -+ if (fin) -+ fclose(fin); -+ -+ *result_crc=calculate_crc; -+ minizip_printf("file %s crc %lx\n", filenameinzip, calculate_crc); -+ return err; -+} -+ -+int isLargeFile(const char* filename) -+{ -+ int largeFile = 0; -+ ZPOS64_T pos = 0; -+ FILE* pFile = FOPEN_FUNC(filename, "rb"); -+ -+ if(pFile != NULL) -+ { -+ FSEEKO_FUNC(pFile, 0, SEEK_END); -+ pos = (ZPOS64_T)FTELLO_FUNC(pFile); -+ -+ minizip_printf("File : %s is %lld bytes\n", filename, pos); -+ -+ if(pos >= 0xffffffff) -+ largeFile = 1; -+ -+ fclose(pFile); -+ } -+ -+ return largeFile; -+} -+ -+int minizip(argc,argv) -+ int argc; -+ char *argv[]; -+{ -+ int i; -+ int opt_overwrite=0; -+ int opt_compress_level=Z_DEFAULT_COMPRESSION; -+ int opt_exclude_path=0; -+ int zipfilenamearg = 0; -+ char filename_try[MAXFILENAME+16]; -+ int zipok; -+ int err=0; -+ size_t size_buf=0; -+ void* buf=NULL; -+ const char* password=NULL; -+ -+ -+ do_banner(); -+ if (argc==1) -+ { -+ do_help(); -+ return 0; -+ } -+ else -+ { -+ for (i=1;i='0') && (c<='9')) -+ opt_compress_level = c-'0'; -+ if ((c=='j') || (c=='J')) -+ opt_exclude_path = 1; -+ -+ if (((c=='p') || (c=='P')) && (i+1='a') && (rep<='z')) -+ rep -= 0x20; -+ } -+ while ((rep!='Y') && (rep!='N') && (rep!='A')); -+ if (rep=='N') -+ zipok = 0; -+ if (rep=='A') -+ opt_overwrite = 2; -+ } -+ } -+ -+ if (zipok==1) -+ { -+ zipFile zf; -+ int errclose; -+# ifdef USEWIN32IOAPI -+ zlib_filefunc64_def ffunc; -+ fill_win32_filefunc64A(&ffunc); -+ zf = zipOpen2_64(filename_try,(opt_overwrite==2) ? 2 : 0,NULL,&ffunc); -+# else -+ zf = zipOpen64(filename_try,(opt_overwrite==2) ? 2 : 0); -+# endif -+ -+ if (zf == NULL) -+ { -+ minizip_printf("error opening %s\n",filename_try); -+ err= ZIP_ERRNO; -+ } -+ else -+ minizip_printf("creating %s\n",filename_try); -+ -+ for (i=zipfilenamearg+1;(i='0') || (argv[i][1]<='9'))) && -+ (strlen(argv[i]) == 2))) -+ { -+ FILE * fin; -+ size_t size_read; -+ const char* filenameinzip = argv[i]; -+ const char *savefilenameinzip; -+ zip_fileinfo zi; -+ unsigned long crcFile=0; -+ int zip64 = 0; -+ -+ zi.tmz_date.tm_sec = zi.tmz_date.tm_min = zi.tmz_date.tm_hour = -+ zi.tmz_date.tm_mday = zi.tmz_date.tm_mon = zi.tmz_date.tm_year = 0; -+ zi.dosDate = 0; -+ zi.internal_fa = 0; -+ zi.external_fa = 0; -+ filetime(filenameinzip,&zi.tmz_date,&zi.dosDate); -+ -+/* -+ err = zipOpenNewFileInZip(zf,filenameinzip,&zi, -+ NULL,0,NULL,0,NULL / * comment * /, -+ (opt_compress_level != 0) ? Z_DEFLATED : 0, -+ opt_compress_level); -+*/ -+ if ((password != NULL) && (err==ZIP_OK)) -+ err = getFileCrc(filenameinzip,buf,size_buf,&crcFile); -+ -+ zip64 = isLargeFile(filenameinzip); -+ -+ /* The path name saved, should not include a leading slash. */ -+ /*if it did, windows/xp and dynazip couldn't read the zip file. */ -+ savefilenameinzip = filenameinzip; -+ while( savefilenameinzip[0] == '\\' || savefilenameinzip[0] == '/' ) -+ { -+ savefilenameinzip++; -+ } -+ -+ /*should the zip file contain any path at all?*/ -+ if( opt_exclude_path ) -+ { -+ const char *tmpptr; -+ const char *lastslash = 0; -+ for( tmpptr = savefilenameinzip; *tmpptr; tmpptr++) -+ { -+ if( *tmpptr == '\\' || *tmpptr == '/') -+ { -+ lastslash = tmpptr; -+ } -+ } -+ if( lastslash != NULL ) -+ { -+ savefilenameinzip = lastslash+1; /* base filename follows last slash. */ -+ } -+ } -+ -+ /**/ -+ err = zipOpenNewFileInZip3_64(zf,savefilenameinzip,&zi, -+ NULL,0,NULL,0,NULL /* comment*/, -+ (opt_compress_level != 0) ? Z_DEFLATED : 0, -+ opt_compress_level,0, -+ /* -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, */ -+ -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, -+ password,crcFile, zip64); -+ -+ if (err != ZIP_OK) -+ minizip_printf("error in opening %s in zipfile\n",filenameinzip); -+ else -+ { -+ fin = FOPEN_FUNC(filenameinzip,"rb"); -+ if (fin==NULL) -+ { -+ err=ZIP_ERRNO; -+ minizip_printf("error in opening %s for reading\n",filenameinzip); -+ } -+ } -+ -+ if (err == ZIP_OK) -+ do -+ { -+ err = ZIP_OK; -+ size_read = fread(buf,1,size_buf,fin); -+ if (size_read < size_buf) -+ if (feof(fin)==0) -+ { -+ minizip_printf("error in reading %s\n",filenameinzip); -+ err = ZIP_ERRNO; -+ } -+ -+ if (size_read>0) -+ { -+ err = zipWriteInFileInZip (zf,buf,(unsigned)size_read); -+ if (err<0) -+ { -+ minizip_printf("error in writing %s in the zipfile\n", -+ filenameinzip); -+ } -+ -+ } -+ } while ((err == ZIP_OK) && (size_read>0)); -+ -+ if (fin) -+ fclose(fin); -+ -+ if (err<0) -+ err=ZIP_ERRNO; -+ else -+ { -+ err = zipCloseFileInZip(zf); -+ if (err!=ZIP_OK) -+ minizip_printf("error in closing %s in the zipfile\n", -+ filenameinzip); -+ } -+ } -+ } -+ errclose = zipClose(zf,NULL); -+ if (errclose != ZIP_OK) -+ minizip_printf("error in closing %s\n",filename_try); -+ } -+ else -+ { -+ do_help(); -+ } -+ -+ free(buf); -+ return 0; -+} -- 2.30.2 diff --git a/recipes/fmilib/all/patches/2.4.1-003-use-expat-from-conan.patch b/recipes/fmilib/all/patches/2.4.1-003-use-expat-from-conan.patch index 054b820d74595..f8bd979c5a82d 100644 --- a/recipes/fmilib/all/patches/2.4.1-003-use-expat-from-conan.patch +++ b/recipes/fmilib/all/patches/2.4.1-003-use-expat-from-conan.patch @@ -1,110 +1,34 @@ -From e35f4b274bf51228e3928491d7205350a0593280 Mon Sep 17 00:00:00 2001 +From 4f28a90cce17e37bfd93ffc647f8ce6d5578d07c Mon Sep 17 00:00:00 2001 From: Joakim Haugen -Date: Thu, 7 Dec 2023 15:43:28 +0100 -Subject: [PATCH 2/6] use expat from conan +Date: Wed, 19 Jun 2024 14:11:41 +0200 +Subject: [PATCH] Expat --- - Config.cmake/fmixml.cmake | 81 ++------------------------------------- - 1 file changed, 3 insertions(+), 78 deletions(-) + Config.cmake/fmixml.cmake | 4 ++++ + 1 file changed, 4 insertions(+) diff --git a/Config.cmake/fmixml.cmake b/Config.cmake/fmixml.cmake -index ddd3c1f..7aa7ffa 100644 +index ddd3c1f..e59135c 100644 --- a/Config.cmake/fmixml.cmake +++ b/Config.cmake/fmixml.cmake -@@ -137,83 +137,8 @@ set(FMIXMLSOURCE +@@ -137,6 +137,7 @@ set(FMIXMLSOURCE src/FMI2/fmi2_xml_variable.c ) --include(ExternalProject) -- --# The *_POSTFIX variables are set because it makes it easier to determine the name of --# the lib expat will produce at configure time. Note that Expat has some special handling --# for it for MSVC which this in effect negates. https://github.com/libexpat/libexpat/pull/316 --set(EXPAT_SETTINGS -- -DEXPAT_BUILD_TOOLS:BOOLEAN=OFF -- -DEXPAT_BUILD_EXAMPLES:BOOLEAN=OFF -- -DEXPAT_BUILD_TESTS:BOOLEAN=OFF -- -DEXPAT_SHARED_LIBS:BOOLEAN=OFF -- -DEXPAT_DTD:BOOLEAN=OFF -- -DEXPAT_NS:BOOLEAN=OFF -- -DEXPAT_MSVC_STATIC_CRT:BOOLEAN=${FMILIB_BUILD_WITH_STATIC_RTLIB} -- -DCMAKE_DEBUG_POSTFIX:STRING= -- -DCMAKE_RELEASE_POSTFIX:STRING= -- -DCMAKE_MINSIZEREL_POSTFIX:STRING= -- -DCMAKE_RELWITHDEBINFO_POSTFIX:STRING= -- -DCMAKE_POSITION_INDEPENDENT_CODE:BOOLEAN=ON -- -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} -- -DCMAKE_EXE_LINKER_FLAGS:STRING=${CMAKE_EXE_LINKER_FLAGS} -- -DCMAKE_LINK_LIBRARY_FLAG:STRING=${CMAKE_LINK_LIBRARY_FLAG} -- -DCMAKE_MODULE_LINKER_FLAGS:STRING=${CMAKE_MODULE_LINKER_FLAGS} -- -DCMAKE_SHARED_LINKER_FLAGS:STRING=${CMAKE_SHARED_LINKER_FLAGS} -- -DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_BINARY_DIR}/ExpatEx/install --) -- --ExternalProject_Add( -- expatex -- PREFIX "${FMIXML_EXPAT_DIR}" -- SOURCE_DIR "${FMIXML_EXPAT_DIR}" -- CMAKE_CACHE_ARGS ${EXPAT_SETTINGS} -- BINARY_DIR ${CMAKE_BINARY_DIR}/ExpatEx -- INSTALL_DIR ${CMAKE_BINARY_DIR}/ExpatEx/install -- TMP_DIR ${CMAKE_BINARY_DIR}/ExpatEx/tmp -- STAMP_DIR ${CMAKE_BINARY_DIR}/ExpatEx/stamp --) -- --ExternalProject_Add_Step( -- expatex dependent_reconfigure -- DEPENDEES configure -- DEPENDERS build -- COMMAND ${CMAKE_COMMAND} -E echo "Running: ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" ${EXPAT_SETTINGS} ${FMIXML_EXPAT_DIR}" -- COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" ${EXPAT_SETTINGS} "${FMIXML_EXPAT_DIR}" -- DEPENDS ${CMAKE_BINARY_DIR}/CMakeCache.txt -- WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/ExpatEx --) -- --add_dependencies(expatex ${CMAKE_BINARY_DIR}/CMakeCache.txt ${FMILIBRARYHOME}/CMakeLists.txt) -- -- --if(MSVC) -- # Expat uses special naming with MSVC, which is mirrored here. -- set(EXPAT_LIB_PREFIX lib) --else() -- set(EXPAT_LIB_PREFIX ${CMAKE_STATIC_LIBRARY_PREFIX}) --endif() -- --set(expatlib "${CMAKE_BINARY_DIR}/ExpatEx/${CMAKE_CFG_INTDIR}/${EXPAT_LIB_PREFIX}expat${CMAKE_STATIC_LIBRARY_SUFFIX}") -- --add_library(expat STATIC IMPORTED) -- --set_target_properties( -- expat PROPERTIES -- IMPORTED_LOCATION "${expatlib}" --) -- --add_dependencies(expat expatex) -- --if(FMILIB_INSTALL_SUBLIBS) -- install(FILES -- "${CMAKE_BINARY_DIR}/ExpatEx/install/lib/${CMAKE_STATIC_LIBRARY_PREFIX}expat${CMAKE_STATIC_LIBRARY_SUFFIX}" -- DESTINATION lib) --endif() -- --set(EXPAT_INCLUDE_DIRS ${CMAKE_BINARY_DIR}/ExpatEx/install/include) -- --include_directories("${EXPAT_INCLUDE_DIRS}" "${FMILIB_THIRDPARTYLIBS}/FMI/" "${FMIXMLGENDIR}/FMI1" "${FMIXMLGENDIR}/FMI2") -+find_package(expat CONFIG REQUIRED) ++if(FALSE) + include(ExternalProject) + + # The *_POSTFIX variables are set because it makes it easier to determine the name of +@@ -214,6 +215,9 @@ endif() + set(EXPAT_INCLUDE_DIRS ${CMAKE_BINARY_DIR}/ExpatEx/install/include) + + include_directories("${EXPAT_INCLUDE_DIRS}" "${FMILIB_THIRDPARTYLIBS}/FMI/" "${FMIXMLGENDIR}/FMI1" "${FMIXMLGENDIR}/FMI2") ++endif() ++find_package(expat REQUIRED) +include_directories("${FMILIB_THIRDPARTYLIBS}/FMI/" "${FMIXMLGENDIR}/FMI1" "${FMIXMLGENDIR}/FMI2") PREFIXLIST(FMIXMLSOURCE ${FMIXMLDIR}/) PREFIXLIST(FMIXMLHEADERS ${FMIXMLDIR}/) -@@ -232,6 +157,6 @@ if(MSVC) - target_compile_definitions(fmixml PUBLIC XML_STATIC) - endif() - --target_link_libraries(fmixml ${JMUTIL_LIBRARIES} expat) -+target_link_libraries(fmixml ${JMUTIL_LIBRARIES} expat::expat) - - endif(NOT FMIXMLDIR) -- -2.30.2 +2.39.2 diff --git a/recipes/fmilib/all/patches/2.4.1-004-use-minizip-and-zlib-from-conan.patch b/recipes/fmilib/all/patches/2.4.1-004-use-minizip-and-zlib-from-conan.patch index 05a8c569790d3..923166d5be665 100644 --- a/recipes/fmilib/all/patches/2.4.1-004-use-minizip-and-zlib-from-conan.patch +++ b/recipes/fmilib/all/patches/2.4.1-004-use-minizip-and-zlib-from-conan.patch @@ -5,13 +5,13 @@ Subject: [PATCH 3/6] use minizip and zlib from conan --- Config.cmake/fmizip.cmake | 17 +++++++++++------ - 1 file changed, 11 insertions(+), 6 deletions(-) + 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Config.cmake/fmizip.cmake b/Config.cmake/fmizip.cmake index 091fc4d..213b5f8 100644 --- a/Config.cmake/fmizip.cmake +++ b/Config.cmake/fmizip.cmake -@@ -19,28 +19,33 @@ if(NOT FMIZIPDIR) +@@ -19,28 +19,30 @@ if(NOT FMIZIPDIR) # set(DOXYFILE_EXTRA_SOURCES "${DOXYFILE_EXTRA_SOURCES} \"${FMIZIPDIR}/include\"") set(FMIZIP_LIBRARIES fmizip) @@ -19,9 +19,6 @@ index 091fc4d..213b5f8 100644 - add_subdirectory(Config.cmake/Minizip) - - include_directories("${FMIZIPDIR}/include" "${FMILIB_THIRDPARTYLIBS}/Minizip/minizip" "${FMILIB_THIRDPARTYLIBS}/FMI" "${FMILIB_THIRDPARTYLIBS}/Zlib/zlib-1.2.6" "${FMILibrary_BINARY_DIR}/zlib") -+ -+ #add_subdirectory(Config.cmake/Minizip) -+ + include_directories("${FMIZIPDIR}/include" "${FMILIB_THIRDPARTYLIBS}/FMI") set(FMIZIPSOURCE @@ -42,13 +39,13 @@ index 091fc4d..213b5f8 100644 #include_directories("${FMILIB_THIRDPARTYLIBS}/zlib/lib/VS2005/win32") -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DZLIB_STATIC") -+find_package(minizip CONFIG REQUIRED) -+find_package(ZLIB CONFIG REQUIRED) ++find_package(minizip REQUIRED) ++find_package(ZLIB REQUIRED) add_library(fmizip ${FMILIBKIND} ${FMIZIPSOURCE} ${FMIZIPHEADERS}) -target_link_libraries(fmizip minizip jmutils) -+target_link_libraries(fmizip minizip::minizip ZLIB::ZLIB jmutils) ++target_link_libraries(fmizip minizip ZLIB::ZLIB jmutils) endif(NOT FMIZIPDIR) -- diff --git a/recipes/fmilib/all/patches/2.4.1-006-link-external-targets.patch b/recipes/fmilib/all/patches/2.4.1-006-link-external-targets.patch index c28f79b5fc92f..116d32b47eb79 100644 --- a/recipes/fmilib/all/patches/2.4.1-006-link-external-targets.patch +++ b/recipes/fmilib/all/patches/2.4.1-006-link-external-targets.patch @@ -16,7 +16,7 @@ index d61137f..0765268 100644 #Create function that zipz the dummy FMUs add_executable (compress_test_fmu_zip ${RTTESTDIR}/compress_test_fmu_zip.c) -target_link_libraries (compress_test_fmu_zip ${FMIZIP_LIBRARIES}) -+target_link_libraries (compress_test_fmu_zip ${FMIZIP_LIBRARIES} minizip::minizip) ++target_link_libraries (compress_test_fmu_zip ${FMIZIP_LIBRARIES} minizip) set_target_properties( jm_vector_test jm_locale_test compress_test_fmu_zip @@ -25,7 +25,7 @@ index d61137f..0765268 100644 endfunction(compress_fmu) -set(FMILIBFORTEST fmilib) -+set(FMILIBFORTEST fmilib minizip::minizip expat::expat) ++set(FMILIBFORTEST fmilib minizip expat) if(FMILIB_BUILD_SHARED_LIB AND (FMILIB_LINK_TEST_TO_SHAREDLIB OR NOT FMILIB_BUILD_STATIC_LIB)) set(FMILIBFORTEST fmilib_shared) @@ -34,11 +34,11 @@ index d61137f..0765268 100644 add_executable (fmi_zip_zip_test ${RTTESTDIR}/FMI1/fmi_zip_zip_test.c ) -target_link_libraries (fmi_zip_zip_test ${FMIZIP_LIBRARIES}) -+target_link_libraries (fmi_zip_zip_test ${FMIZIP_LIBRARIES} minizip::minizip) ++target_link_libraries (fmi_zip_zip_test ${FMIZIP_LIBRARIES} minizip) add_executable (fmi_zip_unzip_test ${RTTESTDIR}/FMI1/fmi_zip_unzip_test.c ) -target_link_libraries (fmi_zip_unzip_test ${FMIZIP_LIBRARIES}) -+target_link_libraries (fmi_zip_unzip_test ${FMIZIP_LIBRARIES} minizip::minizip) ++target_link_libraries (fmi_zip_unzip_test ${FMIZIP_LIBRARIES} minizip) add_executable (fmi_import_test ${RTTESTDIR}/fmi_import_test.c From e06684216e9de23fef5438228be7090c062c1ae8 Mon Sep 17 00:00:00 2001 From: Joakim Haugen Date: Thu, 20 Jun 2024 09:12:45 +0200 Subject: [PATCH 16/17] Remove unused import --- recipes/fmilib/all/conanfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/fmilib/all/conanfile.py b/recipes/fmilib/all/conanfile.py index b1d2d4fff86b2..f602ab896cfe5 100644 --- a/recipes/fmilib/all/conanfile.py +++ b/recipes/fmilib/all/conanfile.py @@ -6,7 +6,7 @@ from conan.tools.microsoft import is_msvc_static_runtime, is_msvc from conan.tools.files import ( apply_conandata_patches, export_conandata_patches, - get, copy, rename, rm, rmdir, replace_in_file + get, copy, rm, rmdir, replace_in_file ) from conan.tools.scm import Version from conan.tools.env import VirtualRunEnv From ad6a4bb2f343e088f11072250ca2e14450f2cf9d Mon Sep 17 00:00:00 2001 From: Joakim Haugen Date: Sun, 23 Jun 2024 09:55:27 +0200 Subject: [PATCH 17/17] Address review comments - Fetch minizip source info from conan_data - Copy fmi headers into source folder rather than build folder --- recipes/fmilib/all/conanfile.py | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/recipes/fmilib/all/conanfile.py b/recipes/fmilib/all/conanfile.py index f602ab896cfe5..c39ef7d8b0ed5 100644 --- a/recipes/fmilib/all/conanfile.py +++ b/recipes/fmilib/all/conanfile.py @@ -58,7 +58,7 @@ def requirements(self): if self.version >= Version("3.0a2"): self.requires("fmi3/3.0.1") self.requires("expat/2.6.2") - self.requires("minizip/[>1.2.13 <=1.3.1]") + self.requires("minizip/[>1.2.13 <2]") self.requires("zlib/[>=1.2.13 <2]") # c99_snprintf -> should be externalised @@ -78,7 +78,7 @@ def generate(self): tc.variables["FMILIB_BUILD_STATIC_LIB"] = not self.options.shared tc.variables["FMILIB_BUILD_SHARED_LIB"] = self.options.shared tc.variables["FMILIB_BUILD_TESTS"] = self.options.with_fmus - tc.variables["FMILIB_FMI_STANDARD_HEADERS"] = posixpath.join(self.build_folder, "fmis").replace("\\", "/") + tc.variables["FMILIB_FMI_STANDARD_HEADERS"] = posixpath.join(self.source_folder, "src", "fmis").replace("\\", "/") tc.variables["FMILIB_GENERATE_DOXYGEN_DOC"] = False # The variable is an option only if the following condition is true @@ -104,20 +104,9 @@ def generate(self): vre = VirtualRunEnv(self) vre.generate(scope="build") - minizip_code = { - "1.3.1": - { - "url": "https://zlib.net/fossils/zlib-1.3.1.tar.gz", - "sha256": "9a93b2b7dfdac77ceba5a558a580e74667dd6fede4585b91eefb60f03b72df23" - }, - "1.2.13": - { - "url": "https://zlib.net/fossils/zlib-1.2.13.tar.gz", - "sha256": "b3a24de97a8fdbc835b9833169501030b8977031bcb54b3b3ac13740f846ab30" - } - } + minizip_version = str(self.dependencies["minizip"].ref.version) get(self, - **minizip_code[str(self.dependencies["minizip"].ref.version)], + **self.dependencies["minizip"].conan_data["sources"][minizip_version], pattern="*/minizip/*", strip_root=True, destination=path.join(self.build_folder)) minizip_src = path.join(self.build_folder, "contrib", "minizip") @@ -149,13 +138,13 @@ def build(self): self._patch_sources() copy(self, "fmiModel*.h", self.dependencies["fmi1"].cpp_info.components["modex"].includedirs[0], - path.join(self.build_folder, "fmis", "FMI1")) + path.join(self.source_folder, "src", "fmis", "FMI1")) copy(self, "fmiPlatformTypes.h", self.dependencies["fmi1"].cpp_info.components["cosim"].includedirs[0], - path.join(self.build_folder, "fmis", "FMI1")) + path.join(self.source_folder, "src", "fmis", "FMI1")) copy(self, "fmiFunctions.h", self.dependencies["fmi1"].cpp_info.components["cosim"].includedirs[0], - path.join(self.build_folder, "fmis", "FMI1")) + path.join(self.source_folder, "src", "fmis", "FMI1")) copy(self, "*.h", self.dependencies["fmi2"].cpp_info.includedirs[0], - path.join(self.build_folder, "fmis", "FMI2")) + path.join(self.source_folder, "src", "fmis", "FMI2")) cmake = CMake(self) cmake.configure()