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

fix: add GTSAM_USE_BOOST_FEATURES to definitions #1995

Merged

Conversation

ArkadiuszNiemiec
Copy link

@ArkadiuszNiemiec ArkadiuszNiemiec commented Jan 23, 2025

This fixes the issue #1994 and some issues mentioned in #1967 and #1981.

The change defines the proper identifier if GTSAM_USE_BOOST_FEATURES option is set in CMakeLists.txt.
It's used in:

#if GTSAM_USE_BOOST_FEATURES
#include <boost/concept_check.hpp>
#include <boost/concept/assert.hpp>
#include <boost/concept/requires.hpp>
#include <boost/concept_check.hpp>
#define GTSAM_CONCEPT_ASSERT(concept) BOOST_CONCEPT_ASSERT((concept))
#define GTSAM_CONCEPT_REQUIRES(concept, return_type) BOOST_CONCEPT_REQUIRES(((concept)), (return_type))
#else
// This does something sensible:
#define BOOST_CONCEPT_USAGE(concept) void check##concept()
// These just ignore the concept checking for now:
#define GTSAM_CONCEPT_ASSERT(concept) static_assert(true, "")
#define GTSAM_CONCEPT_REQUIRES(concept, return_type) return_type
#endif

...and without it the compiler throws BOOST_CONCEPT_USAGE redefinition error.

@dellaert
Copy link
Member

Thanks, but I might not fully understand then: I checked and we don't do this for GTSAM_ENABLE_BOOST_SERIALIZATION, but we can still branch on that in code. Why is GTSAM_USE_BOOST_FEATURES different?

@ArkadiuszNiemiec
Copy link
Author

Thanks, but I might not fully understand then: I checked and we don't do this for GTSAM_ENABLE_BOOST_SERIALIZATION, but we can still branch on that in code. Why is GTSAM_USE_BOOST_FEATURES different?

Oh, right. The GTSAM_ENABLE_BOOST_SERIALIZATION didn't generate a build error for me, but it should be added as well. Fixed.

@dellaert
Copy link
Member

Well, I guess my question was the other way :-) Why can we branch on GTSAM_ENABLE_BOOST_SERIALIZATION currently? And could we use the same mechanism to branch on GTSAM_USE_BOOST_FEATURES? It seems the add_definitions was not needed for GTSAM_ENABLE_BOOST_SERIALIZATION?

@ArkadiuszNiemiec
Copy link
Author

ArkadiuszNiemiec commented Jan 24, 2025

AFAIK both identifiers/macros were always not defined in the code. My linter confirms that but to prove it I added this to one of the examples:
image

...checked out my first commit (with just GTSAM_USE_BOOST_FEATURES fixed), made sure the flag is ON and built:
image

The output:
image

...and you are right. For some reason both are ON 😕 So why it's not working during compile time?

@dellaert
Copy link
Member

right :-)
No idea ! Sleuthing required!
But if we find a]out why we can avoid the “add_definitions” step.
Note: it requires #if and not #ifdef. Maybe there is a straggling #ifdef ?

@dellaert
Copy link
Member

Note, your test is compile time. All macro pre-processing is gone at runtime.

@ArkadiuszNiemiec
Copy link
Author

OK, got it. GTSAM is using https://github.com/borglab/gtsam/blob/develop/gtsam/config.h.in
It creates a config.h that needs to be included if one want to use the CMake variables. To include was missing from that one specific file. Thank you @dellaert, great questions!

Copy link
Member

@dellaert dellaert left a comment

Choose a reason for hiding this comment

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

Ah ! Nice, LGTM :-) I will kick off CI and we can merge.

@varunagrawal
Copy link
Collaborator

FYI add_definitions is an inefficient approach. Please see #1944 for details.

Also sorry I didn't see this before, was busy with other stuff. Else we could have fixed this sooner. :)

@varunagrawal varunagrawal merged commit a744cfc into borglab:develop Jan 25, 2025
35 checks passed
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.

3 participants