0026529: CMake offers rebuilding of platform dependent code unclear for an user
[occt.git] / dox / dev_guides / building / cmake / cmake.md
CommitLineData
ba06f8bb 1Building with CMake {#occt_dev_guides__building_cmake}
e5bd0d98 2===================
3
4@tableofcontents
5
316d77d9 6This article describes **CMake**-based build process which is now suggested as a standard way to produce the binaries of Open CASCADE Technology from sources. *OCCT requires CMake version 3.0 or later*.
e5bd0d98 7
316d77d9 8**Note**: Comparing to the previous (6.x) releases of Open CASCADE Technology, OCCT 7.0 comes with a complete set of CMake scripts and projects, so that there is no need to use WOK anymore. Moreover, CMake gives you a powerful configuration tool which allows to control many aspects of OCCT deployment. At the same time this tool is quite intuitive which is a significant advantage over the legacy WOK utilities.
e5bd0d98 9
316d77d9 10**Note**: We discuss the build procedure on example of Windows platform. However, the workflow is almost the same for *nix and Mac operating systems.
e5bd0d98 11
316d77d9 12All the examples in the article will be based on Windows x64 platform and Visual Studio 2010 solution will be the target IDE. The solution will be generated by CMake from the OCCT sources, the one will be built by an user and ready-to-go OCCT binaries will be deployed into a user specified directory by building *INSTALL* project.
e5bd0d98 13
316d77d9 14You can get all the required 3-rd party products visiting the official download page [**insert link**]; see @ref occt_dev_guides__building for more detailed information also.
e5bd0d98 15
316d77d9 16## Get sources
e5bd0d98 17
316d77d9 18The sources of OCCT can be obtained from the official development web-site [**insert link**] by either downloading the universal source package (available at official download page [**insert link**]) or by cloning the Git repository:
e5bd0d98 19
316d77d9 20 git clone ssh://gitolite@git.dev.opencascade.org/occt occt
e5bd0d98 21
316d77d9 22As a result, you obtain the following directory structure in your filesystem (*workbench* name is used for example):
23
24 workbench\occt\adm
25 \data
26 \dox
27 \samples
28 \src
29 \tests
30 ...
e5bd0d98 31
316d77d9 32The bare sources distribution contains not only the sources of Open CASCADE Technology, but also documentation, samples and non-regression test scripts. The official manual [**insert link**] is refered for details on the distribution contents.
e5bd0d98 33
316d77d9 34## The usage of CMake
e5bd0d98 35
316d77d9 36Now it is time to run a CMake tool which will generate the actual project files for the target IDE (e.g., Visual Studio 2010 solution).
e5bd0d98 37
316d77d9 38It is recommended to use *cmake-gui* - cross-platform GUI tool provided by CMake on Windows, Mac and Linux. As a command-line alternative, *ccmake* also can be used.
e5bd0d98 39
316d77d9 40CMake deals with three directories: source, build or binary and install.
e5bd0d98 41
316d77d9 42* The source directory is where the sources of OCCT are located in your filesystem
43* The build or binary directory is where all the files created during CMake configuration [**insert link**] and generation [**insert link**] process will be located. The mentioned process will be described below.
44* The installation directory is where binaries will be installed after build the *INSTALL* project that is created by CMake generation process, along with header files and resources required for OCCT use in applications.
576f8b11 45
316d77d9 46**Note**: It is possible to choose one installation directory for several configurations of OCCT (differentiated by platform, bitness, compiler and build type).
32856b63 47
316d77d9 48**Note**: The good practice is not to mix up different build configurations [**insert link**] in a single directory and not to use the source directory as a build one, for example:
49
50 workbench/occt/ - the source directory
51 workbench/tmp/occt-build-vc10-x64 - the build directory with the generated
52 solution and other intermediate files created during a CMake tool working
53 workbench/occt-install - the installation directory that is
54 able to contain several OCCT configuratoion
32856b63 55
316d77d9 56## Configuration process
e5bd0d98 57
316d77d9 58If the command-line tool is used, run the tool from the source directory with a single argument indicating the build (binary) (relative or absolute path) directory:
e5bd0d98 59
316d77d9 60 cd <the source directory>
61 ccmake <the build directory>
e5bd0d98 62
316d77d9 63@figure{/dev_guides/building/cmake/images/cmake_image000.png}
e5bd0d98 64
576f8b11 65Press *c* to configure.
e5bd0d98 66
316d77d9 67All required actions in the configuration process will be described with using the GUI tool below.
576f8b11 68
316d77d9 69If the gui-tool is used, run the tool without additional arguments and after that specify the source directory by clicking **Browse Source** and the build (binary) one by clicking **Browse Build**.
adc33035 70
316d77d9 71@figure{/dev_guides/building/cmake/images/cmake_image001.png}
576f8b11 72
316d77d9 73**Note**: Each 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 and compiler (e.g., <i>d:/occt/build/win32-vc10</i> ).
576f8b11 74
316d77d9 75Once the source and build directories are selected, "Configure" button should be pressed in order to start manual configuration process. It begins with selection of a target configurator. It is "Visual Studio 10 2010 Win64" in our example.
ad211ad3 76
316d77d9 77@figure{/dev_guides/building/cmake/images/cmake_image002.png}
ad211ad3 78
316d77d9 79Once "Finish" button is pressed, the first pass the configuration process is executed. At the end of the process, CMake outputs the list of environment variables which have to be properly specified for successful configuration.
80
81The error message provides an information about these variables. This message will appear after each pass of the process until all required variables are specified correctly.
82
83The change of the state of some variables can lead to a new variable appearance. The new variables appeared after the pass of the configuration process is notified with red color by CMake GUI tool.
84
85Note: There is "grouped" option which groups variables with a common prefix.
86
87The following table enumerates the full list of environment variables used at configuration stage:
88
89| Variable | Type | Purpose |
90|----------|------|---------|
91| CMAKE_BUILD_TYPE | String | Specifies the build type on single-configuration generators (sush as make). Possible values are Debug, Release and RelWithDebInfo |
92| USE_FREEIMAGE | Boolean flag | Indicates whether Freeimage product should be used in OCCT visualization module for support of popular graphics image formats (PNG, BMP etc) |
93| USE_GL2PS | Boolean flag | Indicates whether GL2PS product should be used in OCCT visualization module for support of vector image formats (PS, EPS etc) |
94| USE_TBB | Boolean flag | Indicates whether TBB 3-rd party is used or not. TBB stands for Threading Building Blocks, the technology of Intel Corp, which comes with different mechanisms and patterns for injecting parallelism into your application. OCCT remains parallel even without TBB product |
95| USE_VTK | Boolean flag | Indicates whether VTK 3-rd party is used or not. VTK stands for Visualization ToolKit, the technology of Kitware Inc intended for general-purpose scientific visualization. OCCT comes with a bridge between CAD data representation and VTK by means of its dedicated VIS component (VTK Integration Services). You may skip this 3-rd party unless you are planning to use VTK visualization for OCCT geometry. The official documentation [**insert link**] \("VTK Integration Services" user's guide\) for the details on VIS |
96| 3RDPARTY_DIR | Path | Defines the root directory where all required 3-rd party products will be searched. Once you define this path it is very convenient to click "Configure" button in order to let CMake automatically detect all necessary products|
97| 3RDPARTY_FREETYPE_* | Path | Path to Freetype binaries |
98| 3RDPARTY_TCL_* 3RDPARTY_TK_* | Path | Path to Tcl/Tk binaries |
99| 3RDPARTY_FREEIMAGE* | Path | Path to Freeimage binaries |
100| 3RDPARTY_GL2PS_* | Path | Path to GL2PS binaries |
101| 3RDPARTY_TBB* | Path | Path to TBB binaries |
102| 3RDPARTY_VTK_* | Path | Path to VTK binaries |
103| BUILD_MODULE_<MODULE>| Boolean flag | Indicates whether the corresponding OCCT module should be built or not. It should be noted that some toolkits of a module can be built even if this module is not checked (this happens if some other modules depend on these toolkits). The main modules and their descriptions can be found in [**insert link**] \("User Guides" chapter\) and partially in [**insert link**] |
104| BUILD_LIBRARY_TYPE | String | Specifies the type of library to be created. "Shared" libraries are linked dynamically and loaded at runtime. "Static" libraries are archives of object files for use when linking other targets |
105| BUILD_ADDITIONAL_TOOLKITS | String | Semicolon-separated individual toolkits to include into build process. If you want to build some particular libraries (toolkits) only, then you may uncheck all modules in the corresponding *BUILD_MODUE_\<MODULE\>* options and provide the list of necessary libraries here. Of course, all dependencies will be resolved automatically |
106| REBUILD_PLATFORM_DEPENDENT_CODE | Boolean flag | Enables Flex/Bison lexical analyzers. OCCT source files relating to STEP reader and ExprIntrp functionality are generated automatically with Flex/Bison. Checking this options leads to automatic search of Flex/Bison binaries and regeneration of the mentioned files |
107| BUILD_MODULE_OcctMfcSamples | Boolean flag | Indicates whether MFC samples should be built together with OCCT. This option is only relevant to Windows platforms |
108| BUILD_DOC_OcctOverview | Boolean flag | Indicates whether OCCT overview documentation project should be created together with OCCT. It is not built together with OCCT. Checking this options leads to automatic search of Doxygen binaries. Building of it will be call Doxygen command to generate the documentation in HTML format |
109| APPLY_OCCT_PATH_DIR | Boolean flag | Points to the directory recognized as a "patch" for OCCT. If specified, the files from this directory take precedence over the corresponding native OCCT sources. This way you are able to introduce patches to Open CASCADE Technology not affecting the original source distribution |
110| CMAKE_CONFIGURATION_TYPES | String | Semicolon-separated CMake configurations |
111| INSTALL_DIR | Path | Points to the installation directory |
112| INSTALL_FREETYPE | Boolean flag | Indicates whether Freetype binaries should be installed into the installation directory |
113| INSTALL_FREEIMAGE* | Boolean flag | Indicates whether Freeimage binaries should be installed into the installation directory |
114| INSTALL_GL2PS | Boolean flag | Indicates whether GL2PS binaries should be installed into the installation directory |
115| INSTALL_TBB | Boolean flag | Indicates whether TBB binaries should be installed into the installation directory |
116| INSTALL_VTK | Boolean flag | Indicates whether VTK binaries should be installed into the installation directory |
117| INSTALL_TCL | Boolean flag | Indicates whether TCL binaries should be installed into the installation directory |
118| INSTALL_OCCT_SAMPLES | Boolean flag | Indicates whether non-regression OCCT test scripts should be installed into the installation directory |
119| INSTALL_DOC_OcctOverview | Boolean flag | Indicates whether OCCT overview documentation should be installed into the installation directory |
120
121**Note:** In those CMake options defining paths only the forward slashes ("/") are acceptable.
122
123### 3rd-party search mechanism (The variables with <i>3RDPARTY_</i> prefix)
124
125If *3RDPARTY_DIR* directory is defined, required 3rd-party binaries are sought in it, default system folders are ignored.
126
127The procedure expects to find binary and header files of each 3rd-party product in its own sub-directory: *bin*, *lib* and *include*.
128
129The result of the search (achived on the next pass of the configuration process) are recorded in the corresponding variables:
e5bd0d98 130
9f33b387 131* *3RDPARTY_\<PRODUCT\>_DIR* - path to the 3rdparty directory (with directory name) (e.g. <i>D:/3rdparty/tcltk-86-32</i>)
132* *3RDPARTY_\<PRODUCT\>_LIBRARY_DIR* - path to directory containing a library (e.g. <i>D:/3rdparty/tcltk-86-32/lib</i>).
133* *3RDPARTY_\<PRODUCT\>_INCLUDE_DIR* - path to the directory containing a header file (e.g., <i>D:/3rdparty/tcltk-86-32/include</i>)
316d77d9 134* *3RDPARTY_\<PRODUCT\>_DLL_DIR* - path to the directory containing a shared library (e.g., <i>D:/3rdparty/tcltk-86-32/bin</i>) This variable is only relevant to Windows platforms
9f33b387 135
adc33035 136Note: each library and include directory should be the children of product directory if the last one is defined.
e5bd0d98 137
138The search process is as follows:
139
576f8b11 1401. Common path: *3RDPARTY_DIR*
1412. Path to a particular 3rd-party library: *3RDPARTY_\<PRODUCT\>_DIR*
5c573e69 1423. Paths to headers and binaries:
9f33b387 143 1. *3RDPARTY_\<PRODUCT\>_INCLUDE_DIR*
144 2. *3RDPARTY_\<PRODUCT\>_LIBRARY_DIR*
145 3. *3RDPARTY_\<PRODUCT\>_DLL_DIR*
e5bd0d98 146
316d77d9 147If a variable of any level is not defined (empty or <i> \<variable name\>-NOTFOUND </i>) and the upper level variable is defined, the content of the non-defined variable will be sought at the next configuration step. If search process at level 3 does not find the required files, it seeks in default places.
e5bd0d98 148
316d77d9 149If a search result (include path, or library path, or dll path) does not meet your expectations, you can change *3RDPARTY_\<PRODUCT\>_*_DIR variable*, clear (if they are not empty) *3RDPARTY_\<PRODUCT\>_DLL_DIR, 3RDPARTY_\<PRODUCT\>_INCLUDE_DIR* and 3RDPARTY_\<PRODUCT\>_LIBRARY_DIR variables (or clear one of them) and run the configuration process again.
5c573e69 150
576f8b11 151At this time the search will be performed in the newly identified directory
9f33b387 152and the result will be recorded to corresponding variables (replace old value if it is necessary).
e5bd0d98 153
576f8b11 154For example, (Linux case) *3RDPARTY_FREETYPE_DIR* variable
e5bd0d98 155
9f33b387 156 /PRODUCTS/maintenance/Mandriva2010/freetype-2.4.10
e5bd0d98 157
158can be changed to
159
9f33b387 160 /PRODUCTS/maintenance/Mandriva2010/freetype-2.5.3
e5bd0d98 161
316d77d9 162During the configuration process the related variables (*3RDPARTY_FREETYPE_DLL_DIR*, *3RDPARTY_FREETYPE_INCLUDE_DIR* and *3RDPARTY_FREETYPE_LIBRARY_DIR*) will be filled with new found values
e5bd0d98 163
316d77d9 164**Note**: The names of searched libraries and header files are hard-coded. If there is the need to change their names, change appropriate cmake variables (edit CMakeCache.txt file or edit in cmake-gui in advance mode) without reconfiguration: *3RDPARTY_\<PRODUCT\>_INCLUDE* for include, *3RDPARTY_\<PRODUCT\>_LIB* for library and *3RDPARTY_\<PRODUCT\>_DLL* for shared library.
e5bd0d98 165
316d77d9 166### OCCT Generation
e5bd0d98 167
316d77d9 168Once the configuration process is done, "Generate" button is used to prepare project files for the target IDE. In our exercise the Visual Studio solution will be automatically created in the buid directory.
234e52be 169
316d77d9 170### OCCT Building
e5bd0d98 171
576f8b11 172Go to the build folder, start the Visual Studio solution *OCCT.sln* and build it by clicking **Build -> Build Solution**.
173
316d77d9 174By default the build solution process skips the building of the INSTALL and Overview project.
e5bd0d98 175
316d77d9 176When the building process is finished build:
177* Overview project to generate OCCT overview documentation (if BUILD_DOC_OcctOverview variable is checked)
178* the *INSTALL* project to run **the installation process** [**insert link**].
e5bd0d98 179
316d77d9 180For this, right-click on the *Overview/INSTALL* project and select **Project Only -> Build Only** -> *Overview/INSTALL* in the solution explorer.
e5bd0d98 181
316d77d9 182## Installation process
e5bd0d98 183
316d77d9 184Installation is a process of extracting redistributable resources (binaries,include files etc) from the build directory into the installation one. The installation directory will be free of project files, intermediate object files and any other information related to the build routines.
e5bd0d98 185
316d77d9 186Normally you use the installation directory of OCCT to link against your specific application.
576f8b11 187
316d77d9 188the directory structure is follow:
189
190 data - data files for OCCT (brep, iges, stp)
191 doc - OCCT overview documentation in HTML format
192 inc - header files
193 samples - samples
194 src - all required source files for OCCT
195 tests - OCCT test suite
196 win32\vc10\bind - binary files (installed 3rdparties and occt)
197 \libd - libraries (installed 3rdparties and occt)
576f8b11 198
316d77d9 199**Note:** The above example is given for debug configuration. However, it is generally safe to use the same installation directory for the release build. In the latter case the contents of install directory will be enriched with subdirectories and files related to the release configuration. In particular, the binaries directory win64 will be expanded as
200follows:
576f8b11 201
316d77d9 202 \win32\vc10\bind
203 \libd
204 \bin
205 \lib
576f8b11 206
316d77d9 207If CMake installation flags are enabled for the 3-rd party products (e.g. INSTALL_FREETYPE), then the corresponding binaries will be copied to the same bin(d) and lib(d) directories together with the native binaries of OCCT. Such organization of libraries can be especially helpful if your OCCT-based software does not use itself the 3-rd parties of Open CASCADE Technology (thus, there is no sense to pack them into dedicated directories)
e5bd0d98 208
316d77d9 209The installation folder contains the scripts to run *DRAWEXE* (*draw.bat* or *draw.sh*), samples (if its were installed) and overview.html (short-cut for installed OCCT overview documentation).