OpenSceneGraph 3.0: Beginner's Guide
上QQ阅读APP看书,第一时间看更新

Time for action—running CMake in GUI mode

After Cmake has been installed on your system, you can run it from the command line, or choose to run in GUI mode, which allows you to edit the options in a much easier way.

  1. Find the executalbe cmake-gui.exe from the start menu folder and run it. A GUI will show up with two entry panels for specifying the source and binary directories, as well as a couple of text boxes.
  2. To make it work with the OpenSceneGraph source code, you should first identify the place where the source code is: drag the file CMakeLists.txt from the OSG root directory, and drop it onto the CMake window. The contents of two entry panels will change at the same time, and, to the same absolute path value, which indicates that the platform-dependent workspaces or makefiles will be generated directly in the source code directory, and the compilation process will start at the same place, too. In short, this is an in-source build.
  3. Conversely, an out-of-source build will export the generated files into a completely separate directory, with the source code unchanged. For that purpose, you should modify the path value of Where to build the binaries, and designate the expected path. Out-of-source is always recommended because it will keep the source code clear, and make it possible to generate multiple variants of project configurations.
    Time for action—running CMake in GUI mode
  4. Assuming that you have already downloaded the OSG source code to C:\OpenSceneGraph, and set the binary directory to C:\build_OpenSceneGraph, as shown in the previous image, the next step is to click on Configure, and select a suitable generator for your system in following pop-up dialog:
    Time for action—running CMake in GUI mode
  5. Please do not specify a generator that does not exist on your system. CMake will automatically search for an available compiler and a linker according to your selection, and report any errors if this fails. Select Visual Studio 10, or any other generator in the list. Beginners can download the free Visual Studio 10 (2010) Express from http://www.microsoft.com/express/Windows/.
  6. Press the Finish button to continue. After that you will see the blank text box filling with red-highlighted building options. Choose Grouped View in the central combo box and rearrange the options in tree structures, as shown:
    Time for action—running CMake in GUI mode
  7. Try opening a top-level tree item, for instance, the BUILD group. Now it is time to set up building options and get ready to create your Visual Studio 10 solutions. See the section Setting up options below, for more details.
  8. After all of the options are selected and accepted, click on Generate in order to generate the Visual Studio solutions or UNIX makefiles,\ according to your previous selection:
    Time for action—running CMake in GUI mode
  9. Close the CMake GUI, and navigate to C:\build_OpenSceneGraph—the predetermined place to build the binaries. If everything progressed properly, you will find that the solution file has already been created. Open the freshly-baked OpenSceneGraph.sln file, and start to compile OSG binaries and libraries at once!

What just happened?

CMake will generate makefiles and cache files in the Where to build the binaries directory. The cache files are used to keep the build settings, and will remember the user's choices for future rebuilding, which means that options don't have to be repeated if CMake is running on the same build directory the next time.