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