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 15 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
36 changes: 36 additions & 0 deletions recipes/fmilib/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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"
- 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"
157 changes: 157 additions & 0 deletions recipes/fmilib/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
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, 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

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": 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.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.5.0")
self.requires("minizip/1.2.13")
self.requires("zlib/[>=1.2.11 <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.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)

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

cd = CMakeDeps(self)
cd.generate()

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.


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],
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"))
Copy link
Member

Choose a reason for hiding this comment

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

Any insights into why these folders can not to out of source for the build?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is no reason. I moved them to the source folder instead.


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

Loading