0025229: Cappings have gray tint if setting color with vclipplane command
[occt.git] / dox / dev_guides / building / cmake / cmake.md
ba06f8bb 1Building with CMake {#occt_dev_guides__building_cmake}
e5bd0d98 2===================
576f8b11 6This file describes the steps to build OCCT libraries from a complete source package
7with **CMake**. CMake is free software that can create GNU Makefiles, KDevelop,
8XCode, and Visual Studio project files. **CMake** version 2.6 or above is
e5bd0d98 9required.
576f8b11 11If you build OCCT from bare sources (as in Git repository) or make some
e5bd0d98 12changes affecting CDL files, you need to use WOK to re-generate header files
ba06f8bb 13and build scripts / projects. See \ref occt_dev_guides__building_wok for instructions.
e5bd0d98 14
576f8b11 15Before building OCCT, you need to install the required third-party libraries; see the
ba06f8bb 16instructions for your platform in @ref occt_dev_guides__building.
e5bd0d98 17
576f8b11 18## Define the location of build and install directories.
e5bd0d98 19
576f8b11 20The build directory is where intermediate files (projects / makefiles, objects, binaries) will be created. Each built configuration should have its own build directory.
e5bd0d98 21
576f8b11 22The install directory is where binaries will be installed after build, along with header files and resources required for OCCT use in applications.
32856b63 23It is possible to install several configurations of OCCT (differentiated by platform, bitness, compiler, and build type) into the same directory.
e5bd0d98 24
25It is recommended to separate build and install directories from OCCT source directory, for example:
32856b63 27 /user/home/occt/ - sources
28 /user/home/tmp/occt-build-vc10-x64-release - intermediate files
29 /user/home/occt-install - installed binaries
e5bd0d98 30
31## CMake usage
576f8b11 33Run CMake indicating the path to OCCT sources <i>($CASROOT)</i> and selected build directory.
e5bd0d98 34
576f8b11 35It is recommended to use GUI tools provided by CMake: *cmake-gui* on Windows and Mac, *ccmake* or *cmake-gui* on Linux.
e5bd0d98 36
37### Windows:
576f8b11 39Specify the root folder of OCCT (<i>$CASROOT</i>, which contains *CMakelists.txt* file) by clicking **Browse Source**.
e5bd0d98 40
32856b63 41@figure{/dev_guides/building/cmake/images/cmake_image001.png}
e5bd0d98 42
576f8b11 43Specify the location (build folder) for Cmake generated project files by clicking **Browse Build**.
e5bd0d98 44
576f8b11 45Each configuration of the project should be built in its own directory. When building multiple configurations it is recommended to indicate in the name of build directories the system, bitness, compiler, and build type (e.g., <i>d:/occt/build/win32-vc9-debug</i> ).
47**Configure** opens the window with a drop-down list of generators supported by CMake project. Select the required generator (e.g., Visual Studio 2008) and click **Finish**.
32856b63 48
51### Linux (ccmake variant):
e5bd0d98 52
576f8b11 53In the console, change to the build directory and call *ccmake* with the path to the source directory of the project:
e5bd0d98 54
55 > cd ~/occt/build/debug
79d580f2 56 > ccmake ~/occt
e5bd0d98 57
32856b63 58@figure{/dev_guides/building/cmake/images/cmake_image003.png}
e5bd0d98 59
576f8b11 60Press *c* to configure.
e5bd0d98 61
576f8b11 62*cmake-gui* is used in the same way as described above for Windows.
32856b63 63
e5bd0d98 64### Mac OS:
576f8b11 66Use *cmake-gui* **Applications -> CMake 2.8-10.app** to generate project files for the chosen build environment (e.g., XCode).
e5bd0d98 67
32856b63 68@figure{/dev_guides/building/cmake/images/cmake_image004.png}
e5bd0d98 69
70## OCCT Configuration
576f8b11 72The error message, which appears at the end of configuration process, informs you about the required variables,
e5bd0d98 73which need to be defined. This error will appear until all required variables are defined correctly.
e5bd0d98 74
576f8b11 75Note: In *cmake-gui* there is "grouped" option, which groups variables with a common prefix.
77### Selection of the components to be built
e5bd0d98 78
576f8b11 79The variables with <i>BUILD_</i> prefix allow specifying OCCT components and
5c573e69 80configuration to be built:
234e52be 81
576f8b11 82* *BUILD_CONFIGURATION* - defines configuration to be built (Release by default).
83* <i>BUILD_<MODULE></i> - specifies whether the corresponding OCCT module should be
84 built (all toolkits). Note that even if the whole module is not
32856b63 85 selected for build, its toolkits used by other toolkits
86 selected for build will be included automatically.
576f8b11 87* *BUILD_TOOLKITS* - allows including additional toolkits from non-selected
32856b63 88 modules (should be list of toolkit names separated by a
89 space or a semicolon).
576f8b11 90* *BUILD_SAMPLES* - specifies whether OCCT MFC samples should be built.
91* *BUILD_PATCH_DIR* - optionally specifies additional folder containing patched OCCT source files.
32856b63 92 The patch may contain arbitrary subset of OCCT source files (including CMake scripts, templates, etc.), organized in the same structure of folders as OCCT.
576f8b11 93 The projects generated by CMake will use files found in the patch folder instead of the corresponding files of OCCT.
e5bd0d98 94
576f8b11 95Check variables with <i>USE_</i> prefix (<i>USE_FREEIMAGE, USE_GL2PS, USE_TBB,</i> and
96<i>USE_OPENCL</i>) if you want to enable use of the corresponding optional 3rd-party
5c573e69 97library.
576f8b11 99### 3rd-party configuration (The variables with <i>3RDPARTY_</i> prefix)
e5bd0d98 100
101If you have 3rd-party libraries in a non-default location
576f8b11 102(e.g., on Windows, binaries downloaded from http://www.opencascade.org/getocc/download/3rdparty/")
103specify *3RDPARTY_DIR* variable that points to the folders of 3rd-party libraries (some or all).
105At the next configuration step the 3rd-party libraries will be searched for in *3RDPARTY_DIR* directory, and stored in *3RDPARTY_\<LIBRARY\>_DIR* variables.
32856b63 107The procedure expects to find binary and header files of each 3rd-party library in its own sub-directory, separated by sub-directories *bin*, *lib*, and *include*.
ad211ad3 108
576f8b11 109Press **Configure** (**c** key for ccmake).
ad211ad3 110
e5bd0d98 111The result of the 3rdparty product search will be recorded in the corresponding variables:
576f8b11 113* *3RDPARTY_\<PRODUCT\>_DIR* - path to the product directory (with directory name) (e.g. <i>D:/3rdparty/Tcl-</i>)
114* *3RDPARTY_\<PRODUCT\>_LIBRARY* - path to .lib libraries (with the library name) (e.g. <i>D:/3rdparty/Tcl-</i>).
115 In non-windows case, this variable is the same as *3RDPARTY_\<PRODUCT\>_DLL*.
116* *3RDPARTY_\<PRODUCT\>_INCLUDE* - path to the include directory that contains the required header file (with "include" name) (e.g., <i>D:/3rdparty/Tcl- including tcl.h</i>)
117* *3RDPARTY_\<PRODUCT\>_DLL* - path to <i>.dll/.so/.dylib</i> library (with the library name) (e.g., <i>D:/3rdparty/Tcl-</i>)
e5bd0d98 118
119The search process is as follows:
576f8b11 1211. Common path: *3RDPARTY_DIR*
1222. Path to a particular 3rd-party library: *3RDPARTY_\<PRODUCT\>_DIR*
5c573e69 1233. Paths to headers and binaries:
576f8b11 124 1. *3RDPARTY_\<PRODUCT\>_INCLUDE*
e5bd0d98 127
576f8b11 128If a variable of any level is not defined (empty or <i> \<variable name\>-NOTFOUND </i>)
e5bd0d98 129and the upper level variable is defined, the content of the non-defined variable
130will be searched for at the next configuration step. If search process in level 3
234e52be 131does not find the required files, it searches in default places also.
e5bd0d98 132
576f8b11 133**Note**: the names of searched libraries and header files are hard-coded.
134Freetype search process tries to find *ft2build.h* file in *3RDPARTY_FREETYPE INCLUDE* directory
135and after that adds *3RDPARTY_FREETYPE_INCLUDE /freetype2* path to common includes if it exists.
5c573e69 136
576f8b11 137Important: If *BUILD_CONFIGURATION* variable is changed, at the next configuration
138*3RDPARTY_ variables* will be replaced by the search process result, except for the *3RDPARTY_DIR* variable.
e5bd0d98 139
576f8b11 140*Note* : CMake will produce an error after the configuration step until all required variables are defined correctly.
141If the search result (include path, or library path, or dll path) does not meet your expectations,
142you can change *3RDPARTY_\<PRODUCT\>_DIR variable*, clear (if they are not empty)
e5bd0d98 144(or clear one of them) and run the configuration process again.
5c573e69 145
576f8b11 146At this time the search will be performed in the newly identified directory
e5bd0d98 147and the result will be recorded to empty variables (non-empty variables will not be replaced).
576f8b11 149For example, (Linux case) *3RDPARTY_FREETYPE_DIR* variable
e5bd0d98 150
234e52be 151 /PRODUCTS/maintenance/Mandriva2010/freetype-2.3.7
e5bd0d98 152
153can be changed to
234e52be 155 /PRODUCTS/maintenance/Mandriva2010/freetype-2.4.10
e5bd0d98 156
576f8b11 157and the related variables *3RDPARTY_FREETYPE_DLL, 3RDPARTY_FREETYPE_INCLUDE_DIR* and *3RDPARTY_FREETYPE_LIBRARY* will be cleared.
e5bd0d98 158
32856b63 159@figure{/dev_guides/building/cmake/images/cmake_image005.png}
e5bd0d98 160
576f8b11 161During the configuration process the cleaned variables will be filled with new found values.
e5bd0d98 162
234e52be 163###The variables with INSTALL_ prefix:
e5bd0d98 164
576f8b11 165Define in *INSTALL_DIR* variable the path, where the built OCCT files (libraries, executables and headers) will be placed.
166If <i>INSTALL_\<PRODUCT\></i> variable is checked, 3rd-party products will be copied to the install directory.
234e52be 167
576f8b11 168At the end of the configuration process "configuring done" message will be shown and the generation process can be started.
e5bd0d98 169
170## OCCT Generation
576f8b11 172This procedure will create makefiles or project files for your build system.
e5bd0d98 173
174### Windows
576f8b11 176Click **Generate** button and wait until the generation process is finished.
177Then the project files will appear in the build folder (e.g. <i> d:/occt/build/win32-vc9-release </i>).
e5bd0d98 178
179### Linux
576f8b11 181When the configuration is complete, start the generation process by pressing **g**.
e5bd0d98 182
32856b63 183@figure{/dev_guides/building/cmake/images/cmake_image006.png}
e5bd0d98 184
185### Mac OS X
576f8b11 187Click **Generate** button and wait until the generation process is finished.
188Then the project files will appear in the build folder (e.g. <i> /Developer/occt/build/XCode </i>).
e5bd0d98 189
190## OCCT Building
576f8b11 192The install folder contains *bin, inc, lib* and *res* folders and a script to run *DRAWEXE* (*draw.bat* or *draw.sh*).
193* **bin** contains executables, DLL (Windows) style shared libraries and pdb-files in OCCT debug version.
194* **lib** contains the import parts of DLL libraries.
195* **inc** contains header files.
196* **res** contains all required source files for OCCT.
e5bd0d98 197
198### Windows (Visual studio)
576f8b11 200Go to the build folder, start the Visual Studio solution *OCCT.sln* and build it by clicking **Build -> Build Solution**.
202When the building process is finished, build the *INSTALL* project (by default the build solution process skips the building of the INSTALL project) to move the above files to *INSTALL_DIR*.
204For this, right-click on the *INSTALL* project and select **Project Only -> Build Only** -> *INSTALL* in the solution explorer.
e5bd0d98 205
206### Linux (make)
576f8b11 207
208Change directory to the directory with binaries and run *make* command
e5bd0d98 209
210 > make
576f8b11 212To copy all libraries, executables and chosen 3rd-party libraries run *make* command with *install* argument
e5bd0d98 213
214 > make install
576f8b11 216This command will move the above files to *INSTALL_DIR*.
e5bd0d98 217
218### Mac OS X (XCode)
576f8b11 220Go to the build folder, start XCode solution *OCCT.xcodeproj* and build it by clicking **Build -> Build**.
221Please notice that XCode may lag because it processes sources at the first start.
223When the building process has finished, build the *INSTALL* project (by default the build solution process skips the building of *INSTALL* project) to move the above files to *INSTALL_DIR*.
224Notice that *env.sh* (which configures *PATH* and *DYLD_LIBRARY_PATH* environment variables
225as well as Draw Harness extra variables) and *draw.sh* (to launch *DRAWEXE* ) will be created in the target directory.
227### MFC samples
229On Windows you can also build binaries of MFC samples together with OCCT. For this, activate **BUILD_Samples** check-box in CMake configuration dialog.
e5bd0d98 232
576f8b11 233Please take into account that MFC sample binaries will be installed in the same folder as OCCT binaries during building of *INSTALL* project.
234To run an MFC sample use *sample.bat* launcher. The command format is: <i>sample.bat <SampleName></i> (e.g. <i>sample.bat ImportExport</i>).