From 44d1738d47567e6f80fc408cce0a574f4d5ca888 Mon Sep 17 00:00:00 2001 From: Maksim Shabunin Date: Fri, 22 May 2015 17:55:08 +0300 Subject: [PATCH] Transition guide: how to check library version --- .../transition_guide.markdown | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/doc/tutorials/introduction/transition_guide/transition_guide.markdown b/doc/tutorials/introduction/transition_guide/transition_guide.markdown index 5f3e35150c..6cf13172f5 100644 --- a/doc/tutorials/introduction/transition_guide/transition_guide.markdown +++ b/doc/tutorials/introduction/transition_guide/transition_guide.markdown @@ -257,3 +257,49 @@ _cuda_ module has been split into several smaller pieces: Documentation format {#tutorial_transition_docs} -------------------- Documentation has been converted to Doxygen format. You can find updated documentation writing guide in _Tutorials_ section of _OpenCV_ reference documentation (@ref tutorial_documentation). + +Support both versions {#tutorial_transition_both} +--------------------- +In some cases it is possible to support both versions of OpenCV. + +### Source code + +To check library major version one of the following methods can be used: +- if __CV_VERSION_EPOCH__ is defined - you are using 2.4 branch, otherwise - 3.x +- __CV_MAJOR_VERSION__ is defined as `2` or `3` for corresponding version + +One of `opencv2/core/version.hpp` or `opencv2/core/core.hpp` files should be included to use these definitions. + +Examples: +@code{.cpp} +#ifdef CV_VERSION_EPOCH +// do opencv 2 code +#else +// do opencv 3 code +#endif +@endcode +or +@code{.cpp} +#if CV_MAJOR_VERSION == 2 +// do opencv 2 code +#elif CV_MAJOR_VERSION == 3 +// do opencv 3 code +#endif +@endcode +@note Do not use __CV_VERSION_MAJOR__, it has different meaning for 2.4 and 3.x branches! + +### Build system + +It is possible to link different modules or enable/disable some of the features in your application by checking library version in the build system. Standard cmake or pkg-config variables can be used for this: +- `OpenCV_VERSION` for cmake will contain full version: "2.4.11" or "3.0.0" for example +- `OpenCV_VERSION_MAJOR` for cmake will contain only major version number: 2 or 3 +- pkg-config file has standard field `Version` + +Example: +@code{.cmake} +if(OpenCV_VERSION VERSION_LESS "3.0") +# use 2.4 modules +else() +# use 3.x modules +endif() +@endcode -- GitLab