# How to set CMake options to compile some modules only?

We can set the options like the following to compile some but not others:

-DBUILD_opencv_xfeatures2d=ON
-DBUILD_opencv_apps=OFF


As the above, my understanding is xfeatures2d will be compiled (The Makefiles will set it as a target for compilation) and apps definitely not, but other modules haven't specified in the options will be compiled by default. However, if apps is required for xfeatures2d then xfeatures won't be compiled and cmake output will warning this.

What the problems with the above understanding ?

Is there a way to say compile xfeatures2d and the modules it required only ?

Furthermore, is there a way to say compile xfeatures2d and the modules it required and optionally required ones?

How about the WITH options, like -DWITH_1394=OFF, what is the default values for them ? Or, by default, it depends on the environment its running on? For instance, if CMake can find all (local) libraries needed for CUDA, -DWITH_CUDA will be ON by default.

edit retag close merge delete

Sort by » oldest newest most voted

i can only partly answer this, but here are some bulletpoints:

• there is a BUILD_LIST feature, where you can specify the modules you want , overriding the existing BUILD_opencv_xxxx=ON settings. you'd use it like:

cmake -DBUILD_LIST=dnn,core,calib3d,imgproc,imgcodecs,highgui


(comma seperated modulenames without opencv_ prefix)

• to pick up your xfeatures2d example: each module has a CmakeLists.txt, where you can find its dependancies , in this case:

opencv_core opencv_imgproc opencv_features2d opencv_calib3d


are mandatory. (... then you'll find out, that features2d needs flann ;)

• you have to carefully watch the cmake output for lines like:

module xxxx disabled because of missing dependancy yyyy


before you can run configure or make

more

1

Thanks @berak, this is what exact what i am looking for! For others who were confused also: 1. BUILD_LIST is acting like a white list function, only the ones specified will be built given their required ones (dependency) are specified too . Ref def here; 2. Normally, the dependency are list in ocv_define_module of their CMakeLists.txt, for some cases, try ocv_add_module.

( 2018-09-06 11:20:28 -0500 )edit

No similar white list found for WITH_* yet, but all components are list in HERE

( 2018-09-06 12:38:50 -0500 )edit

Yes you can set specific flags needed by you. I prefer using GUI or ccmake . Enter following commands in your terminal

Step1. Change the directory to opencv build folder.
Step2. \$ ccmake .


List of all the modules and flags will be displayed on the screen.

Step3. Now set the flags ON/OFF using enter key.
Step4. Press c to configure changes.
Step5. Press g to generate files.


After this you can do make and install

more

Hi, @ak1, thanks for the response. Get some interesting findings on the way you mentioned also. Thanks bro !

( 2018-09-06 11:44:33 -0500 )edit

Official site

GitHub

Wiki

Documentation