laurentkneip / opengv

OpenGV is a collection of computer vision methods for solving geometric vision problems. It is hosted and maintained by the Mobile Perception Lab of ShanghaiTech.
Other
1.01k stars 354 forks source link

Passing custom (newer) C++ standard in cmake #90

Open NikolausDemmel opened 5 years ago

NikolausDemmel commented 5 years ago

In the cmake configuration the CXX_STANDARD property of the library is set to a fixed value of 11.

https://github.com/laurentkneip/opengv/blob/306a54e6c6b94e2048f820cdf77ef5281d4b48ad/CMakeLists.txt#L184

I'm building opengv as part of my project and would like to set a different (newer) C++ standard from outside. However, currently passing CMAKE_CXX_STANDARD does nothing and is overwritten. As a workaround I modify the CMakeLists.txt, but ideally I would like to pull in the unmodified upstream version.

Is there currently a way to pass a custom C++ standard version from "outside"?

What would be a good way to implement this? Instead of putting a fixed value of 11, we could check if CMAKE_CXX_STANDARD is set. If yes, we use that, if not, we default to 11. Would that be an acceptable change, or does that have possible downsides?

NikolausDemmel commented 5 years ago

Looks like the proper modern cmake way is something like

target_compile_features(opengv PUBLIC cxx_std_11)

which according to a quick test can be overwritten by setting CMAKE_CXX_STANDARD. Unfortunately that is a cmake 3.8+ feature.