evaleev / libint

Libint: high-performance library for computing Gaussian integrals in quantum mechanics
Other
226 stars 95 forks source link

Produce static (PIC) and shared versions of the int2 library in the cmake project #141

Closed francesco-bosia closed 5 years ago

francesco-bosia commented 5 years ago

Currently, in the cmake project, only a static library is produced (libint2.a). This library is compiled without setting the position independent code property to ON. This prevents the subsequent linking of the library in a shared library.

I did it in my local repo, but I thought to spread my solution with the project.

In order to do so, I propose to a) add the said property (set_target_property PROPERTIES POSITION_INDEPENDENT_CODE ON) to the obejct file produced for the int2 library. b) produce a shared and a static version of the libraries without increasing the compile time. This is done by compiling an object file int2_obj and subsequently creating a STATIC int2_static and a SHARED int2 target form it. Compile time is thus the same.

Now both versions are available for linking. No further problem with shared projects is envisioned. Tests are linked to the shared version to save some time at link stage.

evaleev commented 5 years ago

Thanks for the contribution!

Due to (mostly trivial, but nonzero) impact of PIC on performance it is desirable to be able to avoid PIC when not required. Hence the default behavior to produce a single (shared or static) library, with its type specified by BUILD_SHARED_LIBS (user can already produce a dynamic library by setting this cache variable via command line or ccmake). I recommend the proposed 1-shot shared+static build is made optional, enabled by cache variable LIBINT_BUILD_SHARED_AND_STATIC_LIBS (or smth similar).

Thoughts?

francesco-bosia commented 5 years ago

Thank you for your review!

I get your point. I did not profile the code with and without PIC, so I will adapt the pull request to implement the proposal for optional one-shot construction of shared and static libraries.

evaleev commented 5 years ago

I highly doubt that the performance impact is significant, if any. Nevertheless I prefer to "only pay for what you use".

francesco-bosia commented 5 years ago

Ok. Then I will remove the PIC and allow for 1 shot static and shared build.

I tried to grep the whole CMake project for BUILD_SHARED_LIBS or SHARED, but I did not find where the option is set/used. Could you please point me to where the option is set/used in the CMake project?

evaleev commented 5 years ago

https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html

francesco-bosia commented 5 years ago

Sure! I changed the CMakeLists.txt.export to include the cases in which both libraries are constructed and the case where only a specific library is constructed accordingly.

francesco-bosia commented 5 years ago

Some tests fail due to timeouts.