Repository navigation
Make header-only builds work from any number of translation units #104
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,15 +23,14 @@ else() | |
| endif() | ||
|
|
||
| add_library(integratorxx_common_ut quad_matcher.cxx) | ||
| if(INTEGRATORXX_HEADER_ONLY) | ||
| target_sources(integratorxx_common_ut PRIVATE lib_impl.cxx) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added in 518c367 as Checked both directions by defining |
||
| endif() | ||
| target_link_libraries( integratorxx_common_ut PUBLIC Catch2::Catch2WithMain integratorxx ) | ||
|
|
||
| add_executable( quadrature_manipulation quadrature_manipulation.cxx ) | ||
| target_link_libraries( quadrature_manipulation PUBLIC integratorxx_common_ut ) | ||
|
|
||
| add_executable( spherical_generator spherical_generator.cxx ) | ||
| # generator_second_tu.cxx only includes the generator headers: it is here so | ||
| # that a header-only build links two TUs that carry the implementations. | ||
| add_executable( spherical_generator spherical_generator.cxx generator_second_tu.cxx ) | ||
| target_link_libraries( spherical_generator PUBLIC integratorxx_common_ut ) | ||
|
|
||
| add_executable( 1d_quadratures 1d_quadratures.cxx ) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| // A second translation unit that includes the generator headers, so that the | ||
| // property this executable exists to check -- that a header-only build links | ||
| // from any number of translation units -- is actually exercised. In header-only | ||
| // mode these headers carry their own definitions, and any definition that loses | ||
| // its inline linkage collides with spherical_generator.cxx at link time. | ||
| // | ||
| // This has to sit in the executable rather than in integratorxx_common_ut: an | ||
| // object in a static library is pulled in only when something references it, so | ||
| // a duplicate definition there would go unnoticed. | ||
| // | ||
| // Including the headers is the whole test. A non-inline function with external | ||
| // linkage is emitted whether or not it is called, so no reference is needed. | ||
|
|
||
| #include <integratorxx/generators/spherical_factory.hpp> | ||
| #include <integratorxx/generators/radial_factory.hpp> | ||
| #include <integratorxx/generators/s2_factory.hpp> |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Worth stating here that the choice has to be consistent across the whole link. A TU compiled without
INTEGRATORXX_HEADER_ONLYsees only the declarations, and linking it againstlibintegratorxxwhile other TUs carry the inline definitions gives the same functions two definitions with different linkage, which is an ODR violation. Something like "define it in every translation unit, and don't also link the compiled library" would cover it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added, with the ODR reasoning spelled out: define it in every translation unit and do not also link the compiled library, because a TU compiled without it sees only the declarations.