Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fmilib: add recipe for version 2.4.1 #20256

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
91c1f83
fmilibrary: add recipe for version 2.4.1
joakimono Oct 2, 2023
8e69985
Remove alpha version remnants
joakimono Oct 2, 2023
fe5739c
Merge branch 'master' into fmilibrary/new-package
joakimono Oct 3, 2023
eed1b95
Add missing include and reviewer suggestion
joakimono Oct 25, 2023
6f8fd9c
Merge branch 'master' into fmilibrary/new-package
joakimono Oct 30, 2023
bfc74d2
fmilibrary does not support armv8 Macos yet
joakimono Oct 30, 2023
0ef2f16
Make zlib a direct dependency
joakimono Oct 30, 2023
1cf10e7
Fix shared build windows
joakimono Oct 30, 2023
8b3f0f5
Fix post package warnings
joakimono Oct 30, 2023
ed70246
Apply suggestions from code review
joakimono Oct 31, 2023
c3255d7
Move fmi copy to build and bump expat to 2.5.0
joakimono Oct 31, 2023
a616a6d
Address reviewer suggestions
joakimono Nov 8, 2023
94483e4
enforce that fmilib is pure C
joakimono Nov 8, 2023
e3b9ce9
Merge branch 'master' into fmilibrary/new-package
joakimono Nov 10, 2023
517dd95
Merge branch 'master' into fmilibrary/new-package
joakimono Nov 27, 2023
d918a85
Remove unneeded patch
joakimono Dec 4, 2023
0a60219
Combine two patches working on same issue and file
joakimono Dec 7, 2023
2070551
Let `with_fmus` option be False by default
joakimono Dec 7, 2023
b30ae79
Merge branch 'master' into fmilibrary/new-package
joakimono Dec 18, 2023
36f1153
Merge branch 'master' into fmilibrary/new-package
joakimono Jan 8, 2024
808db31
Merge branch 'master' into fmilibrary/new-package
joakimono Jan 18, 2024
b7f639b
Merge branch 'conan-io:master' into fmilibrary/new-package
joakimono Jun 19, 2024
90bb8b3
Address review comments
joakimono Jun 19, 2024
e066842
Remove unused import
joakimono Jun 20, 2024
ad6a4bb
Address review comments
joakimono Jun 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions recipes/fmilib/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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-add-missing-stdlib.h-include.patch"
patch_description: "exit() is defined in stdlib.h"
patch_type: "bugfix"
patch_source: "https://github.com/modelon-community/fmi-library/issues/95"
186 changes: 186 additions & 0 deletions recipes/fmilib/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
from os import path
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, rm, rmdir, replace_in_file
)
from conan.tools.scm import Version
from conan.tools.env import VirtualRunEnv
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout

required_conan_version = ">=1.53.0"


class PackageConan(ConanFile):
name = "fmilib"
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": False
}

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.settings.rm_safe("compiler.libcxx")
self.settings.rm_safe("compiler.cppstd")

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.6.2")
self.requires("minizip/[>1.2.13 <2]")
self.requires("zlib/[>=1.2.13 <2]")
# c99_snprintf -> should be externalised

def validate(self):
# 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}")

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):

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.source_folder, "src", "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)

tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0026"] = "OLD"
tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0045"] = "OLD"
tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0046"] = "OLD"
joakimono marked this conversation as resolved.
Show resolved Hide resolved
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")
Comment on lines +104 to +105
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is normally not required for CMake projects. What is the purpose of it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is need when option with_fmu=True. Then, during the build process some executables need runtime access to what can be found in the virtual run environment.


minizip_version = str(self.dependencies["minizip"].ref.version)
get(self,
**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")
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.source_folder, "src", "fmis", "FMI1"))
copy(self, "fmiPlatformTypes.h", self.dependencies["fmi1"].cpp_info.components["cosim"].includedirs[0],
path.join(self.source_folder, "src", "fmis", "FMI1"))
copy(self, "fmiFunctions.h", self.dependencies["fmi1"].cpp_info.components["cosim"].includedirs[0],
path.join(self.source_folder, "src", "fmis", "FMI1"))
copy(self, "*.h", self.dependencies["fmi2"].cpp_info.includedirs[0],
path.join(self.source_folder, "src", "fmis", "FMI2"))

cmake = CMake(self)
cmake.configure()
cmake.build()

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()

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"))

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"]
self.cpp_info.set_property("cmake_target_aliases", ["fmilibrary::fmilibrary"])
25 changes: 25 additions & 0 deletions recipes/fmilib/all/patches/2.4.1-001-static-c99snprintf.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
From e4ad54090e455289ac23a45867b17c8dca88e704 Mon Sep 17 00:00:00 2001
From: Joakim Haugen <[email protected]>
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

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
From 150530fed42e0193f0ccac73971bdce2d277b368 Mon Sep 17 00:00:00 2001
From: Joakim Haugen <[email protected]>
Date: Thu, 7 Dec 2023 15:42:49 +0100
Subject: [PATCH 1/6] add minizip tools as functions

---
src/ZIP/include/miniunz.h | 11 +
src/ZIP/include/minizip.h | 12 +
2 files changed, 23 insertions(+)
create mode 100644 src/ZIP/include/miniunz.h
create mode 100644 src/ZIP/include/minizip.h

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 */
--
2.30.2

34 changes: 34 additions & 0 deletions recipes/fmilib/all/patches/2.4.1-003-use-expat-from-conan.patch
joakimono marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
From 4f28a90cce17e37bfd93ffc647f8ce6d5578d07c Mon Sep 17 00:00:00 2001
From: Joakim Haugen <[email protected]>
Date: Wed, 19 Jun 2024 14:11:41 +0200
Subject: [PATCH] Expat

---
Config.cmake/fmixml.cmake | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/Config.cmake/fmixml.cmake b/Config.cmake/fmixml.cmake
index ddd3c1f..e59135c 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
@@ -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}/)
--
2.39.2

Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
From e006938706d06379f899edbe3fc8fe2367fec1f6 Mon Sep 17 00:00:00 2001
From: Joakim Haugen <[email protected]>
Date: Thu, 7 Dec 2023 15:44:54 +0100
Subject: [PATCH 3/6] use minizip and zlib from conan

---
Config.cmake/fmizip.cmake | 17 +++++++++++------
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,30 @@ 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")
+ 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
Comment on lines +27 to +36
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replacing the third party by Conan makes sense, but why do you need to add these files now? Is it something broken in the upstream?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The third party minizip source that fmilib uses are modified so that minizip and miniunz are functions rather than executables. This makes it necessary to add both the source and header files, which have modified function signatures (main -> mini{zip,unz})

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, if you are including those files, the minizip library is still required?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, because minizip.c includes zip.h, and miniunz.c includes unzip.h; those files are provided by minizip.

uilianries marked this conversation as resolved.
Show resolved Hide resolved
)

#include_directories("${FMILIB_THIRDPARTYLIBS}/zlib/lib/VS2005/win32")

-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DZLIB_STATIC")
+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 ZLIB::ZLIB jmutils)

endif(NOT FMIZIPDIR)
--
2.30.2

Loading
Loading