Cantera / enhancements

Repository for proposed and ongoing enhancements to Cantera
11 stars 5 forks source link

Add cantera to conancenter #191

Open NelDav opened 7 months ago

NelDav commented 7 months ago

Abstract

Conan is a system developed to add dependencies to c++ applicaitons. It enables installation of the dependency and has a good integration with cmake.

Motivation

Providing an easy way to use cantera in your c++ applicaiton. Conan is used by many people to maintian their dependencies.

Description

In order to add cantera to conan, a reciepe has to be written, that descibes the build process. Cona will then use this reciepe to build cantera. The reciepe as well as the binaries can then be downloaded by every conan user.

Alternatives

An alternative is vcpkg. But we are not limitted to one solution here. It makes sense to add cantera to vcpkg and conancenter. But I do not know, hwo to add packages to vcpkg.

Question

Is it ok for you if I add cantera to conancenter?

speth commented 7 months ago

Thanks for writing this up, @NelDav. I was not previously familiar with ConanCenter, but I think packaging Cantera here could be beneficial if you're interested in working on it. Several of the other Cantera packages, such as for Gentoo, Fedora, and FreeBSD, are also community maintained.

If you haven't already looked at it, our recipe for conda-forge (here) might be of some use in structuring the recipe for Conan. If you have any questions as you're working on this, feel free to ask here!

NelDav commented 7 months ago

That is very nice. Thank you very much for the conda-forge recipe. I will check it.

NelDav commented 6 months ago

During the last few weeks, I made some progress, creating the conan package. However, I want to create a static version of cantera. From my perspective, a static version is only usefull, if all dependencies are static as well. Because of that, I am wondering if it is possible to link the static versions of fmt and yaml-cpp?

The documentation states the following:

This installation of fmt must include the shared version of the library, for example, libfmt.so.

NelDav commented 5 months ago

@speth, do you know a solution to statically link fmt and yaml-cpp?

speth commented 5 months ago

You can avoid needing the fmt library by using it in header-only mode, which can be done by defining FMT_HEADER_ONLY before any of the fmt includes. We avoid doing generally because it slows down compilation a bit.

For yaml-cpp, it looks like Conan provides a static variant of the library. The linker should use that as long as there isn't a shared version also installed. If both are installed, it's a little more complicated, and you have to add flags while linking that tell it which one to use. With the GNU linker, you basically need the linker command to contain -Wl,-Bstatic before -lyaml-cpp.

NelDav commented 5 months ago

Thanks for your answer. I think I made some mistakes before. That's why it didn't worked. However, your hint regarding FMT_HEADER_ONLY is very helpful. I will try that soon.

NelDav commented 5 months ago

Hi @speth, I have annother question. Probably, my bad knowledge about soncs is the problem. When performing a debug build with cantera, the linker still tries to link via -lfmt and -lyaml-cpp (see here: https://github.com/conan-io/conan-center-index/pull/21324#issuecomment-1892498007)

However, conan will also perform a debug build for the dependencies and will create libfmtd.so and libyaml-cppd.so. So, the linker need to link -lfmtd and -lyaml-cppd instead. But I haven't found any way to tell scons.

speth commented 5 months ago

There's nothing built into our SCons configuration to let you change the name of the libraries being linked to.

If you use FMT_HEADER_ONLY, it shouldn't be necessary to link to version of libfmt.so or libfmtd.so.

For yaml-cpp, you could make use of the option to compile it from the git submodule, in which case it should be compiled with the same compiler options as the rest of Cantera and bundled into the Cantera library file. You can do this by specifying the system_yamlcpp=n option when running scons build ....

NelDav commented 5 months ago

Thanks for your answer. You are right, using headers only will fix the problem for fmt. However, I do not realy understand how to define FMT_HEADER_ONLY during build. I cannot find any scons option to define it. Also, there is no option to set the content of env['CPPDEFINES']. For me it looks like I have to modify the SConstruct file to do so right?

I will ask at connancenter, if they have a solution for yaml-cpp. I cannot use the submodule, because the conancenter pipeline will not clone a repository but download an archive.

NelDav commented 5 months ago

I tried modifying the SConstruct file at different locations but still, the linker tries to link fmt.lib. I did following changes:

- env['CPPDEFINES'] = {}
+ env['CPPDEFINES'] = {'FMT_HEADER_ONLY': 1}
- extraEnvArgs = {}
+ extraEnvArgs = {'FMT_HEADER_ONLY': 1}

I am lost now. I look forward to your answer on how to do it right.

speth commented 5 months ago

Ah, I see the issue with fmt. If you are already applying patches to SConstruct, you could try the following to just link to libfmtd.so instead (and don't bother messing with the FMT_HEADER_ONLY define):

  if env["system_fmt"]:
-     env["external_libs"].append("fmt")
+     env["external_libs"].append("fmtd")
      # Usually need to link to fmt directly because of templated/inlined code that calls
      # fmt
-     env["cantera_shared_libs"].append("fmt")
+     env["cantera_shared_libs"].append("fmtd")

For yaml-cpp, I think you can likewise do:

  if env["system_yamlcpp"]:
-     env["external_libs"].append("yaml-cpp")
+     env["external_libs"].append("yaml-cppd")

Does this not also affect the other library dependencies, like SUNDIALS and HDF5?

NelDav commented 5 months ago

Yes, I already tried that. But unfortunately, the linker will not find certain functions. For now, I deactivated debug builds for the cantera conan package. Maybe we can implement them later.

Does this not also affect the other library dependencies, like SUNDIALS and HDF5?

Probably, but I haven't noticed any problems so far.