grackle-project / grackle

The Grackle chemistry and cooling library for astrophysical simulations and models.
Other
26 stars 50 forks source link

Cmake Build Part 2: have the install-process create metadata files #204

Closed mabruzzo closed 3 months ago

mabruzzo commented 5 months ago

This PR looks bigger than it actually is since it builds on #182. (The last 2 commits are the only ones that introduce changes).

This was split off from #182 because these changes are not strictly required to build Grackle with cmake. These changes exist to add support for installing metadata files that can be used to help downstream applications link against a grackle installation. There are 2 types of metadata files.

pkg-config file: grackle.pc

This file can be used by downstream projects build with any build system. The only requirement to use these files is having the pkg-config utility or pkgconf utility (an alternative implementation) installed. Both of these utilities are run at the command-line.

The downstream build can execute a number of useful commands:

CMake Package Config File: GrackleConfig.cmake

Downstream applications built with cmake (that don't want to directly embed the grackle build within their build) can make use of this file (plus a handful of related auto-generated files).

This basically conveys all the same information as the grackle.pc file, but has some theoretical advantages. In grackle's current form, these advantage don't matter much and this format is provided mostly as a convenience (it makes integration of grackle into a downstream cmake MUCH more seamless).

For posterity, the theoretical disadvantages of pkg-config (that cmake addresses) are:

Other thoughts

If we ultimately decide not to use cmake, it would probably make a lot of sense to rework most of this and try to work it into the existing build-system (with that said, I'm a little skeptical that we could get robust-generalized-solutions without significantly more work)

[^1]: Technically, there is very specific, rare edge-case right now related to use libgrackle.a compiled with OpenMP that could arise if we didn't use cmake to build the package-config file. Currently, we use CMake to identify the exact runtime-openmp libraries that need to be linked (so we can convert those requirements to -L and -l arguments). If we weren't using openmp, we would need to list the openmp compiler-specific flag in grackle.pc's linker arguments (so -fopenmp for gcc/clang or -qopenmp for intel, -qsmp=omp for ibm, -mp for pgi). If the downstream application didn't use openmp outside of grackle, problems would arise if they directly invoked ld for linking or uses a different compiler toolchain altogether. (If the downstream application did use openmp outside of grackle, this would be a non-issue). This would be extremely rare, and I'd be fine with it... But, this is mostly to provide a concrete example

mabruzzo commented 3 months ago

I decided to merge this with #182