INSTALL_DIR is synced with CMAKE_INSTALL_PREFIX . Change of any of these vars resets...
[occt.git] / CMakeLists.txt
1 cmake_minimum_required (VERSION 2.8.12 FATAL_ERROR)
2
3 set (CMAKE_SUPPRESS_REGENERATION TRUE)
4
5 set (CMAKE_CONFIGURATION_TYPES Release Debug RelWithDebInfo CACHE INTERNAL "" FORCE)
6
7 # macro: include patched file if it exists
8 macro (OCCT_INCLUDE_CMAKE_FILE BEING_INCLUDED_FILE)
9   if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/${BEING_INCLUDED_FILE}.cmake")
10     include (${BUILD_PATCH}/${BEING_INCLUDED_FILE}.cmake)
11   else()
12     include (${CMAKE_SOURCE_DIR}/${BEING_INCLUDED_FILE}.cmake)
13   endif()
14 endmacro()
15
16 # include variable description
17 OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/vardescr")
18
19 # set type of OCCT libraries
20 if (NOT BUILD_LIBRARY_TYPE)
21   set (BUILD_LIBRARY_TYPE "Shared" CACHE STRING "${BUILD_LIBRARY_TYPE_DESCR}" FORCE)
22   SET_PROPERTY(CACHE BUILD_LIBRARY_TYPE PROPERTY STRINGS Shared Static)
23 endif()
24
25 if ("${BUILD_LIBRARY_TYPE}" STREQUAL "Shared")
26   set (BUILD_SHARED_LIBS ON)
27 else()
28   unset (BUILD_SHARED_LIBS)
29 endif()
30
31 # the name of the project
32 project (OCCT)
33
34 # include occt macros
35 OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/occt_macros")
36
37 # Solution folder property
38 set_property (GLOBAL PROPERTY USE_FOLDERS ON)
39
40 # get current OCCT version
41 OCC_VERSION (OCC_VERSION_MAJOR OCC_VERSION_MINOR OCC_VERSION_MAINTENANCE OCC_VERSION_DEVELOPMENT OCC_VERSION_STRING_EXT)
42
43 set_property (GLOBAL PROPERTY OCC_VERSION_MAJOR ${OCC_VERSION_MAJOR})
44 set_property (GLOBAL PROPERTY OCC_VERSION_MINOR ${OCC_VERSION_MINOR})
45 set_property (GLOBAL PROPERTY OCC_VERSION_MAINTENANCE ${OCC_VERSION_MAINTENANCE})
46
47 set (INSTALL_TEST_CASES OFF CACHE BOOL "${INSTALL_TEST_CASES_DESCR}")
48
49 # single-configuration generator
50 set (SINGLE_GENERATOR OFF)
51 if (CMAKE_BUILD_TYPE)
52   set (SINGLE_GENERATOR ON)
53 endif()
54
55 # a single-configuration generator like the Makefile generator defines CMAKE_BUILD_TYPE variable
56 # check this variable and set if it's required
57 if (DEFINED CMAKE_BUILD_TYPE AND NOT CMAKE_BUILD_TYPE) # single-configuration generator.
58   set (CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." FORCE)
59 endif()
60
61 # enable extended messages of many OCCT algorithms
62 set (BUILD_WITH_DEBUG OFF CACHE BOOL "${BUILD_WITH_DEBUG_DESCR}")
63 if (BUILD_WITH_DEBUG)
64   add_definitions (-DOCCT_DEBUG)
65 endif()
66
67 # copy samples to install directory
68 set (INSTALL_SAMPLES OFF CACHE BOOL "${INSTALL_SAMPLES_DESCR}")
69
70 # install dir of the project
71 if (NOT DEFINED INSTALL_DIR)
72   set (INSTALL_DIR "${CMAKE_INSTALL_PREFIX}" CACHE PATH "${INSTALL_DIR_DESCR}")
73 endif()
74
75 if (NOT DEFINED CMAKE_INSTALL_PREFIX_PREV)
76   set (CMAKE_INSTALL_PREFIX_PREV "${CMAKE_INSTALL_PREFIX}" CACHE INTERNAL "" FORCE)
77 elseif (NOT "${CMAKE_INSTALL_PREFIX_PREV}" STREQUAL "${CMAKE_INSTALL_PREFIX}")
78   # CMAKE_INSTALL_PREFIX has been changed at previous step
79   set (CMAKE_INSTALL_PREFIX_PREV "${CMAKE_INSTALL_PREFIX}" CACHE INTERNAL "" FORCE)
80   
81   # INSTALL_DIR is required to be updated
82   set (INSTALL_DIR "${CMAKE_INSTALL_PREFIX}" CACHE PATH "${INSTALL_DIR_DESCR}" FORCE)
83 endif()
84
85 if (NOT DEFINED INSTALL_DIR_PREV)
86   set (INSTALL_DIR_PREV "${INSTALL_DIR}" CACHE INTERNAL "" FORCE)
87 elseif (NOT "${INSTALL_DIR_PREV}" STREQUAL "${INSTALL_DIR}")
88   # INSTALL_DIR has been changed at previous step
89   set (INSTALL_DIR_PREV "${INSTALL_DIR}" CACHE INTERNAL "" FORCE)
90
91   # sync CMAKE_INSTALL_PREFIX with INSTALL_DIR 
92   set (CMAKE_INSTALL_PREFIX "${INSTALL_DIR}" CACHE INTERNAL "" FORCE)
93
94   # set CMAKE_INSTALL_PREFIX_PREV to avoid the reset of structure of the install folder 
95   set (CMAKE_INSTALL_PREFIX_PREV "${INSTALL_DIR}" CACHE INTERNAL "" FORCE)
96
97   # The structure of install folder should be reset
98   OCCT_CHECK_AND_UNSET (INSTALL_BIN_DIR)
99   OCCT_CHECK_AND_UNSET (INSTALL_SCRIPT_DIR)
100   OCCT_CHECK_AND_UNSET (INSTALL_LIB_DIR)
101   OCCT_CHECK_AND_UNSET (INSTALL_INCLUDE_DIR)
102   OCCT_CHECK_AND_UNSET (INSTALL_OCCT_RESOURCE_DIR)
103   OCCT_CHECK_AND_UNSET (INSTALL_SHARE_DIR)
104 endif()
105
106 # hide CMAKE_INSTALL_PREFIX from a user
107 set (CMAKE_INSTALL_PREFIX "${INSTALL_DIR}" CACHE INTERNAL "" FORCE)
108
109 set (BIN_LETTER "")
110 if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
111   set (BIN_LETTER "d")
112 elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo")
113   set (BIN_LETTER "i")
114 endif()
115
116 # Get all used variables: OS_WITH_BIT, COMPILER
117 OCCT_MAKE_OS_WITH_BITNESS()
118 OCCT_MAKE_COMPILER_SHORT_NAME()
119
120 # do not define INSTALL_BIN_DIR for win. 
121 # Leave library structure for win: <prefix>/win64/vc10/bin(d)
122 if (NOT DEFINED INSTALL_BIN_DIR)
123   if (UNIX)
124     set (INSTALL_BIN_DIR "${INSTALL_DIR}/bin" CACHE PATH "${INSTALL_BIN_DIR_DESCR}")
125   else()
126     if (SINGLE_GENERATOR)
127       set (INSTALL_BIN_DIR "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bin${BIN_LETTER}" CACHE PATH "${INSTALL_BIN_DIR_DESCR}")
128     endif()
129   endif()
130 endif()
131
132 # define folder contaning all shell/batch scripts
133 if (NOT DEFINED INSTALL_SCRIPT_DIR)
134   if (UNIX)
135     set (INSTALL_SCRIPT_DIR "${INSTALL_BIN_DIR}/opencascade-${OCC_VERSION_STRING_EXT}" CACHE PATH "${INSTALL_SCRIPT_DIR_DESCR}")
136   else()
137     set (INSTALL_SCRIPT_DIR "${INSTALL_DIR}" CACHE PATH "${INSTALL_SCRIPT_DIR_DESCR}")
138   endif()
139 endif()
140
141 # place the libraries to <prefix>/lib folder for unix and leave old structure for windows
142 if (NOT DEFINED INSTALL_LIB_DIR)
143   if (UNIX)
144     set (INSTALL_LIB_DIR "${INSTALL_DIR}/lib" CACHE PATH "${INSTALL_LIB_DIR_DESCR}")
145   else()
146     if (SINGLE_GENERATOR)
147       set (INSTALL_LIB_DIR "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/lib${BIN_LETTER}" CACHE PATH "${INSTALL_LIB_DIR_DESCR}")
148     endif()
149   endif()
150 endif()
151
152 # OCCT headers: <prefix>/inc for windows,
153 #               <prefix>/include/opencascade-7.0.0 for unix
154 if (NOT DEFINED INSTALL_INCLUDE_DIR)
155   if (UNIX)
156     set (INSTALL_INCLUDE_DIR "${INSTALL_DIR}/include/opencascade-${OCC_VERSION_STRING_EXT}" CACHE PATH "${INSTALL_INCLUDE_DIR_DESCR}")
157   else()
158     set (INSTALL_INCLUDE_DIR "${INSTALL_DIR}/inc" CACHE PATH "${INSTALL_INCLUDE_DIR_DESCR}")
159   endif()
160 endif()
161
162 # OCCT resources: <prefix>/src for windows,
163 #                 <prefix>/share/opencascade-7.0.0/resources for unix
164 if (NOT DEFINED INSTALL_OCCT_RESOURCE_DIR)
165   if (UNIX)
166     set (INSTALL_OCCT_RESOURCE_DIR "${INSTALL_DIR}/share/opencascade-${OCC_VERSION_STRING_EXT}/resoures" CACHE PATH "${INSTALL_OCCT_RESOURCE_DIR_DESCR}")
167   else()
168     set (INSTALL_OCCT_RESOURCE_DIR "${INSTALL_DIR}/src" CACHE PATH "${INSTALL_OCCT_RESOURCE_DIR_DESCR}")
169   endif()
170 endif()
171
172 # OCCT data
173 if (NOT DEFINED INSTALL_SHARE_DIR)
174   if (UNIX)
175     set (INSTALL_SHARE_DIR "${INSTALL_DIR}/share/opencascade-${OCC_VERSION_STRING_EXT}" CACHE PATH "${INSTALL_SHARE_DIR_DESCR}")
176   else()
177     set (INSTALL_SHARE_DIR "${INSTALL_DIR}" CACHE PATH "${INSTALL_SHARE_DIR_DESCR}")
178   endif()
179 endif()
180
181 # a directory recognized as a 'patch' for OCCT
182 set (BUILD_PATCH "" CACHE PATH "${BUILD_PATCH_DESCR}")
183
184 # the list of being built toolkits
185 set (BUILD_ADDITIONAL_TOOLKITS "" CACHE STRING "${BUILD_ADDITIONAL_TOOLKITS_DESCR}")
186 separate_arguments (BUILD_ADDITIONAL_TOOLKITS)
187
188 if (MSVC)
189   set (BUILD_MODULE_OcctMfcSamples OFF CACHE BOOL "${BUILD_MODULE_OcctMfcSamples_DESCR}")
190 endif()
191
192 # whether use optional 3rdparty or not
193 if (APPLE)
194   set (USE_GLX OFF CACHE BOOL "${USE_GLX_DESCR}")
195 endif()
196
197 if (WIN32)
198   set (USE_D3D OFF CACHE BOOL "${USE_D3D_DESCR}")
199 endif()
200
201 # include the patched or original list of modules
202 # list <MODULENAME>_TOOLKITS is created foreach module and contains its toolkits
203 # list <OCCT_MODULES> will contain all modules
204 OCCT_MODULES_AND_TOOLKITS (OCCT_MODULES)
205
206 foreach (OCCT_MODULE ${OCCT_MODULES})
207   BUILD_MODULE (${OCCT_MODULE})
208 endforeach()
209
210 if (ANDROID AND BUILD_MODULE_Draw)
211   message (STATUS "Info. Draw module is turned off due to it is not supported on Android")
212   set (BUILD_MODULE_Draw OFF CACHE BOOL "${BUILD_MODULE_Draw_DESCR}" FORCE)
213 endif()
214
215 # Overview
216 set (BUILD_DOC_OcctOverview OFF CACHE BOOL "${BUILD_DOC_OcctOverview_DESCR}")
217
218 if (NOT USE_D3D)
219   list (REMOVE_ITEM Visualization_TOOLKITS TKD3DHost)
220 endif()
221
222 # accumulate used toolkits (first level) in BUILD_TOOLKITS variable
223 list (APPEND BUILD_TOOLKITS ${BUILD_ADDITIONAL_TOOLKITS})
224
225 foreach (OCCT_MODULE ${OCCT_MODULES})
226   if (BUILD_MODULE_${OCCT_MODULE})
227     list (APPEND BUILD_TOOLKITS ${${OCCT_MODULE}_TOOLKITS})
228   endif()
229 endforeach()
230
231 # DRAWEXE excluded when library build is static
232 if (NOT BUILD_SHARED_LIBS)
233   list (REMOVE_ITEM BUILD_TOOLKITS DRAWEXE)
234   message (STATUS "Info: DRAWEXE is not included due to ${BUILD_LIBRARY_TYPE} build library type")
235 endif()
236
237 # accumulate all used toolkits
238 list (REMOVE_DUPLICATES BUILD_TOOLKITS)
239 set (RAW_BUILD_TOOLKITS)
240 foreach (BUILD_TOOLKIT ${BUILD_TOOLKITS})
241   OCCT_TOOLKIT_FULL_DEP (${BUILD_TOOLKIT} TOOLKIT_FULL_DEPS)
242   list (APPEND RAW_BUILD_TOOLKITS ${BUILD_TOOLKIT} ${TOOLKIT_FULL_DEPS})
243 endforeach()
244
245 list (REMOVE_DUPLICATES RAW_BUILD_TOOLKITS)
246 set (BUILD_TOOLKITS ${RAW_BUILD_TOOLKITS})
247
248 # include the patched or original list of definitions and flags
249 OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/occt_defs_flags")
250
251 OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/3rdparty_macro")
252
253 # search for TKIVtk and TKIVtkDraw in BUILD_TOOLKITS
254 list (FIND BUILD_TOOLKITS TKIVtk CAN_USE_VTK)
255 if (CAN_USE_VTK EQUAL -1)
256   list (FIND BUILD_TOOLKITS TKIVtkDraw CAN_USE_VTK)
257 endif()
258
259 if (NOT CAN_USE_VTK EQUAL -1)
260   if (NOT DEFINED USE_VTK)
261     set (USE_VTK OFF CACHE BOOL "${USE_VTK_DESCR}")
262   endif()
263 else()
264   OCCT_CHECK_AND_UNSET (USE_VTK)
265 endif()
266
267 # Rebuild *.yacc and *.lex files that are contained by TKMath toolkit
268 list (FIND BUILD_TOOLKITS TKMath   CAN_REBUILD_PDC_FOR_TKMATH)
269 list (FIND BUILD_TOOLKITS StepFile CAN_REBUILD_PDC_FOR_STEPFILE)
270
271 if (NOT ${CAN_REBUILD_PDC_FOR_TKMATH} EQUAL -1 OR NOT ${CAN_REBUILD_PDC_FOR_STEPFILE} EQUAL -1)
272   set (BUILD_YACCLEX OFF CACHE BOOL "${BUILD_YACCLEX_DESCR}")
273 else()
274   OCCT_CHECK_AND_UNSET (BUILD_YACCLEX)
275 endif()
276
277 if (NOT DEFINED 3RDPARTY_DIR)
278   set (3RDPARTY_DIR "" CACHE PATH ${3RDPARTY_DIR_DESCR})
279   get_filename_component (3RDPARTY_DIR "${3RDPARTY_DIR}" ABSOLUTE)
280 endif()
281
282 # search for CSF_TclLibs variable in EXTERNLIB of each being used toolkit
283 OCCT_IS_PRODUCT_REQUIRED (CSF_TclLibs USE_TCL)
284
285 if (USE_TCL)
286   message (STATUS "Info: TCL is used by OCCT")
287   OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/tcl")
288   
289   message (STATUS "Info: TK is used by OCCT")
290   OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/tk")
291 else()
292   OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_TCL")
293   OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_TK")
294
295   OCCT_CHECK_AND_UNSET ("INSTALL_TCL")
296   OCCT_CHECK_AND_UNSET ("INSTALL_TK")
297 endif()
298
299 # search for CSF_FREETYPE variable in EXTERNLIB of each being used toolkit
300 OCCT_IS_PRODUCT_REQUIRED (CSF_FREETYPE USE_FREETYPE)
301
302 if (USE_FREETYPE)
303   message (STATUS "Info: Freetype is used by OCCT")
304   OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/freetype")
305 else()
306   OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_FREETYPE")
307   OCCT_CHECK_AND_UNSET ("3RDPARTY_FREETYPE_INCLUDE_DIR_freetype2")
308   OCCT_CHECK_AND_UNSET ("3RDPARTY_FREETYPE_INCLUDE_DIR_ft2build")
309   OCCT_CHECK_AND_UNSET ("INSTALL_FREETYPE")
310 endif()
311
312 # VTK
313 if (USE_VTK)
314   add_definitions (-DHAVE_VTK)
315   OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/vtk")
316 else()
317   OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_VTK")
318   
319   if (NOT CAN_USE_VTK EQUAL -1)
320     message (STATUS "Info: TKIVtk and TKIVtkDraw toolkits excluded due to VTK usage is disabled")
321
322     list (REMOVE_ITEM BUILD_TOOLKITS TKIVtk)
323     list (REMOVE_ITEM BUILD_TOOLKITS TKIVtkDraw)
324   endif()
325 endif()
326
327 # D3D
328 if (USE_D3D)
329   add_definitions (-DHAVE_D3D)
330   #if(MSVC_VERSION LESS 1700)
331   #OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/d3d")
332   #endif()
333 endif()
334
335 # GLX
336 if (USE_GLX)
337   add_definitions (-DMACOSX_USE_GLX)
338   OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/glx")
339 endif()
340
341 # FREEIMAGE
342 # search for CSF_FREEIMAGE variable in EXTERNLIB of each being used toolkit
343 OCCT_IS_PRODUCT_REQUIRED (CSF_FREEIMAGE     CAN_USE_FREEIMAGE)
344 OCCT_IS_PRODUCT_REQUIRED (CSF_FreeImagePlus CAN_USE_FREEIMAGEPLUS)
345
346 if (CAN_USE_FREEIMAGE OR CAN_USE_FREEIMAGEPLUS)
347   set (USE_FREEIMAGE OFF CACHE BOOL "${USE_FREEIMAGE_DESCR}")
348
349   if (USE_FREEIMAGE)
350     add_definitions (-DHAVE_FREEIMAGE)
351     OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/freeimage")
352     OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/freeimageplus")
353   else()
354     OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_FREEIMAGE")
355     OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_FREEIMAGEPLUS")
356     OCCT_CHECK_AND_UNSET ("INSTALL_FREEIMAGE")
357     OCCT_CHECK_AND_UNSET ("INSTALL_FREEIMAGEPLUS")
358   endif()
359 else()
360   OCCT_CHECK_AND_UNSET ("USE_FREEIMAGE")
361
362   OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_FREEIMAGE")
363   OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_FREEIMAGEPLUS")
364   OCCT_CHECK_AND_UNSET ("INSTALL_FREEIMAGE")
365   OCCT_CHECK_AND_UNSET ("INSTALL_FREEIMAGEPLUS")
366 endif()
367
368 # GL2PS
369 # search for CSF_GL2PS variable in EXTERNLIB of each being used toolkit
370 OCCT_IS_PRODUCT_REQUIRED (CSF_GL2PS CAN_USE_GL2PS)
371
372 if (NOT DEFINED ANDROID AND CAN_USE_GL2PS)
373   set (USE_GL2PS OFF CACHE BOOL "${USE_GL2PS_DESCR}")
374
375   if (USE_GL2PS)
376     add_definitions (-DHAVE_GL2PS)
377     OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/gl2ps")
378   else()
379     OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_GL2PS")
380     OCCT_CHECK_AND_UNSET ("INSTALL_GL2PS")
381   endif()
382 else()
383   OCCT_CHECK_AND_UNSET ("USE_GL2PS")
384
385   OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_GL2PS")
386   OCCT_CHECK_AND_UNSET ("INSTALL_GL2PS")
387 endif()
388
389 # TBB
390 # search for CSF_TBB variable in EXTERNLIB of each being used toolkit
391 OCCT_IS_PRODUCT_REQUIRED (CSF_TBB CAN_USE_TBB)
392
393 if (NOT DEFINED ANDROID AND CAN_USE_TBB)
394   set (USE_TBB OFF CACHE BOOL "${USE_TBB_DESCR}")
395
396   if (USE_TBB)
397     add_definitions (-DHAVE_TBB)
398     OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/tbb")
399   else()
400     OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_TBB")
401     OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_TBBMALLOC")
402     OCCT_CHECK_AND_UNSET ("INSTALL_TBB")
403   endif()
404 else()
405   OCCT_CHECK_AND_UNSET ("USE_TBB")
406
407   OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_TBB")
408   OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_TBBMALLOC")
409   OCCT_CHECK_AND_UNSET ("INSTALL_TBB")
410 endif()
411
412 # Doxygen
413 if (BUILD_DOC_OcctOverview)
414   if (NOT DEFINED INSTALL_DOC_OcctOverview)
415     set (INSTALL_DOC_OcctOverview OFF CACHE BOOL "${INSTALL_DOC_OcctOverview_DESCR}")
416   endif()
417
418   if (INSTALL_DOC_OcctOverview)
419     install (DIRECTORY "${CMAKE_BINARY_DIR}/doc/overview" DESTINATION  "${INSTALL_SHARE_DIR}/doc")
420
421     # create overview.html only for windows
422     if (WIN32)
423       OCCT_INSTALL_FILE_OR_DIR ("dox/resources/overview.html" "${INSTALL_SCRIPT_DIR}")
424     endif()
425   endif()
426
427   OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/doxygen")
428 else()
429   OCCT_CHECK_AND_UNSET ("INSTALL_DOC_OcctOverview")
430
431   OCCT_CHECK_AND_UNSET ("3RDPARTY_DOXYGEN_EXECUTABLE")
432   OCCT_CHECK_AND_UNSET ("3RDPARTY_DOT_EXECUTABLE")
433 endif()
434
435 # bison 
436 if (BUILD_YACCLEX)
437   OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/bison")
438 else()
439   OCCT_CHECK_AND_UNSET ("3RDPARTY_BISON_EXECUTABLE")
440 endif()
441
442 # flex 
443 if (BUILD_YACCLEX)
444   OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/flex")
445 else()
446   OCCT_CHECK_AND_UNSET ("3RDPARTY_FLEX_EXECUTABLE")
447 endif()
448
449 string (REGEX REPLACE ";" " " 3RDPARTY_NOT_INCLUDED "${3RDPARTY_NOT_INCLUDED}")
450
451 # check all 3rdparty paths
452 if (3RDPARTY_NOT_INCLUDED)
453   message (FATAL_ERROR "NOT FOUND: ${3RDPARTY_NOT_INCLUDED}" )
454 endif()
455
456 if (3RDPARTY_INCLUDE_DIRS)
457   list (REMOVE_DUPLICATES 3RDPARTY_INCLUDE_DIRS)
458   string (REGEX REPLACE ";" "\n\t" 3RDPARTY_INCLUDE_DIRS_WITH_ENDS "${3RDPARTY_INCLUDE_DIRS}")
459   message (STATUS "Info: The directories of 3rdparty headers: ${3RDPARTY_INCLUDE_DIRS_WITH_ENDS}")
460   include_directories (${3RDPARTY_INCLUDE_DIRS})
461 endif()
462
463 # include <cmake binary folder>/inc
464 include_directories (${CMAKE_BINARY_DIR}/inc)
465
466 if (3RDPARTY_LIBRARY_DIRS)
467   list (REMOVE_DUPLICATES 3RDPARTY_LIBRARY_DIRS)
468   string (REGEX REPLACE ";" "\n\t" 3RDPARTY_LIBRARY_DIRS_WITH_ENDS "${3RDPARTY_LIBRARY_DIRS}")
469   message (STATUS "Info: The directories of 3rdparty libraries: ${3RDPARTY_LIBRARY_DIRS_WITH_ENDS}")
470   link_directories (${3RDPARTY_LIBRARY_DIRS})
471 endif()
472
473 # build directories
474 set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/lib")
475 set (CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/bin")
476 set (CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/lib")
477
478 set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/libi")
479 set (CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/bini")
480 set (CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/libi")
481
482 set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/libd")
483 set (CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/bind")
484 set (CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/libd")
485
486 if (WIN32) 
487   set (CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE        "${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/bin")
488   set (CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/bini")
489   set (CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG          "${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/bind")
490 endif()
491
492 string(TIMESTAMP CURRENT_TIME "%H:%M:%S")
493 message (STATUS "\nInfo: \(${CURRENT_TIME}\) Start collecting all OCCT header files into ${CMAKE_BINARY_DIR}/inc ...")
494
495 # collect all the headers to <binary dir>/inc folder
496 COLLECT_AND_INSTALL_OCCT_HEADER_FILES ("${CMAKE_BINARY_DIR}" "${BUILD_TOOLKITS}")
497
498 string(TIMESTAMP CURRENT_TIME "%H:%M:%S")
499 message (STATUS "Info: \(${CURRENT_TIME}\) End the collecting")
500
501 OCCT_INSTALL_FILE_OR_DIR ("data" "${INSTALL_SHARE_DIR}")
502
503 # OCCT samples
504 if (INSTALL_SAMPLES)
505   if (WIN32)
506     OCCT_INSTALL_FILE_OR_DIR ("samples/CSharp" "${INSTALL_SHARE_DIR}/samples")
507     OCCT_INSTALL_FILE_OR_DIR ("samples/mfc" "${INSTALL_SHARE_DIR}/samples")   
508   endif()
509   
510   OCCT_INSTALL_FILE_OR_DIR ("samples/java" "${INSTALL_SHARE_DIR}/samples")
511   OCCT_INSTALL_FILE_OR_DIR ("samples/ocafsamples" "${INSTALL_SHARE_DIR}/samples")
512   OCCT_INSTALL_FILE_OR_DIR ("samples/qt" "${INSTALL_SHARE_DIR}/samples")
513 endif()
514
515 OCCT_INSTALL_FILE_OR_DIR ("samples/tcl" "${INSTALL_SHARE_DIR}/samples")
516
517 if (INSTALL_TEST_CASES)
518   OCCT_INSTALL_FILE_OR_DIR ("tests" "${INSTALL_SHARE_DIR}")
519 endif()
520
521 if (WIN32)
522   set (SCRIPT_EXT bat)
523 else()
524   set (SCRIPT_EXT sh)
525 endif()
526
527 # copy draw script to install script folder
528 if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/adm/templates/draw.${SCRIPT_EXT}")
529   install (FILES "${BUILD_PATCH}/adm/templates/draw.${SCRIPT_EXT}" DESTINATION  "${INSTALL_SCRIPT_DIR}"
530           PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_WRITE GROUP_EXECUTE WORLD_READ WORLD_WRITE WORLD_EXECUTE)
531 else()
532   install (FILES "${CMAKE_SOURCE_DIR}/adm/templates/draw.${SCRIPT_EXT}" DESTINATION  "${INSTALL_SCRIPT_DIR}"
533           PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_WRITE GROUP_EXECUTE WORLD_READ WORLD_WRITE WORLD_EXECUTE)
534 endif()
535
536 # copy draw script to CMake binary folder
537 OCCT_COPY_FILE_OR_DIR ("adm/templates/draw.${SCRIPT_EXT}" "${CMAKE_BINARY_DIR}")
538
539 set (SUB_CUSTOM_NAME "custom_${COMPILER}_${COMPILER_BITNESS}.${SCRIPT_EXT}")
540
541 if (WIN32)
542   set (ADDITIONAL_CUSTOM_CONTENT "\nif exist \"%~dp0${SUB_CUSTOM_NAME}\" (\n  call \"%~dp0${SUB_CUSTOM_NAME}\" %VCVER% %ARCH% %CASDEB% \n)")
543 else()
544   set (ADDITIONAL_CUSTOM_CONTENT "\nif [ -e \"\${aScriptPath}/${SUB_CUSTOM_NAME}\" ]; then\n  source \"\${aScriptPath}/${SUB_CUSTOM_NAME}\" \"\$1\" \"\$2\" \nfi")
545 endif()
546
547  # change custom.bat/sh
548 if (EXISTS "${INSTALL_BIN_DIR}/custom.${SCRIPT_EXT}")
549   file (READ "${INSTALL_BIN_DIR}/custom.${SCRIPT_EXT}" CUSTOM_CONTENT)
550
551   set (CUSTOM_CONTENT "${CUSTOM_CONTENT} ${ADDITIONAL_CUSTOM_CONTENT}")
552
553   file (WRITE "${INSTALL_BIN_DIR}/custom.${SCRIPT_EXT}" "${CUSTOM_CONTENT}")
554 else()
555   OCCT_CONFIGURE_AND_INSTALL ("adm/templates/custom.${SCRIPT_EXT}.main" "custom.${SCRIPT_EXT}" "custom.${SCRIPT_EXT}" "${INSTALL_SCRIPT_DIR}")
556 endif()
557
558 # write current custom.bat/sh (for install directory)
559 set (SUB_CUSTOM_BUILD_NAME "custom_${COMPILER}_${COMPILER_BITNESS}.install.${SCRIPT_EXT}")
560 OCCT_CONFIGURE_AND_INSTALL ("adm/templates/custom.install.${SCRIPT_EXT}.in" "${SUB_CUSTOM_BUILD_NAME}" "${SUB_CUSTOM_NAME}" "${INSTALL_SCRIPT_DIR}")
561
562 # write current custom.bat/sh (for build directory)
563 OCCT_CONFIGURE ("adm/templates/custom.build.${SCRIPT_EXT}.in" "${SUB_CUSTOM_NAME}")
564
565 if (BUILD_MODULE_OcctMfcSamples)
566   OCCT_INSTALL_FILE_OR_DIR ("adm/templates/sample.bat" "${INSTALL_SCRIPT_DIR}")
567   OCCT_COPY_FILE_OR_DIR    ("adm/templates/sample.bat" "${CMAKE_BINARY_DIR}")
568 endif()
569
570 # env script for draw in building environment
571 OCCT_CONFIGURE ("adm/templates/env.build.${SCRIPT_EXT}.in" "env.${SCRIPT_EXT}")
572
573 # end script for draw in standalone environment
574 if (UNIX)
575   OCCT_CONFIGURE ("adm/templates/env.install.sh.in" "env.install.sh")
576   install (FILES "${CMAKE_BINARY_DIR}/env.install.sh" DESTINATION  "${INSTALL_SCRIPT_DIR}" RENAME "env.sh")
577 else()
578   # release version
579   set (CURRENT_BUILD_LETTER "")
580   OCCT_CONFIGURE ("adm/templates/env.install.bat.in" "env.install.release.bat")
581   install (FILES "${CMAKE_BINARY_DIR}/env.install.release.bat" 
582            CONFIGURATIONS Release
583            DESTINATION  "${INSTALL_SCRIPT_DIR}" RENAME "env.bat")
584
585   # debug version
586   set (CURRENT_BUILD_LETTER "d")
587   OCCT_CONFIGURE ("adm/templates/env.install.bat.in" "env.install.debug.bat")
588   install (FILES "${CMAKE_BINARY_DIR}/env.install.debug.bat" 
589            CONFIGURATIONS Debug
590            DESTINATION  "${INSTALL_SCRIPT_DIR}" RENAME "env.bat")
591
592   # release with debug info version
593   set (CURRENT_BUILD_LETTER "i")
594   OCCT_CONFIGURE ("adm/templates/env.install.bat.in" "env.install.relwithdebinfo.bat")
595   install (FILES "${CMAKE_BINARY_DIR}/env.install.relwithdebinfo.bat" 
596            CONFIGURATIONS RelWithDebInfo
597            DESTINATION  "${INSTALL_SCRIPT_DIR}" RENAME "env.bat")
598 endif()
599
600 # copy DrawAppliInit from OCCT source to build directory
601 if (NOT EXISTS "${CMAKE_BINARY_DIR}/DrawAppliInit")
602   OCCT_COPY_FILE_OR_DIR (DrawAppliInit "${CMAKE_BINARY_DIR}")
603 endif()
604
605 # RESOURCES
606 FILE_TO_LIST ("adm/RESOURCES" RESOURCES)
607 foreach(RESOURCE ${RESOURCES})
608   get_filename_component(RESOURCE_FOLDER ${RESOURCE} DIRECTORY)
609   if(NOT "${RESOURCE_FOLDER}" STREQUAL "")
610     get_filename_component(RESOURCE_FOLDER ${RESOURCE_FOLDER} NAME)
611     OCCT_INSTALL_FILE_OR_DIR ("src/${RESOURCE}" "${INSTALL_OCCT_RESOURCE_DIR}/${RESOURCE_FOLDER}")
612   else()
613     OCCT_INSTALL_FILE_OR_DIR ("src/${RESOURCE}" "${INSTALL_OCCT_RESOURCE_DIR}")
614   endif()
615 endforeach()
616
617 # define CSF variable
618 OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/occt_csf")
619
620 # include patched toolkit projects or original ones
621 foreach (BUILD_TOOLKIT ${BUILD_TOOLKITS})
622   OCCT_ADD_SUBDIRECTORY ("src/${BUILD_TOOLKIT}")
623 endforeach()
624
625 if (BUILD_DOC_OcctOverview)
626   OCCT_ADD_SUBDIRECTORY (dox)
627 endif()
628
629 # patch DRAWEXE
630 if (MSVC AND 3RDPARTY_DLL_DIRS)
631   list (FIND BUILD_TOOLKITS DRAWEXE DRAWEXE_INDEX)
632   if (${DRAWEXE_INDEX} GREATER -1)
633     list (REMOVE_DUPLICATES 3RDPARTY_DLL_DIRS)
634     set (3RDPARTY_DLL_DIRS_FOR_PATH "")
635
636     foreach (3RDPARTY_DLL_DIR ${3RDPARTY_DLL_DIRS})
637       set (3RDPARTY_DLL_DIRS_FOR_PATH "${3RDPARTY_DLL_DIRS_FOR_PATH};${3RDPARTY_DLL_DIR}")
638     endforeach()
639
640     OCCT_MAKE_COMPILER_BITNESS()
641     set (X_COMPILER_BITNESS "x64")
642     if ("${COMPILER_BITNESS}" STREQUAL "32")
643       set (X_COMPILER_BITNESS "Win32")
644     endif()
645
646     OCCT_CONFIGURE ("adm/templates/DRAWEXE.vcxproj.user.in" "${CMAKE_BINARY_DIR}/src/DRAWEXE/DRAWEXE.vcxproj.user")
647   endif()
648 endif()
649
650 # samples do not support patch usage
651 if (BUILD_MODULE_OcctMfcSamples)
652   set (OCCT_ROOT ${CMAKE_SOURCE_DIR})
653
654   set (MFC_STANDARD_SAMPLES_DIR ${OCCT_ROOT}/samples/mfc/standard)
655   set (COMMON_WINMAIN_FILE      ${MFC_STANDARD_SAMPLES_DIR}/Common/Winmain.cpp)
656
657   add_subdirectory(samples/mfc/standard/mfcsample)
658   add_subdirectory(samples/mfc/standard/01_Geometry)
659   add_subdirectory(samples/mfc/standard/02_Modeling)
660   add_subdirectory(samples/mfc/standard/03_Viewer2d)
661   add_subdirectory(samples/mfc/standard/04_Viewer3d)
662   add_subdirectory(samples/mfc/standard/05_ImportExport)
663   add_subdirectory(samples/mfc/standard/06_Ocaf)
664   add_subdirectory(samples/mfc/standard/07_Triangulation)
665   add_subdirectory(samples/mfc/standard/08_HLR)
666   add_subdirectory(samples/mfc/standard/09_Animation)
667   add_subdirectory(samples/mfc/standard/10_Convert)
668 endif()