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

Add build dependency on fmtlib #1930

Merged
merged 2 commits into from
Sep 17, 2020
Merged

Add build dependency on fmtlib #1930

merged 2 commits into from
Sep 17, 2020

Conversation

joakim-hove
Copy link
Member

In C++20 the library fmtwhich replaces printf() and << based formatting - looks very good.

Before C++20 we can use the external library: https://github.com/fmtlib/fmt/ - which is essentially what was included for C++20.

For the ongoing work with improvements in error messages this would be extremely valuable, I therefor suggest that we use fmtlib until we switch to C++20.

This PR assumes that fmtlib is installed on your system (it is available as binary package on RH, Ubuntu & Debian) and integrates that in the build system - the cmake integration is quite naive and probably needs some love and attention from someone in the know.

opm-common-prereqs.cmake Outdated Show resolved Hide resolved
@alfbr
Copy link
Member

alfbr commented Sep 17, 2020

This is potentially very painful for us. Can you please elaborate how this is available in Red Hat (e.g., does it suffice to use a devtoolset when compilinng for Red Hat 6 and 7?).

@akva2
Copy link
Member

akva2 commented Sep 17, 2020

it's in epel.

@alfbr
Copy link
Member

alfbr commented Sep 17, 2020

it's in epel.

If it is installed from EPEL and linked dynamically, this quickly means we need it installed on everyting, not just build servers.

@akva2
Copy link
Member

akva2 commented Sep 17, 2020

fmt is a pure template library.

@alfbr
Copy link
Member

alfbr commented Sep 17, 2020

fmt is a pure template library.

Only a compile time dependency then? That makes it much less painful. It seems like it is available for both Red Hat 6 and 7 in EPEL. Sounds like it will be part of the GCC toolchain come C++20. If my understanding is correct, this is fine from my end.

@akva2
Copy link
Member

akva2 commented Sep 17, 2020

precisely.

@atgeirr
Copy link
Member

atgeirr commented Sep 17, 2020

If it is a header-only lib, why do we change the target_link_libraries() call?

@akva2
Copy link
Member

akva2 commented Sep 17, 2020

because it pulls in include paths from the fmt::fmt dependency.

@atgeirr
Copy link
Member

atgeirr commented Sep 17, 2020

I assumed target_link_libraries() only added LINK information. What you say seems to imply that it adds COMPILE information as well, is that correct?

@akva2
Copy link
Member

akva2 commented Sep 17, 2020

yes, fmt uses cmake targets, which is the "modern" way of doing cmake. these are cool because they carry all info. including include paths. the target_link_libraries call adds the include path as well. no need for separate _LIBRARES, _INCLUDE_DIRS etc variables any more.

@bska
Copy link
Member

bska commented Sep 17, 2020

fmt uses cmake targets, which is the "modern" way of doing cmake

True. If we ever decide to take the time to rework OPM's CMake-based build system, then targets and properties is the way to do it.

@atgeirr
Copy link
Member

atgeirr commented Sep 17, 2020

Thanks for the information. Now I am not against merging this, but I need one more piece of information: What do I need to do on a Ubuntu system to get this? I ask because we must update the build instructions on the website. (I assume brew install <something> is good enough on my mac.)

@akva2
Copy link
Member

akva2 commented Sep 17, 2020

apt install libfmt-dev

CMakeLists.txt Outdated
@@ -373,3 +373,5 @@ if (OPM_ENABLE_PYTHON)
add_definitions(-DEMBEDDED_PYTHON)
endif()
endif()

target_link_libraries(opmcommon PUBLIC fmt::fmt)
Copy link
Member

Choose a reason for hiding this comment

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

Looking at the documentation this line could arguably be

target_link_library(opmcommon PRIVATE fmt::fmt-header-only)

instead. The above appears to link to a precompiled (.a or .so) version of the fmt library.

Copy link
Member Author

@joakim-hove joakim-hove Sep 17, 2020

Choose a reason for hiding this comment

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

Tried that - did not get it to work - assume the cmake in the binary debian package does not support this target?

Copy link
Member

Choose a reason for hiding this comment

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

Tried that - did not get it to work.

In that case this (using fmt) may be more untenable. If we do indeed need a precompiled third-party library then it is a much more expensive proposition.

Copy link
Member Author

@joakim-hove joakim-hove Sep 17, 2020

Choose a reason for hiding this comment

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

The debian package supplies a libfmt.a - but that is an implementation detail debian have chosen when packaging, you could just as well dump a bunch of header files in your source folder.

I assume that since debian have opted to supply a libfmt.a in their binary package the corresponding cmake configuration file does not support the fmt::fmt-header-only link target.

But this should not alter the fact that there are no runtime dependencies involved here.

Copy link
Member

Choose a reason for hiding this comment

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

it's a shared object on epel. anyways, see akva2@d8f0106 (sorry you have to "distribute" across your commits).

tested on rhel and ubuntu.

the fmt-header-only target is fairly recent so we cannot rely on it (even ubuntu 20.04 is on fmt 6.1.2 which does not export it in the config files).

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank'll pick that up; but it does look like you have chosen a non optimal starting point for your fixes. I guess if you rebase on top of the tip of this branch I can just merge the changes right in?

Copy link
Member

Choose a reason for hiding this comment

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

no, it sits on top of two of your branches and changes are across different commits. just make it happen, i don't care about authorship or whatever.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK - done; I have added add_definitions(-DFMT_HEADER_ONLY). Thank you

@joakim-hove
Copy link
Member Author

jenkins build this please

@joakim-hove
Copy link
Member Author

OK; I see this as roughly ack'ed - I will merge now. All developers need to install fmtlib on their machine. Unfortunately there are some version differences between the fmtlib versions available for different distributions, hopefully this will not create problems.

I will merge this now, but will wait a bit with dependent code - so that we can easily pull it out again if it creates problems.

@joakim-hove joakim-hove merged commit 403fd09 into OPM:master Sep 17, 2020
@atgeirr
Copy link
Member

atgeirr commented Sep 17, 2020

I am struggling, but will try a bit more before I ask for mercy. I think a notice to the mailing list would be appropriate?

@joakim-hove
Copy link
Member Author

I think a notice to the mailing list would be appropriate?

I agree

@atgeirr
Copy link
Member

atgeirr commented Sep 17, 2020

I managed to figure out things. There were no installation instructions, but a normal cmake-based build process was sufficient.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants