Ask Your Question
0

how to use .txt and .cmake files in CMake?

asked 2013-04-25 21:49:28 -0600

Vaclav gravatar image

OK OK folks , enough googling for old / incorrect / incomplete / none-existent stuff about cmakes. What are these .txt files for? WHERE is the real tutorial on how to use .cmake file to build required opencv2 directory so opencv.hpp will compile????? A correct / real link would be appreciated - none of these "read doc" is helping much.

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
4

answered 2013-04-25 23:30:53 -0600

HD_Mouse gravatar image

updated 2013-04-25 23:32:34 -0600

Read the doc.

I kid. But seriously, tutorials are out there for reading. I will admit that CMake is pretty difficult to comprehend a lot of the times, but when set up properly it can be pretty damn cool. That said, I'll give you a quick summary of how to use it.

To answer your question directly, the main .txt file you'll be interested in is "CMakeLists.txt." This is the main configuration file for CMake that it uses when building your project. When you invoke CMake, the first thing it does is look for this file. Open it up and try to read the comments, because OpenCV guys put a pretty decent amount of comments in there and despite it's size, it's decently organized for a CMakeLists.txt file.

If you scroll down to line 108, you'll see where you can edit some build options. (CMake also has a GUI, so you may not even have to edit CMakeLists.txt directly!) The syntax might be overwhelming at first because of the absurd amount of options available, but if you take it slow and digest it, you'll see that it's pretty simple. Line 113 will let you decide if you want to include or omit IEEE1394 support. Simply change "ON" to "OFF" to turn it off. Most of configuration is as simple as that.

So looking at the *.cmake files. What they do can be inferred from their file names. Most of these are just general build options or scripts for finding some of the external/3rd party libs. Honestly, it's extremely unlikely that you'll be editing these files yourself, unless you're building a really customized version of OpenCV.

So how do you build? From the command line! (usually, I said earlier that there's CMakeGui, and that's an option as well, my quick example will be for a unix like command line) But it really just boils down to a few commands:

From the root directory, the one with CMakeLists.txt:

mkdir build
cd build/
cmake ..
make

And done.

If it isn't obvious, the first two commands make a build directory, because it's usually advised to keep build files separate from the main files. The next command is CMake in action. It'll look in the directory above build (the one with CMakeLists.txt), and start to generate build files. This includes looking for libraries, checking your options, and setting various other settings. At the end of a bunch of text, you'll see whether CMake failed or succeeded, and then if it succeeded, a summary of the various options you set. You'll notice that all those options can be set in CMakeLists.txt. Assuming everything worked and you're happy with the configuration, 'make' is a general command that searches for a file named 'Makefile' (this was generated when you called cmake) This step will compile OpenCV, and install the files onto your system ... (more)

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-04-25 21:49:28 -0600

Seen: 14,578 times

Last updated: Apr 25 '13