Transition guide: how to check library version
authorMaksim Shabunin <maksim.shabunin@itseez.com>
Fri, 22 May 2015 14:55:08 +0000 (17:55 +0300)
committerMaksim Shabunin <maksim.shabunin@itseez.com>
Fri, 22 May 2015 15:46:16 +0000 (18:46 +0300)
doc/tutorials/introduction/transition_guide/transition_guide.markdown

index 5f3e351..6cf1317 100644 (file)
@@ -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