The equivalent code is #define foo.
Example of using the new add_compile_definitions:
add_compile_definitions(OPENCV_VERSION=${OpenCV_VERSION})
add_compile_definitions(WITH_OPENCV2)
Either:
add_compile_definitions(OPENCV_VERSION=${OpenCV_VERSION} WITH_OPENCV2)
The good thing about this is that it bypasses the old tricks of CMake for add_definitions. CMake is a Such a shabby system, but they finally found some sanity.
Find more instructions on the commands used for compiler flags here: https://cmake.org/cmake/help/latest /command/add_definitions.html
Similarly, you can do this by target as explained in Jim Hunziker’s answer.
How to pass CMake defines preprocessor variables?
The equivalent code is #define foo.
For a long time, CMake used the add_definitions command for this purpose However, recently this command has been replaced by a more refined method (compilation definition, a separate command containing directory and compiler options).
Example of using the new add_compile_definitions:
add_compile_definitions(OPENCV_VERSION=${OpenCV_VERSION})
add_compile_definitions(WITH_OPENCV2)
Either:
add_compile_definitions( OPENCV_VERSION=${OpenCV_VERSION} WITH_OPENCV2)
The good thing about this is that it bypasses the shabby tricks of CMake for add_definitions. CMake is such a shabby system, but they finally found some sanity .
Find more instructions on the commands used for compiler flags here: https://cmake.org/cmake/help/latest/command/add_definitions.html
Similarly, you can do this by target as explained in Jim Hunziker’s answer.