0027022: Configuration, CMake - rename ungrouped variables to include them to the...
[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 # Solution folder property
35 set_property (GLOBAL PROPERTY USE_FOLDERS ON)
36
37 set (INSTALL_TEST_CASES OFF CACHE BOOL "${INSTALL_TEST_CASES_DESCR}")
38 # a single-configuration generator like the Makefile generator defines CMAKE_BUILD_TYPE variable
39 # check this variable and set if it's required
40 if (DEFINED CMAKE_BUILD_TYPE AND NOT CMAKE_BUILD_TYPE) # single-configuration generator.
41   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)
42 endif()
43
44 # enable extended messages of many OCCT algorithms
45 set (BUILD_WITH_DEBUG OFF CACHE BOOL "${BUILD_WITH_DEBUG_DESCR}")
46 if (BUILD_WITH_DEBUG)
47   add_definitions (-DOCCT_DEBUG)
48 endif()
49
50 # copy samples to install directory
51 set (INSTALL_SAMPLES OFF CACHE BOOL "${INSTALL_SAMPLES_DESCR}")
52
53 # install dir of the built project
54 set (INSTALL_DIR "" CACHE PATH "${INSTALL_DIR_DESCR}" )
55 set (CMAKE_INSTALL_PREFIX "${INSTALL_DIR}" CACHE INTERNAL "" FORCE )
56
57 set (BUILD_PATCH "" CACHE PATH "${BUILD_PATCH_DESCR}")
58
59 # the list of being built toolkits
60 set (BUILD_ADDITIONAL_TOOLKITS "" CACHE STRING "${BUILD_ADDITIONAL_TOOLKITS_DESCR}")
61 separate_arguments (BUILD_ADDITIONAL_TOOLKITS)
62
63 if (MSVC)
64   set (BUILD_MODULE_OcctMfcSamples OFF CACHE BOOL "${BUILD_MODULE_OcctMfcSamples_DESCR}")
65 endif()
66
67 # whether use optional 3rdparty or not
68 if (APPLE)
69   set (USE_GLX OFF CACHE BOOL "${USE_GLX_DESCR}")
70 endif()
71 if (WIN32)
72   set (USE_D3D OFF CACHE BOOL "${USE_D3D_DESCR}")
73 endif()
74
75 # include occt macros
76 OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/occt_macros")
77
78 # include the patched or original list of modules
79 # list <MODULENAME>_TOOLKITS is created foreach module and contains its toolkits
80 # list <OCCT_MODULES> will contain all modules
81 OCCT_MODULES_AND_TOOLKITS (OCCT_MODULES)
82
83 foreach (OCCT_MODULE ${OCCT_MODULES})
84   BUILD_MODULE (${OCCT_MODULE})
85 endforeach()
86
87 if (ANDROID AND BUILD_MODULE_Draw)
88   message (STATUS "Info. Draw module is turned off due to it is not supported on Android")
89   set (BUILD_MODULE_Draw OFF CACHE BOOL "${BUILD_MODULE_Draw_DESCR}" FORCE)
90 endif()
91
92 # Overview
93 set (BUILD_DOC_OcctOverview OFF CACHE BOOL "${BUILD_DOC_OcctOverview_DESCR}")
94
95 if (NOT USE_D3D)
96   list (REMOVE_ITEM Visualization_TOOLKITS TKD3DHost)
97 endif()
98
99 # accumulate used toolkits (first level) in BUILD_TOOLKITS variable
100 list (APPEND BUILD_TOOLKITS ${BUILD_ADDITIONAL_TOOLKITS})
101
102 foreach (OCCT_MODULE ${OCCT_MODULES})
103   if (BUILD_MODULE_${OCCT_MODULE})
104     list (APPEND BUILD_TOOLKITS ${${OCCT_MODULE}_TOOLKITS})
105   endif()
106 endforeach()
107
108 # DRAWEXE excluded when library build is static
109 if (NOT BUILD_SHARED_LIBS)
110   list (REMOVE_ITEM BUILD_TOOLKITS DRAWEXE)
111   message (STATUS "Info: DRAWEXE is not included due to ${BUILD_LIBRARY_TYPE} build library type")
112 endif()
113
114 # accumulate all used toolkits
115 list (REMOVE_DUPLICATES BUILD_TOOLKITS)
116 set (RAW_BUILD_TOOLKITS)
117 foreach(BUILD_TOOLKIT ${BUILD_TOOLKITS})
118   OCCT_TOOLKIT_FULL_DEP (${BUILD_TOOLKIT} TOOLKIT_FULL_DEPS)
119   list (APPEND RAW_BUILD_TOOLKITS ${BUILD_TOOLKIT} ${TOOLKIT_FULL_DEPS})
120 endforeach()
121
122 list (REMOVE_DUPLICATES RAW_BUILD_TOOLKITS)
123 set (BUILD_TOOLKITS ${RAW_BUILD_TOOLKITS})
124
125 # include the patched or original list of definitions and flags
126 OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/occt_defs_flags")
127
128 OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/3rdparty_macro")
129
130 # search for TKIVtk and TKIVtkDraw in BUILD_TOOLKITS
131 list (FIND BUILD_TOOLKITS TKIVtk CAN_USE_VTK)
132 if (CAN_USE_VTK EQUAL -1)
133   list (FIND BUILD_TOOLKITS TKIVtkDraw CAN_USE_VTK)
134 endif()
135
136 if (NOT CAN_USE_VTK EQUAL -1)
137   if (NOT DEFINED USE_VTK)
138     set (USE_VTK OFF CACHE BOOL "${USE_VTK_DESCR}")
139   endif()
140 else()
141   OCCT_CHECK_AND_UNSET (USE_VTK)
142 endif()
143
144 # Rebuild *.yacc and *.lex files that are contained by TKMath toolkit
145 list (FIND BUILD_TOOLKITS TKMath   CAN_REBUILD_PDC_FOR_TKMATH)
146 list (FIND BUILD_TOOLKITS StepFile CAN_REBUILD_PDC_FOR_STEPFILE)
147
148 if (NOT ${CAN_REBUILD_PDC_FOR_TKMATH} EQUAL -1 OR NOT ${CAN_REBUILD_PDC_FOR_STEPFILE} EQUAL -1)
149   set (BUILD_YACCLEX OFF CACHE BOOL "${BUILD_YACCLEX_DESCR}")
150 else()
151   OCCT_CHECK_AND_UNSET (BUILD_YACCLEX)
152 endif()
153
154 if (NOT DEFINED 3RDPARTY_DIR)
155   set (3RDPARTY_DIR "" CACHE PATH ${3RDPARTY_DIR_DESCR})
156   get_filename_component (3RDPARTY_DIR "${3RDPARTY_DIR}" ABSOLUTE)
157 endif()
158
159 # search for CSF_TclLibs variable in EXTERNLIB of each being used toolkit
160 OCCT_IS_PRODUCT_REQUIRED (CSF_TclLibs USE_TCL)
161
162 if (USE_TCL)
163   message (STATUS "Info: TCL is used by OCCT")
164   OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/tcl")
165   
166   message (STATUS "Info: TK is used by OCCT")
167   OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/tk")
168 else()
169   OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_TCL")
170   OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_TK")
171
172   OCCT_CHECK_AND_UNSET ("INSTALL_TCL")
173   OCCT_CHECK_AND_UNSET ("INSTALL_TK")
174 endif()
175
176 # search for CSF_FREETYPE variable in EXTERNLIB of each being used toolkit
177 OCCT_IS_PRODUCT_REQUIRED (CSF_FREETYPE USE_FREETYPE)
178
179 if (USE_FREETYPE)
180   message (STATUS "Info: Freetype is used by OCCT")
181   OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/freetype")
182 else()
183   OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_FREETYPE")
184   OCCT_CHECK_AND_UNSET ("3RDPARTY_FREETYPE_INCLUDE_DIR_freetype2")
185   OCCT_CHECK_AND_UNSET ("3RDPARTY_FREETYPE_INCLUDE_DIR_ft2build")
186   OCCT_CHECK_AND_UNSET ("INSTALL_FREETYPE")
187 endif()
188
189 # VTK
190 if (USE_VTK)
191   add_definitions (-DHAVE_VTK)
192   OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/vtk")
193 else()
194   OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_VTK")
195   
196   if (NOT CAN_USE_VTK EQUAL -1)
197     message (STATUS "Info: TKIVtk and TKIVtkDraw toolkits excluded due to VTK usage is disabled")
198
199     list (REMOVE_ITEM BUILD_TOOLKITS TKIVtk)
200     list (REMOVE_ITEM BUILD_TOOLKITS TKIVtkDraw)
201   endif()
202 endif()
203
204 # D3D
205 if (USE_D3D)
206   add_definitions (-DHAVE_D3D)
207   #if(MSVC_VERSION LESS 1700)
208   #OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/d3d")
209   #endif()
210 endif()
211
212 # GLX
213 if (USE_GLX)
214   add_definitions (-DMACOSX_USE_GLX)
215   OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/glx")
216 endif()
217
218 # FREEIMAGE
219 # search for CSF_FREEIMAGE variable in EXTERNLIB of each being used toolkit
220 OCCT_IS_PRODUCT_REQUIRED (CSF_FREEIMAGE     CAN_USE_FREEIMAGE)
221 OCCT_IS_PRODUCT_REQUIRED (CSF_FreeImagePlus CAN_USE_FREEIMAGEPLUS)
222
223 if (CAN_USE_FREEIMAGE OR CAN_USE_FREEIMAGEPLUS)
224   set (USE_FREEIMAGE OFF CACHE BOOL "${USE_FREEIMAGE_DESCR}")
225
226   if (USE_FREEIMAGE)
227     add_definitions (-DHAVE_FREEIMAGE)
228     OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/freeimage")
229     OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/freeimageplus")
230   else()
231     OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_FREEIMAGE")
232     OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_FREEIMAGEPLUS")
233     OCCT_CHECK_AND_UNSET ("INSTALL_FREEIMAGE")
234     OCCT_CHECK_AND_UNSET ("INSTALL_FREEIMAGEPLUS")
235   endif()
236 else()
237   OCCT_CHECK_AND_UNSET ("USE_FREEIMAGE")
238
239   OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_FREEIMAGE")
240   OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_FREEIMAGEPLUS")
241   OCCT_CHECK_AND_UNSET ("INSTALL_FREEIMAGE")
242   OCCT_CHECK_AND_UNSET ("INSTALL_FREEIMAGEPLUS")
243 endif()
244
245 # GL2PS
246 # search for CSF_GL2PS variable in EXTERNLIB of each being used toolkit
247 OCCT_IS_PRODUCT_REQUIRED (CSF_GL2PS CAN_USE_GL2PS)
248
249 if (NOT DEFINED ANDROID AND CAN_USE_GL2PS)
250   set (USE_GL2PS OFF CACHE BOOL "${USE_GL2PS_DESCR}")
251
252   if (USE_GL2PS)
253     add_definitions (-DHAVE_GL2PS)
254     OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/gl2ps")
255   else()
256     OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_GL2PS")
257     OCCT_CHECK_AND_UNSET ("INSTALL_GL2PS")
258   endif()
259 else()
260   OCCT_CHECK_AND_UNSET ("USE_GL2PS")
261
262   OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_GL2PS")
263   OCCT_CHECK_AND_UNSET ("INSTALL_GL2PS")
264 endif()
265
266 # TBB
267 # search for CSF_TBB variable in EXTERNLIB of each being used toolkit
268 OCCT_IS_PRODUCT_REQUIRED (CSF_TBB CAN_USE_TBB)
269
270 if (NOT DEFINED ANDROID AND CAN_USE_TBB)
271   set (USE_TBB OFF CACHE BOOL "${USE_TBB_DESCR}")
272
273   if (USE_TBB)
274     add_definitions (-DHAVE_TBB)
275     OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/tbb")
276   else()
277     OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_TBB")
278     OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_TBBMALLOC")
279     OCCT_CHECK_AND_UNSET ("INSTALL_TBB")
280   endif()
281 else()
282   OCCT_CHECK_AND_UNSET ("USE_TBB")
283
284   OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_TBB")
285   OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_TBBMALLOC")
286   OCCT_CHECK_AND_UNSET ("INSTALL_TBB")
287 endif()
288
289 # Doxygen
290 if (BUILD_DOC_OcctOverview)
291   if (NOT DEFINED INSTALL_DOC_OcctOverview)
292     set (INSTALL_DOC_OcctOverview OFF CACHE BOOL "${INSTALL_DOC_OcctOverview_DESCR}")
293   endif()
294
295   if (INSTALL_DOC_OcctOverview)
296     install (DIRECTORY "${CMAKE_BINARY_DIR}/doc/overview" DESTINATION  "${INSTALL_DIR}/doc")
297
298     OCCT_INSTALL_FILE_OR_DIR ("dox/resources/overview.html" "${INSTALL_DIR}")
299   endif()
300
301   OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/doxygen")
302 else()
303   OCCT_CHECK_AND_UNSET ("INSTALL_DOC_OcctOverview")
304
305   OCCT_CHECK_AND_UNSET ("3RDPARTY_DOXYGEN_EXECUTABLE")
306   OCCT_CHECK_AND_UNSET ("3RDPARTY_DOT_EXECUTABLE")
307 endif()
308
309 # bison 
310 if (BUILD_YACCLEX)
311   OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/bison")
312 else()
313   OCCT_CHECK_AND_UNSET ("3RDPARTY_BISON_EXECUTABLE")
314 endif()
315
316 # flex 
317 if (BUILD_YACCLEX)
318   OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/flex")
319 else()
320   OCCT_CHECK_AND_UNSET ("3RDPARTY_FLEX_EXECUTABLE")
321 endif()
322
323 string (REGEX REPLACE ";" " " 3RDPARTY_NOT_INCLUDED "${3RDPARTY_NOT_INCLUDED}")
324
325 # check all 3rdparty paths
326 if (3RDPARTY_NOT_INCLUDED)
327   message (FATAL_ERROR "NOT FOUND: ${3RDPARTY_NOT_INCLUDED}" )
328 endif()
329
330 if (3RDPARTY_INCLUDE_DIRS)
331   list (REMOVE_DUPLICATES 3RDPARTY_INCLUDE_DIRS)
332   string (REGEX REPLACE ";" "\n\t" 3RDPARTY_INCLUDE_DIRS_WITH_ENDS "${3RDPARTY_INCLUDE_DIRS}")
333   message (STATUS "Info: The directories of 3rdparty headers: ${3RDPARTY_INCLUDE_DIRS_WITH_ENDS}")
334   include_directories (${3RDPARTY_INCLUDE_DIRS})
335 endif()
336
337 # include <cmake binary folder>/inc
338 include_directories (${CMAKE_BINARY_DIR}/inc)
339
340 if (3RDPARTY_LIBRARY_DIRS)
341   list (REMOVE_DUPLICATES 3RDPARTY_LIBRARY_DIRS)
342   string (REGEX REPLACE ";" "\n\t" 3RDPARTY_LIBRARY_DIRS_WITH_ENDS "${3RDPARTY_LIBRARY_DIRS}")
343   message (STATUS "Info: The directories of 3rdparty libraries: ${3RDPARTY_LIBRARY_DIRS_WITH_ENDS}")
344   link_directories (${3RDPARTY_LIBRARY_DIRS})
345 endif()
346
347 # Get all used variables: OS_WITH_BIT, COMPILER
348 OCCT_MAKE_OS_WITH_BITNESS()
349 OCCT_MAKE_COMPILER_SHORT_NAME()
350
351 # build directories
352 set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/lib")
353 set (CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/bin")
354 set (CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/lib")
355
356 set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/libi")
357 set (CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/bini")
358 set (CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/libi")
359
360 set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/libd")
361 set (CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/bind")
362 set (CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/libd")
363
364 if (WIN32) 
365   set (CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE        "${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/bin")
366   set (CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/bini")
367   set (CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG          "${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/bind")
368 endif()
369
370 if ("${INSTALL_DIR}" STREQUAL "")
371   get_filename_component (CMAKE_BINARY_DIR_PARENT ${CMAKE_BINARY_DIR} DIRECTORY)
372
373   set (INSTALL_DIR "${CMAKE_BINARY_DIR_PARENT}/install" CACHE PATH "${INSTALL_DIR_DESCR}" FORCE)
374   set (CMAKE_INSTALL_PREFIX "${INSTALL_DIR}" CACHE INTERNAL "" FORCE )
375
376   message (STATUS "Info: INSTALL_DIR has been set as ${INSTALL_DIR}")
377 endif()
378
379 string(TIMESTAMP CURRENT_TIME "%H:%M:%S")
380 message (STATUS "\nInfo: \(${CURRENT_TIME}\) Start collecting all OCCT header files into ${CMAKE_BINARY_DIR}/inc ...")
381
382 # collect all the headers to <binary dir>/inc folder
383 COLLECT_AND_INSTALL_OCCT_HEADER_FILES ("${CMAKE_BINARY_DIR}" "${BUILD_TOOLKITS}")
384
385 string(TIMESTAMP CURRENT_TIME "%H:%M:%S")
386 message (STATUS "Info: \(${CURRENT_TIME}\) End the collecting")
387
388 OCCT_INSTALL_FILE_OR_DIR ("data" "${INSTALL_DIR}")
389 OCCT_INSTALL_FILE_OR_DIR ("samples/tcl" "${INSTALL_DIR}/samples")
390
391 if (INSTALL_SAMPLES)
392   OCCT_INSTALL_FILE_OR_DIR ("samples" "${INSTALL_DIR}")
393 endif()
394
395 if (INSTALL_TEST_CASES)
396   OCCT_INSTALL_FILE_OR_DIR ("tests" "${INSTALL_DIR}")
397 endif()
398
399 if (WIN32)
400   set (SCRIPT_EXT bat)
401 else()
402   set (SCRIPT_EXT sh)
403 endif()
404
405 # DRAW.BAT or DRAW.SH
406 if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/adm/templates/draw.${SCRIPT_EXT}")
407   install (FILES "${BUILD_PATCH}/adm/templates/draw.${SCRIPT_EXT}" DESTINATION  "${INSTALL_DIR}" PERMISSIONS
408           OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_WRITE GROUP_EXECUTE WORLD_READ WORLD_WRITE WORLD_EXECUTE)
409 else()
410   install (FILES "${CMAKE_SOURCE_DIR}/adm/templates/draw.${SCRIPT_EXT}" DESTINATION  "${INSTALL_DIR}" PERMISSIONS
411           OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_WRITE GROUP_EXECUTE WORLD_READ WORLD_WRITE WORLD_EXECUTE)
412 endif()
413 OCCT_COPY_FILE_OR_DIR ("adm/templates/draw.${SCRIPT_EXT}" "${CMAKE_BINARY_DIR}")
414
415 set (SUB_CUSTOM_NAME "custom_${COMPILER}_${COMPILER_BITNESS}.${SCRIPT_EXT}")
416
417 if (WIN32)
418   set (ADDITIONAL_CUSTOM_CONTENT "\nif exist \"%~dp0${SUB_CUSTOM_NAME}\" (\n  call \"%~dp0${SUB_CUSTOM_NAME}\" %VCVER% %ARCH% %CASDEB% \n)")
419 else()
420   set (ADDITIONAL_CUSTOM_CONTENT "\nif [ -e \"\${aScriptPath}/${SUB_CUSTOM_NAME}\" ]; then\n  source \"\${aScriptPath}/${SUB_CUSTOM_NAME}\" \"\${COMPILER}\" \"\${WOKSTATION}\${ARCH}\" \"\${CASDEB}\" \nfi")
421 endif()
422
423  # change custom.bat/sh
424 if (EXISTS "${INSTALL_DIR}/custom.${SCRIPT_EXT}")
425   file (READ "${INSTALL_DIR}/custom.${SCRIPT_EXT}" CUSTOM_CONTENT)
426
427   set (CUSTOM_CONTENT "${CUSTOM_CONTENT} ${ADDITIONAL_CUSTOM_CONTENT}")
428
429   file (WRITE "${INSTALL_DIR}/custom.${SCRIPT_EXT}" "${CUSTOM_CONTENT}")
430 else()
431   OCCT_CONFIGURE_AND_INSTALL ("adm/templates/custom.${SCRIPT_EXT}.main" "custom.${SCRIPT_EXT}" "custom.${SCRIPT_EXT}" "${INSTALL_DIR}")
432 endif()
433
434 # write current custom.bat/sh (for install directory)
435 set (SUB_CUSTOM_BUILD_NAME "custom_${COMPILER}_${COMPILER_BITNESS}.install.${SCRIPT_EXT}")
436 OCCT_CONFIGURE_AND_INSTALL ("adm/templates/custom.install.${SCRIPT_EXT}.in" "${SUB_CUSTOM_BUILD_NAME}" "${SUB_CUSTOM_NAME}" "${INSTALL_DIR}")
437
438 # write current custom.bat/sh (for build directory)
439 OCCT_CONFIGURE ("adm/templates/custom.build.${SCRIPT_EXT}.in" "${SUB_CUSTOM_NAME}")
440
441 if (BUILD_MODULE_OcctMfcSamples)
442   OCCT_INSTALL_FILE_OR_DIR ("adm/templates/sample.bat" "${INSTALL_DIR}")
443   OCCT_COPY_FILE_OR_DIR    ("adm/templates/sample.bat" "${CMAKE_BINARY_DIR}")
444 endif()
445
446 # env script for draw in building environment
447 OCCT_CONFIGURE ("adm/templates/env.build.${SCRIPT_EXT}.in" "env.${SCRIPT_EXT}")
448
449 # end script for draw in standalone environment
450 # release version
451 set (BUILD_LETTER "")
452 OCCT_CONFIGURE ("adm/templates/env.install.${SCRIPT_EXT}.in" "env.install.release.${SCRIPT_EXT}")
453 install (FILES "${CMAKE_BINARY_DIR}/env.install.release.${SCRIPT_EXT}" 
454          CONFIGURATIONS Release
455          DESTINATION  "${INSTALL_DIR}"
456          RENAME "env.${SCRIPT_EXT}")
457
458 # debug version
459 set (BUILD_LETTER "d")
460 OCCT_CONFIGURE ("adm/templates/env.install.${SCRIPT_EXT}.in" "env.install.debug.${SCRIPT_EXT}")
461 install (FILES "${CMAKE_BINARY_DIR}/env.install.debug.${SCRIPT_EXT}" 
462          CONFIGURATIONS Debug
463          DESTINATION  "${INSTALL_DIR}"
464          RENAME "env.${SCRIPT_EXT}")
465
466 # release with debug info version
467 set (BUILD_LETTER "i")
468 OCCT_CONFIGURE ("adm/templates/env.install.${SCRIPT_EXT}.in" "env.install.relwithdebinfo.${SCRIPT_EXT}")
469 install (FILES "${CMAKE_BINARY_DIR}/env.install.relwithdebinfo.${SCRIPT_EXT}" 
470          CONFIGURATIONS RelWithDebInfo
471          DESTINATION  "${INSTALL_DIR}"
472          RENAME "env.${SCRIPT_EXT}")
473
474 # copy DrawAppliInit from OCCT source to build directory
475 if (NOT EXISTS "${CMAKE_BINARY_DIR}/DrawAppliInit")
476   OCCT_COPY_FILE_OR_DIR (DrawAppliInit "${CMAKE_BINARY_DIR}")
477 endif()
478
479 # RESOURCES
480 FILE_TO_LIST ("adm/RESOURCES" RESOURCES)
481 foreach(RESOURCE ${RESOURCES})
482   get_filename_component(RESOURCE_FOLDER ${RESOURCE} DIRECTORY)
483   if(NOT "${RESOURCE_FOLDER}" STREQUAL "")
484     get_filename_component(RESOURCE_FOLDER ${RESOURCE_FOLDER} NAME)
485     OCCT_INSTALL_FILE_OR_DIR ("src/${RESOURCE}" "${INSTALL_DIR}/src/${RESOURCE_FOLDER}")
486   else()
487     OCCT_INSTALL_FILE_OR_DIR ("src/${RESOURCE}" "${INSTALL_DIR}/src")
488   endif()
489 endforeach()
490
491 # define CSF variable
492 OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/occt_csf")
493
494 # include patched toolkit projects or original ones
495 foreach (BUILD_TOOLKIT ${BUILD_TOOLKITS})
496   OCCT_ADD_SUBDIRECTORY ("src/${BUILD_TOOLKIT}")
497 endforeach()
498
499 if (BUILD_DOC_OcctOverview)
500   OCCT_ADD_SUBDIRECTORY (dox)
501 endif()
502
503 # patch DRAWEXE
504 if (MSVC AND 3RDPARTY_DLL_DIRS)
505   list (FIND BUILD_TOOLKITS DRAWEXE DRAWEXE_INDEX)
506   if (${DRAWEXE_INDEX} GREATER -1)
507     list (REMOVE_DUPLICATES 3RDPARTY_DLL_DIRS)
508     set (3RDPARTY_DLL_DIRS_FOR_PATH "")
509
510     foreach (3RDPARTY_DLL_DIR ${3RDPARTY_DLL_DIRS})
511       set (3RDPARTY_DLL_DIRS_FOR_PATH "${3RDPARTY_DLL_DIRS_FOR_PATH};${3RDPARTY_DLL_DIR}")
512     endforeach()
513
514     OCCT_MAKE_COMPILER_BITNESS()
515     set (X_COMPILER_BITNESS "x64")
516     if ("${COMPILER_BITNESS}" STREQUAL "32")
517       set (X_COMPILER_BITNESS "Win32")
518     endif()
519
520     OCCT_CONFIGURE ("adm/templates/DRAWEXE.vcxproj.user.in" "${CMAKE_BINARY_DIR}/src/DRAWEXE/DRAWEXE.vcxproj.user")
521   endif()
522 endif()
523
524 # samples do not support patch usage
525 if (BUILD_MODULE_OcctMfcSamples)
526   set (OCCT_ROOT ${CMAKE_SOURCE_DIR})
527
528   set (MFC_STANDARD_SAMPLES_DIR ${OCCT_ROOT}/samples/mfc/standard)
529   set (COMMON_WINMAIN_FILE      ${MFC_STANDARD_SAMPLES_DIR}/Common/Winmain.cpp)
530
531   add_subdirectory(samples/mfc/standard/mfcsample)
532   add_subdirectory(samples/mfc/standard/01_Geometry)
533   add_subdirectory(samples/mfc/standard/02_Modeling)
534   add_subdirectory(samples/mfc/standard/03_Viewer2d)
535   add_subdirectory(samples/mfc/standard/04_Viewer3d)
536   add_subdirectory(samples/mfc/standard/05_ImportExport)
537   add_subdirectory(samples/mfc/standard/06_Ocaf)
538   add_subdirectory(samples/mfc/standard/07_Triangulation)
539   add_subdirectory(samples/mfc/standard/08_HLR)
540   add_subdirectory(samples/mfc/standard/09_Animation)
541   add_subdirectory(samples/mfc/standard/10_Convert)
542 endif()