Soroush Rabiei
Soroush Rabiei

Reputation: 10868

Compile openCV with CMake: set architecture and optimization flags

I need to compile OpenCV for i486 architecture. I would like to set optimization flags to O3. The problem is that can't find a way to set compiler flags in cmake file or with configuration script.

Upvotes: 1

Views: 6437

Answers (3)

ab77
ab77

Reputation: 871

./opencv/cmake/OpenCVCompilerOptions.cmake

Line 29:

set(OPENCV_EXTRA_FLAGS_RELEASE "-O3")

Note the overrides at the top though.

Upvotes: 1

Simon
Simon

Reputation: 32923

CMake allows you to set your compiler flags on a configuration basis. By default, if you choose the Release configuration, the optimization flags will probably be enabled. If you want to turn them on yourself, use:

set(CMAKE_C_FLAGS_RELEASE "-O3")

and choose the Release configuration (you could also do this using the Cache or the GUI):

set(CMAKE_BUILD_TYPE Release)

Relevant doc:

NB: replace C by CXX if you use C++

Upvotes: 6

mevatron
mevatron

Reputation: 14021

I believe you can either set the CFLAGS or CXXFLAGS as environment variables before you run cmake. Alternatively, have a look at using the CMAKE_C_FLAGS inside the relevant CMakeLists.txt files.

Hope that helps!

Upvotes: 1

Related Questions