0033378: Configuration - Moving ExpToCas into separate module
[occt.git] / CMakeLists.txt
1 cmake_minimum_required (VERSION 3.1 FATAL_ERROR)
2
3 set (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/adm/cmake")
4
5 set (CMAKE_SUPPRESS_REGENERATION TRUE)
6
7 set (CMAKE_CONFIGURATION_TYPES Release Debug RelWithDebInfo CACHE INTERNAL "" FORCE)
8
9 # set using C++ standard
10 set (BUILD_CPP_STANDARD "C++11" CACHE STRING "Select using c++ standard.")
11 set_property(CACHE BUILD_CPP_STANDARD PROPERTY STRINGS "C++11" "C++14" "C++17" "C++20" "C++23")
12
13 # Set desired C++ standard
14 if     ("${BUILD_CPP_STANDARD}" STREQUAL "C++11")
15   set (CMAKE_CXX_STANDARD 11)
16 elseif ("${BUILD_CPP_STANDARD}" STREQUAL "C++14")
17   set (CMAKE_CXX_STANDARD 14)
18 elseif ("${BUILD_CPP_STANDARD}" STREQUAL "C++17")
19   set (CMAKE_CXX_STANDARD 17)
20 elseif ("${BUILD_CPP_STANDARD}" STREQUAL "C++20")
21   set (CMAKE_CXX_STANDARD 20)
22 elseif ("${BUILD_CPP_STANDARD}" STREQUAL "C++23")
23   set (CMAKE_CXX_STANDARD 23)
24 else ()
25   message (FATAL_ERROR, "misprint in c++ standard name")
26 endif()
27 set (CMAKE_CXX_STANDARD_REQUIRED ON)
28
29 # macro: include patched file if it exists
30 macro (OCCT_INCLUDE_CMAKE_FILE BEING_INCLUDED_FILE)
31   if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/${BEING_INCLUDED_FILE}.cmake")
32     include (${BUILD_PATCH}/${BEING_INCLUDED_FILE}.cmake)
33   else()
34     include (${CMAKE_SOURCE_DIR}/${BEING_INCLUDED_FILE}.cmake)
35   endif()
36 endmacro()
37
38 # include variable description
39 OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/vardescr")
40
41 # set type of OCCT libraries
42 if (NOT BUILD_LIBRARY_TYPE)
43   set (BUILD_LIBRARY_TYPE "Shared" CACHE STRING "${BUILD_LIBRARY_TYPE_DESCR}" FORCE)
44   SET_PROPERTY(CACHE BUILD_LIBRARY_TYPE PROPERTY STRINGS Shared Static)
45 endif()
46
47 if ("${BUILD_LIBRARY_TYPE}" STREQUAL "Shared")
48   set (BUILD_SHARED_LIBS ON)
49
50   if (NOT DEFINED BUILD_SHARED_LIBRARY_NAME_POSTFIX)
51     set (BUILD_SHARED_LIBRARY_NAME_POSTFIX "" CACHE STRING "${BUILD_SHARED_LIBRARY_NAME_POSTFIX_DESCR}" FORCE)
52   endif()
53 else()
54   unset (BUILD_SHARED_LIBS)
55   unset (BUILD_SHARED_LIBRARY_NAME_POSTFIX)
56 endif()
57
58 # the name of the project
59 project (OCCT)
60
61 if (WIN32)
62   add_definitions(-DUNICODE)
63   add_definitions(-D_UNICODE)
64 endif()
65
66 # include occt macros
67 OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/occt_macros")
68
69 # Solution folder property
70 set_property (GLOBAL PROPERTY USE_FOLDERS ON)
71
72 # get current OCCT version
73 OCC_VERSION (OCC_VERSION_MAJOR OCC_VERSION_MINOR OCC_VERSION_MAINTENANCE OCC_VERSION_DEVELOPMENT OCC_VERSION_STRING_EXT)
74
75 set_property (GLOBAL PROPERTY OCC_VERSION_MAJOR ${OCC_VERSION_MAJOR})
76 set_property (GLOBAL PROPERTY OCC_VERSION_MINOR ${OCC_VERSION_MINOR})
77 set_property (GLOBAL PROPERTY OCC_VERSION_MAINTENANCE ${OCC_VERSION_MAINTENANCE})
78
79 # set soversion variable determining compatibility version on platforms with symlinks
80 # 0 - for empty, 1 - for major, 2 - for major.minor, 3 - for major.minor.maintenance
81 if (NOT BUILD_SOVERSION_NUMBERS)
82   set (BUILD_SOVERSION_NUMBERS "0" CACHE STRING "${BUILD_SOVERSION_NUMBERS_DESCR}" FORCE)
83   SET_PROPERTY(CACHE BUILD_SOVERSION_NUMBERS PROPERTY STRINGS 0 1 2 3)
84
85   # update default state of soversion on different platforms
86   if (WIN32 OR ANDROID OR EMSCRIPTEN)
87     set (BUILD_SOVERSION_NUMBERS 0)
88   else()
89     set (BUILD_SOVERSION_NUMBERS 2)
90   endif()
91 endif()
92
93 set (INSTALL_TEST_CASES OFF CACHE BOOL "${INSTALL_TEST_CASES_DESCR}")
94
95 # Regeneration of OCCT resource files
96 set (BUILD_RESOURCES OFF CACHE BOOL "${BUILD_RESOURCES_DESCR}")
97
98 # single-configuration generator
99 set (SINGLE_GENERATOR OFF)
100 if (DEFINED CMAKE_BUILD_TYPE)
101   set (SINGLE_GENERATOR ON)
102 endif()
103
104 # a single-configuration generator like the Makefile generator defines CMAKE_BUILD_TYPE variable
105 # check this variable and set if it's required
106 if (DEFINED CMAKE_BUILD_TYPE AND NOT CMAKE_BUILD_TYPE) # single-configuration generator.
107   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)
108 endif()
109
110 # enable extended messages of many OCCT algorithms
111 if (((SINGLE_GENERATOR AND "${CMAKE_BUILD_TYPE}" STREQUAL "Debug") OR NOT SINGLE_GENERATOR) AND (NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "WindowsStore"))
112   if (NOT BUILD_WITH_DEBUG)
113     set (BUILD_WITH_DEBUG OFF CACHE BOOL "${BUILD_WITH_DEBUG_DESCR}")
114   endif()
115 else()
116   OCCT_CHECK_AND_UNSET (BUILD_WITH_DEBUG)
117 endif()
118
119 if (BUILD_WITH_DEBUG)
120   set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS $<$<CONFIG:DEBUG>:OCCT_DEBUG>)
121 endif()
122
123 # option disabling OCCT exceptions in Release builds (No_Exception)
124 if (NOT DEFINED BUILD_RELEASE_DISABLE_EXCEPTIONS)
125   set (BUILD_RELEASE_DISABLE_EXCEPTIONS ON CACHE BOOL "${BUILD_RELEASE_DISABLE_EXCEPTIONS_DESCR}")
126 endif()
127
128 if (MSVC)
129   set (BUILD_FORCE_RelWithDebInfo OFF CACHE BOOL "${BUILD_FORCE_RelWithDebInfo_DESCR}")
130 else()
131   set (BUILD_FORCE_RelWithDebInfo OFF)
132 endif()
133
134 if (BUILD_FORCE_RelWithDebInfo)
135   set (CMAKE_CONFIGURATION_TYPES Release Debug CACHE INTERNAL "" FORCE)
136 endif()
137
138 # option to enable or disable use of precompiled headers
139 if (NOT DEFINED BUILD_USE_PCH)
140   set (BUILD_USE_PCH OFF CACHE BOOL "${BUILD_USE_PCH_DESCR}")
141 endif()
142
143 if (BUILD_USE_PCH)
144
145   # Load Cotire tool for accelerating build procedure
146   include(cotire)
147
148   # Set Cotire to ignore lxx, pxx, gxx
149   set (COTIRE_ADDITIONAL_PREFIX_HEADER_IGNORE_EXTENSIONS "lxx;pxx;gxx" CACHE STRING "Set Cotire to ignore OCCT specific files that can be #included" FORCE)
150
151   # Set priority for inclusion of system headers in PCH to reduce problems
152   # due to incomplete inclusion or wrong order.
153   if (WIN32)
154     # on Windows, assume that SDK (windows.h) is in default location
155     set(ProgramFilesX86 "ProgramFiles(x86)")
156     file(TO_CMAKE_PATH "$ENV{${ProgramFilesX86}}" ProgramFilesX86)
157     set_property (DIRECTORY PROPERTY COTIRE_PREFIX_HEADER_INCLUDE_PRIORITY_PATH "${ProgramFilesX86}")
158     unset(ProgramFilesX86)
159   endif()
160
161 endif()
162
163 # copy samples to install directory
164 set (INSTALL_SAMPLES OFF CACHE BOOL "${INSTALL_SAMPLES_DESCR}")
165
166 # install dir of the project
167 if (NOT DEFINED INSTALL_DIR)
168   # set default install directory for Windows
169   if (WIN32 AND NOT DEFINED CMAKE_INSTALL_PREFIX)
170     set (CMAKE_INSTALL_PREFIX "C:/opencascade-${OCC_VERSION_STRING_EXT}")
171   endif()
172   set (INSTALL_DIR "${CMAKE_INSTALL_PREFIX}" CACHE PATH "${INSTALL_DIR_DESCR}")
173 else()
174   file (TO_CMAKE_PATH "${INSTALL_DIR}" INSTALL_DIR)
175   set (INSTALL_DIR "${INSTALL_DIR}" CACHE PATH "${INSTALL_DIR_DESCR}" FORCE)
176 endif()
177
178 # choose a variant of the layout of the install paths
179 if (NOT INSTALL_DIR_LAYOUT)
180   if (WIN32)
181     set (INSTALL_DIR_LAYOUT "Windows" CACHE STRING "${INSTALL_DIR_LAYOUT_DESCR}" FORCE)
182   else()
183     set (INSTALL_DIR_LAYOUT "Unix" CACHE STRING "${INSTALL_DIR_LAYOUT_DESCR}" FORCE)
184   endif()
185   SET_PROPERTY(CACHE INSTALL_DIR_LAYOUT PROPERTY STRINGS Windows Unix)
186 endif()
187
188 # check INSTALL_DIR_LAYOUT changes and update INSTALL_DIR_* paths if necessary
189 if (NOT DEFINED INSTALL_DIR_LAYOUT_PREV)
190   set (INSTALL_DIR_LAYOUT_PREV "${INSTALL_DIR_LAYOUT}" CACHE INTERNAL "" FORCE)
191 elseif (NOT "${INSTALL_DIR_LAYOUT_PREV}" STREQUAL "${INSTALL_DIR_LAYOUT}")
192   set (INSTALL_DIR_LAYOUT_PREV "${INSTALL_DIR_LAYOUT}" CACHE INTERNAL "" FORCE)
193   # The structure of install folder should be reset due to changed layout
194   OCCT_CHECK_AND_UNSET_INSTALL_DIR_SUBDIRS ()
195
196   # Unset INSTALL_DIR_WITH_VERSION on windows
197   if ("${INSTALL_DIR_LAYOUT}" STREQUAL "Windows")
198     OCCT_CHECK_AND_UNSET (INSTALL_DIR_WITH_VERSION)
199   else()
200     if (NOT DEFINED INSTALL_DIR_WITH_VERSION)
201       set (INSTALL_DIR_WITH_VERSION OFF CACHE BOOL "${INSTALL_DIR_WITH_VERSION_DESCR}")
202     endif()
203   endif()
204 endif()
205
206 # check CMAKE_INSTALL_PREFIX changes and update INSTALL_DIR if necessary
207 if (NOT DEFINED CMAKE_INSTALL_PREFIX_PREV)
208   set (CMAKE_INSTALL_PREFIX_PREV "${CMAKE_INSTALL_PREFIX}" CACHE INTERNAL "" FORCE)
209 elseif (NOT "${CMAKE_INSTALL_PREFIX_PREV}" STREQUAL "${CMAKE_INSTALL_PREFIX}")
210   # CMAKE_INSTALL_PREFIX has been changed at previous step
211   set (CMAKE_INSTALL_PREFIX_PREV "${CMAKE_INSTALL_PREFIX}" CACHE INTERNAL "" FORCE)
212
213   # INSTALL_DIR is required to be updated
214   set (INSTALL_DIR "${CMAKE_INSTALL_PREFIX}" CACHE PATH "${INSTALL_DIR_DESCR}" FORCE)
215 endif()
216
217 # check INSTALL_DIR changes and update CMAKE_INSTALL_PREFIX if necessary
218 if (NOT DEFINED INSTALL_DIR_PREV)
219   set (INSTALL_DIR_PREV "${INSTALL_DIR}" CACHE INTERNAL "" FORCE)
220 elseif (NOT "${INSTALL_DIR_PREV}" STREQUAL "${INSTALL_DIR}")
221   # INSTALL_DIR has been changed at previous step
222   set (INSTALL_DIR_PREV "${INSTALL_DIR}" CACHE INTERNAL "" FORCE)
223
224   # sync CMAKE_INSTALL_PREFIX with INSTALL_DIR
225   set (CMAKE_INSTALL_PREFIX "${INSTALL_DIR}" CACHE INTERNAL "" FORCE)
226
227   # set CMAKE_INSTALL_PREFIX_PREV to avoid the reset of structure of the install folder
228   set (CMAKE_INSTALL_PREFIX_PREV "${INSTALL_DIR}" CACHE INTERNAL "" FORCE)
229 endif()
230
231 if ("${INSTALL_DIR_LAYOUT}" STREQUAL "Unix")
232   if (NOT DEFINED INSTALL_DIR_WITH_VERSION_PREV)
233     set (INSTALL_DIR_WITH_VERSION_PREV "${INSTALL_DIR_WITH_VERSION}" CACHE INTERNAL "" FORCE)
234   elseif (NOT "${INSTALL_DIR_WITH_VERSION_PREV}" STREQUAL "${INSTALL_DIR_WITH_VERSION}")
235     # INSTALL_DIR_WITH_VERSION has been changed at previous step
236     set (INSTALL_DIR_WITH_VERSION_PREV "${INSTALL_DIR_WITH_VERSION}" CACHE INTERNAL "" FORCE)
237
238     OCCT_CHECK_AND_UNSET_INSTALL_DIR_SUBDIRS ()
239   endif()
240 endif()
241
242 # hide CMAKE_INSTALL_PREFIX from a user
243 set (CMAKE_INSTALL_PREFIX "${INSTALL_DIR}" CACHE INTERNAL "" FORCE)
244
245 set (BIN_LETTER "")
246 if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
247   set (BIN_LETTER "d")
248 elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo")
249   set (BIN_LETTER "i")
250 endif()
251
252 # Get all used variables: OS_WITH_BIT, COMPILER
253 OCCT_MAKE_OS_WITH_BITNESS()
254 OCCT_MAKE_COMPILER_SHORT_NAME()
255
256 # do not define INSTALL_DIR_BIN for win.
257 # Leave library structure for win: <prefix>/win64/vc10/bin(d)
258 if (NOT DEFINED INSTALL_DIR_BIN)
259   if ("${INSTALL_DIR_LAYOUT}" STREQUAL "Unix")
260     set (INSTALL_DIR_BIN "bin" CACHE PATH "${INSTALL_DIR_BIN_DESCR}")
261   else()
262     set (INSTALL_DIR_BIN "${OS_WITH_BIT}/${COMPILER}/bin" CACHE PATH "${INSTALL_DIR_BIN_DESCR}")
263   endif()
264 endif()
265
266 # define folder containing all shell/batch scripts
267 if (NOT DEFINED INSTALL_DIR_SCRIPT)
268   if ("${INSTALL_DIR_LAYOUT}" STREQUAL "Unix")
269     set (INSTALL_DIR_SCRIPT "${INSTALL_DIR_BIN}" CACHE PATH "${INSTALL_DIR_SCRIPT_DESCR}")
270   else()
271     set (INSTALL_DIR_SCRIPT "." CACHE PATH "${INSTALL_DIR_SCRIPT_DESCR}")
272   endif()
273 endif()
274
275 # place the libraries to <prefix>/lib folder for unix and leave old structure for windows
276 if (NOT DEFINED INSTALL_DIR_LIB)
277   if ("${INSTALL_DIR_LAYOUT}" STREQUAL "Unix")
278     set (INSTALL_DIR_LIB "lib" CACHE PATH "${INSTALL_DIR_LIB_DESCR}")
279   else()
280     set (INSTALL_DIR_LIB "${OS_WITH_BIT}/${COMPILER}/lib" CACHE PATH "${INSTALL_DIR_LIB_DESCR}")
281   endif()
282 endif()
283
284 # OCCT headers: <prefix>/inc for windows,
285 #               <prefix>/include/opencascade-7.0.0 for unix
286 if (NOT DEFINED INSTALL_DIR_INCLUDE)
287   if ("${INSTALL_DIR_LAYOUT}" STREQUAL "Unix")
288     set (INSTALL_DIR_INCLUDE "include/opencascade" CACHE PATH "${INSTALL_DIR_INCLUDE_DESCR}")
289     if (INSTALL_DIR_WITH_VERSION)
290       set (INSTALL_DIR_INCLUDE "include/opencascade-${OCC_VERSION_STRING_EXT}" CACHE PATH "${INSTALL_DIR_INCLUDE_DESCR}" FORCE)
291     endif()
292   else()
293     set (INSTALL_DIR_INCLUDE "inc" CACHE PATH "${INSTALL_DIR_INCLUDE_DESCR}")
294   endif()
295 endif()
296
297 # OCCT resources: <prefix>/src for windows,
298 #                 <prefix>/share/opencascade-7.0.0/resources for unix
299 if (NOT DEFINED INSTALL_DIR_RESOURCE)
300   if ("${INSTALL_DIR_LAYOUT}" STREQUAL "Unix")
301     set (INSTALL_DIR_RESOURCE "share/opencascade/resources" CACHE PATH "${INSTALL_DIR_RESOURCE_DESCR}")
302     if (INSTALL_DIR_WITH_VERSION)
303       set (INSTALL_DIR_RESOURCE "share/opencascade-${OCC_VERSION_STRING_EXT}/resources" CACHE PATH "${INSTALL_DIR_RESOURCE_DESCR}" FORCE)
304     endif()
305   else()
306     set (INSTALL_DIR_RESOURCE "src" CACHE PATH "${INSTALL_DIR_RESOURCE_DESCR}")
307   endif()
308 endif()
309
310 # OCCT data
311 if (NOT DEFINED INSTALL_DIR_DATA)
312   if ("${INSTALL_DIR_LAYOUT}" STREQUAL "Unix")
313     set (INSTALL_DIR_DATA "share/opencascade/data" CACHE PATH "${INSTALL_DIR_DATA_DESCR}")
314     if (INSTALL_DIR_WITH_VERSION)
315       set (INSTALL_DIR_DATA "share/opencascade-${OCC_VERSION_STRING_EXT}/data" CACHE PATH "${INSTALL_DIR_DATA_DESCR}" FORCE)
316     endif()
317   else()
318     set (INSTALL_DIR_DATA "data" CACHE PATH "${INSTALL_DIR_DATA_DESCR}")
319   endif()
320 endif()
321
322 # OCCT samples
323 if (NOT DEFINED INSTALL_DIR_SAMPLES)
324   if ("${INSTALL_DIR_LAYOUT}" STREQUAL "Unix")
325     set (INSTALL_DIR_SAMPLES "share/opencascade/samples" CACHE PATH "${INSTALL_DIR_SAMPLES_DESCR}")
326     if (INSTALL_DIR_WITH_VERSION)
327       set (INSTALL_DIR_SAMPLES "share/opencascade-${OCC_VERSION_STRING_EXT}/samples" CACHE PATH "${INSTALL_DIR_SAMPLES_DESCR}" FORCE)
328     endif()
329   else()
330     set (INSTALL_DIR_SAMPLES "samples" CACHE PATH "${INSTALL_DIR_SAMPLES_DESCR}")
331   endif()
332 endif()
333
334 # OCCT tests
335 if (NOT DEFINED INSTALL_DIR_TESTS)
336   if ("${INSTALL_DIR_LAYOUT}" STREQUAL "Unix")
337     set (INSTALL_DIR_TESTS "share/opencascade/tests" CACHE PATH "${INSTALL_DIR_TESTS_DESCR}")
338     if (INSTALL_DIR_WITH_VERSION)
339       set (INSTALL_DIR_TESTS "share/opencascade-${OCC_VERSION_STRING_EXT}/tests" CACHE PATH "${INSTALL_DIR_TESTS_DESCR}" FORCE)
340     endif()
341   else()
342     set (INSTALL_DIR_TESTS "tests" CACHE PATH "${INSTALL_DIR_TESTS_DESCR}")
343   endif()
344 endif()
345
346 # OCCT doc
347 if (NOT DEFINED INSTALL_DIR_DOC)
348   if ("${INSTALL_DIR_LAYOUT}" STREQUAL "Unix")
349     set (INSTALL_DIR_DOC "share/doc/opencascade" CACHE PATH "${INSTALL_DIR_DOC_DESCR}")
350     if (INSTALL_DIR_WITH_VERSION)
351       set (INSTALL_DIR_DOC "share/doc/opencascade-${OCC_VERSION_STRING_EXT}" CACHE PATH "${INSTALL_DIR_DOC_DESCR}" FORCE)
352     endif()
353   else()
354     set (INSTALL_DIR_DOC "doc" CACHE PATH "${INSTALL_DIR_DOC_DESCR}")
355   endif()
356 endif()
357
358 # define folder containing CMake configuration files
359 if (NOT DEFINED INSTALL_DIR_CMAKE)
360   if ("${INSTALL_DIR_LAYOUT}" STREQUAL "Unix")
361     if (INSTALL_DIR_WITH_VERSION)
362       set (INSTALL_DIR_CMAKE "lib/cmake/opencascade-${OCC_VERSION_STRING_EXT}" CACHE PATH "${INSTALL_DIR_CMAKE_DESCR}")
363     else()
364       set (INSTALL_DIR_CMAKE "lib/cmake/opencascade" CACHE PATH "${INSTALL_DIR_CMAKE_DESCR}")
365     endif()
366   else()
367     set (INSTALL_DIR_CMAKE "cmake" CACHE PATH "${INSTALL_DIR_CMAKE_DESCR}")
368   endif()
369 endif()
370
371 # include occt macros
372 OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/occt_resources")
373
374 # install LICENSE_LGPL_21.txt and OCCT_LGPL_EXCEPTION.txt files
375 if ("${INSTALL_DIR_LAYOUT}" STREQUAL "Unix")
376   OCCT_INSTALL_FILE_OR_DIR ("LICENSE_LGPL_21.txt" "${INSTALL_DIR_DOC}")
377   OCCT_INSTALL_FILE_OR_DIR ("OCCT_LGPL_EXCEPTION.txt" "${INSTALL_DIR_DOC}")
378 else()
379   OCCT_INSTALL_FILE_OR_DIR ("LICENSE_LGPL_21.txt" ".")
380   OCCT_INSTALL_FILE_OR_DIR ("OCCT_LGPL_EXCEPTION.txt" ".")
381 endif()
382
383 if(APPLE)
384   set (INSTALL_NAME_DIR "" CACHE STRING "install_name library suffix on OS X (e.g. @executable_path/../Frameworks)")
385 endif()
386
387 # a directory recognized as a 'patch' for OCCT
388 set (BUILD_PATCH "" CACHE PATH "${BUILD_PATCH_DESCR}")
389
390 # the list of being built toolkits
391 set (BUILD_ADDITIONAL_TOOLKITS "" CACHE STRING "${BUILD_ADDITIONAL_TOOLKITS_DESCR}")
392 separate_arguments (BUILD_ADDITIONAL_TOOLKITS)
393
394 if (MSVC)
395   set (BUILD_SAMPLES_MFC OFF CACHE BOOL "${BUILD_SAMPLES_MFC_DESCR}")
396 endif()
397 set (BUILD_SAMPLES_QT OFF CACHE BOOL "${BUILD_SAMPLES_QT_DESCR}")
398
399 set (BUILD_Inspector OFF CACHE BOOL "${BUILD_Inspector_DESCR}")
400
401 # uwp sample
402 if (MSVC)
403   if ("${CMAKE_SYSTEM_NAME}" STREQUAL "WindowsStore")
404     set (BUILD_MODULE_UwpSample OFF CACHE BOOL "${BUILD_MODULE_UwpSample_DESCR}")
405   else()
406     unset (BUILD_MODULE_UwpSample)
407   endif()
408 endif()
409
410 # whether use optional 3rdparty or not
411 set (USE_TK        ON  CACHE BOOL "${USE_TK_DESCR}")
412 set (USE_FREETYPE  ON  CACHE BOOL "${USE_FREETYPE_DESCR}")
413 set (USE_FREEIMAGE OFF CACHE BOOL "${USE_FREEIMAGE_DESCR}")
414 set (USE_FFMPEG    OFF CACHE BOOL "${USE_FFMPEG_DESCR}")
415 set (USE_OPENVR    OFF CACHE BOOL "${USE_OPENVR_DESCR}")
416 set (USE_RAPIDJSON OFF CACHE BOOL "${USE_RAPIDJSON_DESCR}")
417 set (USE_DRACO     OFF CACHE BOOL "${USE_DRACO_DESCR}")
418 set (USE_TBB       OFF CACHE BOOL "${USE_TBB_DESCR}")
419 set (USE_EIGEN     OFF CACHE BOOL "${USE_EIGEN_DESCR}")
420
421 if (WIN32 OR ANDROID OR IOS OR EMSCRIPTEN)
422   # no Xlib
423 elseif (APPLE)
424   set (USE_XLIB OFF CACHE BOOL "${USE_XLIB_DESCR}")
425 else()
426   set (USE_XLIB ON  CACHE BOOL "${USE_XLIB_DESCR}")
427 endif()
428
429 if (WIN32)
430   set (USE_D3D OFF CACHE BOOL "${USE_D3D_DESCR}")
431 else()
432   set (USE_D3D OFF)
433 endif()
434
435 # Enable/Disable the floating point exceptions (FPE) during runtime.
436 if (NOT BUILD_ENABLE_FPE_SIGNAL_HANDLER)
437   set (BUILD_ENABLE_FPE_SIGNAL_HANDLER OFF CACHE BOOL "${BUILD_ENABLE_FPE_SIGNAL_HANDLER_DESCR}" FORCE)
438 endif()
439
440 if (BUILD_ENABLE_FPE_SIGNAL_HANDLER)
441   set (BUILD_ENABLE_FPE_SIGNAL_HANDLER 1)
442 else()
443   set (BUILD_ENABLE_FPE_SIGNAL_HANDLER 0)
444 endif()
445
446 # OpenGL
447 if (ANDROID OR IOS OR EMSCRIPTEN OR "${CMAKE_SYSTEM_NAME}" STREQUAL "WindowsStore")
448   set (USE_OPENGL OFF)
449   set (USE_GLES2 ON)
450 else()
451   set (USE_OPENGL ON CACHE BOOL "${USE_OPENGL_DESCR}")
452   set (USE_GLES2 OFF CACHE BOOL "${USE_GLES2_DESCR}")
453 endif()
454
455 # include the patched or original list of modules
456 # list <MODULENAME>_TOOLKITS is created foreach module and contains its toolkits
457 # list <OCCT_MODULES> will contain all modules
458 OCCT_MODULES_AND_TOOLKITS (MODULES "TOOLKITS" OCCT_MODULES)
459
460 foreach (OCCT_MODULE ${OCCT_MODULES})
461   BUILD_MODULE (${OCCT_MODULE})
462 endforeach()
463
464 if (ANDROID AND BUILD_MODULE_Draw)
465   message (STATUS "Info. Draw module is turned off due to it is not supported on Android")
466   set (BUILD_MODULE_Draw OFF CACHE BOOL "${BUILD_MODULE_Draw_DESCR}" FORCE)
467 endif()
468 if ("${CMAKE_SYSTEM_NAME}" STREQUAL "WindowsStore" AND BUILD_MODULE_Draw)
469   message (STATUS "Info. Draw module is turned off due to it is not supported on UWP")
470   set (BUILD_MODULE_Draw OFF CACHE BOOL "${BUILD_MODULE_Draw_DESCR}" FORCE)
471 endif()
472
473 # Overview
474 if (NOT DEFINED BUILD_DOC_Overview)
475   set (DO_ONLY_CHECK_FOR_DOXYGEN ON)
476   OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/doxygen")
477   set (DO_ONLY_CHECK_FOR_DOXYGEN OFF)
478
479   if (CAN_DOXYGEN_BE_USED)
480     message (STATUS "Info. Overview building is turned on")
481   endif()
482
483   set (BUILD_DOC_Overview ${CAN_DOXYGEN_BE_USED} CACHE BOOL "${BUILD_DOC_Overview_DESCR}")
484 endif()
485
486 # accumulate used toolkits (first level) in BUILD_TOOLKITS variable
487 list (APPEND BUILD_TOOLKITS ${BUILD_ADDITIONAL_TOOLKITS})
488
489 foreach (OCCT_MODULE ${OCCT_MODULES})
490   if (BUILD_MODULE_${OCCT_MODULE})
491     list (APPEND BUILD_TOOLKITS ${${OCCT_MODULE}_TOOLKITS})
492   endif()
493 endforeach()
494
495 # accumulate all used toolkits
496 list (REMOVE_DUPLICATES BUILD_TOOLKITS)
497 set (RAW_BUILD_TOOLKITS)
498 foreach (BUILD_TOOLKIT ${BUILD_TOOLKITS})
499   OCCT_TOOLKIT_FULL_DEP (${BUILD_TOOLKIT} TOOLKIT_FULL_DEPS)
500   list (APPEND RAW_BUILD_TOOLKITS ${BUILD_TOOLKIT} ${TOOLKIT_FULL_DEPS})
501 endforeach()
502
503 list (REMOVE_DUPLICATES RAW_BUILD_TOOLKITS)
504 set (BUILD_TOOLKITS ${RAW_BUILD_TOOLKITS})
505
506 # include the patched or original list of definitions and flags
507 OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/occt_defs_flags")
508
509 OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/3rdparty_macro")
510
511 # search for TKIVtk and TKIVtkDraw in BUILD_TOOLKITS
512 list (FIND BUILD_TOOLKITS TKIVtk CAN_USE_VTK)
513 if (CAN_USE_VTK EQUAL -1)
514   list (FIND BUILD_TOOLKITS TKIVtkDraw CAN_USE_VTK)
515 endif()
516
517 if (NOT CAN_USE_VTK EQUAL -1)
518   if (NOT DEFINED USE_VTK)
519     set (USE_VTK OFF CACHE BOOL "${USE_VTK_DESCR}")
520   endif()
521 else()
522   OCCT_CHECK_AND_UNSET (USE_VTK)
523 endif()
524
525 # Rebuild *.yacc and *.lex files that are contained by TKMath toolkit
526 list (FIND BUILD_TOOLKITS TKMath   CAN_REBUILD_PDC_FOR_TKMATH)
527 list (FIND BUILD_TOOLKITS StepFile CAN_REBUILD_PDC_FOR_STEPFILE)
528
529 if (NOT ${CAN_REBUILD_PDC_FOR_TKMATH} EQUAL -1 OR NOT ${CAN_REBUILD_PDC_FOR_STEPFILE} EQUAL -1)
530   set (BUILD_YACCLEX OFF CACHE BOOL "${BUILD_YACCLEX_DESCR}")
531 else()
532   OCCT_CHECK_AND_UNSET (BUILD_YACCLEX)
533 endif()
534
535 if (NOT DEFINED 3RDPARTY_DIR)
536   set (3RDPARTY_DIR "" CACHE PATH ${3RDPARTY_DIR_DESCR})
537   get_filename_component (3RDPARTY_DIR "${3RDPARTY_DIR}" ABSOLUTE)
538 else()
539   file (TO_CMAKE_PATH "${3RDPARTY_DIR}" 3RDPARTY_DIR)
540   set (3RDPARTY_DIR "${3RDPARTY_DIR}" CACHE PATH "${3RDPARTY_DIR_DESCR}" FORCE)
541 endif()
542
543 # search for CSF variable in EXTERNLIB of each being used toolkit
544 OCCT_IS_PRODUCT_REQUIRED (CSF_FreeImagePlus CAN_USE_FREEIMAGE)
545 OCCT_IS_PRODUCT_REQUIRED (CSF_TclLibs USE_TCL)
546 OCCT_IS_PRODUCT_REQUIRED (CSF_TclTkLibs CAN_USE_TK)
547 OCCT_IS_PRODUCT_REQUIRED (CSF_XwLibs CAN_USE_XLIB)
548 OCCT_IS_PRODUCT_REQUIRED (CSF_FREETYPE CAN_USE_FREETYPE)
549 OCCT_IS_PRODUCT_REQUIRED (CSF_OpenGlLibs CAN_USE_OPENGL)
550 OCCT_IS_PRODUCT_REQUIRED (CSF_OpenGlesLibs CAN_USE_GLES2)
551 OCCT_IS_PRODUCT_REQUIRED (CSF_TBB CAN_USE_TBB)
552 OCCT_IS_PRODUCT_REQUIRED (CSF_EIGEN CAN_USE_EIGEN)
553
554 # define CSF variable
555 OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/occt_csf")
556
557 # Tcl (mandatory for Draw Harness)
558 if (USE_TCL)
559   message (STATUS "Info: TCL is used by OCCT")
560   OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/tcl")
561 else()
562   OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_TCL")
563   OCCT_CHECK_AND_UNSET ("INSTALL_TCL")
564 endif()
565
566 # Tk (optional for Draw Harness)
567 if (CAN_USE_TK)
568   if (USE_TK)
569     message (STATUS "Info: TK is used by OCCT")
570     add_definitions (-DHAVE_TK)
571     OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/tk")
572   else()
573     OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_TK")
574     OCCT_CHECK_AND_UNSET ("INSTALL_TK")
575   endif()
576 else()
577   OCCT_CHECK_AND_UNSET ("USE_TK")
578   OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_TK")
579   OCCT_CHECK_AND_UNSET ("INSTALL_TK")
580 endif()
581
582 # Xlib
583 if (CAN_USE_XLIB)
584   if (USE_XLIB)
585     message (STATUS "Info: Xlib is used by OCCT")
586     add_definitions (-DHAVE_XLIB)
587     if (APPLE)
588       OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/glx")
589     endif()
590   endif()
591 else()
592   OCCT_CHECK_AND_UNSET ("USE_XLIB")
593 endif()
594
595 # FreeType
596 if (CAN_USE_FREETYPE)
597   if (USE_FREETYPE)
598     message (STATUS "Info: FreeType is used by OCCT")
599     add_definitions (-DHAVE_FREETYPE)
600     OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/freetype")
601   else()
602     OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_FREETYPE")
603     OCCT_CHECK_AND_UNSET ("3RDPARTY_FREETYPE_INCLUDE_DIR_freetype2")
604     OCCT_CHECK_AND_UNSET ("3RDPARTY_FREETYPE_INCLUDE_DIR_ft2build")
605     OCCT_CHECK_AND_UNSET ("INSTALL_FREETYPE")
606   endif()
607 else()
608   OCCT_CHECK_AND_UNSET ("USE_FREETYPE")
609   OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_FREETYPE")
610   OCCT_CHECK_AND_UNSET ("INSTALL_FREETYPE")
611 endif()
612
613 # VTK
614 if (USE_VTK)
615   add_definitions (-DHAVE_VTK)
616   set (OCCT_VTK_USED_TARGETS "" CACHE INTERNAL "" FORCE)
617   OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/vtk")
618 else()
619   OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_VTK")
620
621   if (NOT CAN_USE_VTK EQUAL -1)
622     message (STATUS "Info: TKIVtk and TKIVtkDraw toolkits excluded due to VTK usage is disabled")
623
624     list (REMOVE_ITEM BUILD_TOOLKITS TKIVtk)
625     list (REMOVE_ITEM BUILD_TOOLKITS TKIVtkDraw)
626   endif()
627 endif()
628
629 # FREEIMAGE
630 if (CAN_USE_FREEIMAGE)
631   if (USE_FREEIMAGE)
632     add_definitions (-DHAVE_FREEIMAGE)
633     OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/freeimage")
634   else()
635     OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_FREEIMAGE")
636     OCCT_CHECK_AND_UNSET ("INSTALL_FREEIMAGE")
637   endif()
638 else()
639   OCCT_CHECK_AND_UNSET ("USE_FREEIMAGE")
640
641   OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_FREEIMAGE")
642   OCCT_CHECK_AND_UNSET ("INSTALL_FREEIMAGE")
643 endif()
644
645 # OpenVR
646 # search for CSF_OpenVR variable in EXTERNLIB of each being used toolkit
647 OCCT_IS_PRODUCT_REQUIRED (CSF_OpenVR CAN_USE_OPENVR)
648 if (CAN_USE_OPENVR)
649   if (USE_OPENVR)
650     add_definitions (-DHAVE_OPENVR)
651     OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/openvr")
652   else()
653     OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_OPENVR")
654     OCCT_CHECK_AND_UNSET ("INSTALL_OPENVR")
655   endif()
656 else()
657   OCCT_CHECK_AND_UNSET ("USE_OPENVR")
658
659   OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_OPENVR")
660   OCCT_CHECK_AND_UNSET ("INSTALL_OPENVR")
661 endif()
662
663 # FFmpeg
664 # search for CSF_FFmpeg variable in EXTERNLIB of each being used toolkit
665 OCCT_IS_PRODUCT_REQUIRED (CSF_FFmpeg CAN_USE_FFMPEG)
666
667 if (CAN_USE_FFMPEG)
668   if (USE_FFMPEG)
669     add_definitions (-DHAVE_FFMPEG)
670     OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/ffmpeg")
671   else()
672     OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_FFMPEG")
673     OCCT_CHECK_AND_UNSET ("INSTALL_FFMPEG")
674   endif()
675 else()
676   OCCT_CHECK_AND_UNSET ("USE_FFMPEG")
677
678   OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_FFMPEG")
679   OCCT_CHECK_AND_UNSET ("INSTALL_FFMPEG")
680 endif()
681
682 # OpenGL
683 if (CAN_USE_OPENGL)
684   if (USE_OPENGL)
685     add_definitions (-DHAVE_OPENGL_EXT)
686   else()
687     list (REMOVE_ITEM BUILD_TOOLKITS TKOpenGl)
688     list (REMOVE_ITEM BUILD_TOOLKITS TKOpenGlTest)
689   endif()
690 else()
691   OCCT_CHECK_AND_UNSET ("USE_OPENGL")
692 endif()
693
694 # OpenGL ES 2.0
695 if (CAN_USE_GLES2)
696   if (USE_GLES2)
697     add_definitions (-DHAVE_GLES2_EXT)
698     if (NOT IOS)
699       OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/egl")
700       OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/gles2")
701     endif()
702   else()
703     OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_EGL")
704     OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_GLES2")
705     OCCT_CHECK_AND_UNSET ("INSTALL_EGL")
706     OCCT_CHECK_AND_UNSET ("INSTALL_GLES2")
707     list (REMOVE_ITEM BUILD_TOOLKITS TKOpenGles)
708     list (REMOVE_ITEM BUILD_TOOLKITS TKOpenGlesTest)
709   endif()
710 else()
711   OCCT_CHECK_AND_UNSET ("USE_GLES2")
712
713   OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_EGL")
714   OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_GLES2")
715   OCCT_CHECK_AND_UNSET ("INSTALL_EGL")
716   OCCT_CHECK_AND_UNSET ("INSTALL_GLES2")
717 endif()
718
719 # D3D
720 if (USE_D3D)
721   add_definitions (-DHAVE_D3D)
722   #if(MSVC_VERSION LESS 1700)
723   #OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/d3d")
724   #endif()
725 else()
726   list (REMOVE_ITEM BUILD_TOOLKITS TKD3DHost)
727   list (REMOVE_ITEM BUILD_TOOLKITS TKD3DHostTest)
728 endif()
729
730 # TBB
731 if (NOT DEFINED ANDROID AND CAN_USE_TBB)
732   if (USE_TBB)
733     add_definitions (-DHAVE_TBB)
734     OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/tbb")
735   else()
736     OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_TBB")
737     OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_TBBMALLOC")
738     OCCT_CHECK_AND_UNSET ("INSTALL_TBB")
739   endif()
740 else()
741   OCCT_CHECK_AND_UNSET ("USE_TBB")
742
743   OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_TBB")
744   OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_TBBMALLOC")
745   OCCT_CHECK_AND_UNSET ("INSTALL_TBB")
746 endif()
747
748 # RapidJSON
749 # search for CSF_RapidJSON variable in EXTERNLIB of each being used toolkit
750 OCCT_IS_PRODUCT_REQUIRED (CSF_RapidJSON CAN_USE_RAPIDJSON)
751 if (CAN_USE_RAPIDJSON)
752   if (USE_RAPIDJSON)
753     add_definitions (-DHAVE_RAPIDJSON)
754     OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/rapidjson")
755   else()
756     OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_RAPIDJSON")
757     OCCT_CHECK_AND_UNSET ("INSTALL_RAPIDJSON")
758   endif()
759 else()
760   OCCT_CHECK_AND_UNSET ("USE_RAPIDJSON")
761
762   OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_RAPIDJSON")
763   OCCT_CHECK_AND_UNSET ("INSTALL_RAPIDJSON")
764 endif()
765
766 # Draco library
767 # search for CSF_Draco variable in EXTERNLIB of each being used toolkit
768 OCCT_IS_PRODUCT_REQUIRED (CSF_Draco CAN_USE_DRACO)
769 if (CAN_USE_DRACO)
770   if (USE_DRACO)
771     add_definitions (-DHAVE_DRACO)
772     OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/draco")
773   else()
774     OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_DRACO")
775     OCCT_CHECK_AND_UNSET ("INSTALL_DRACO")
776   endif()
777 else()
778   OCCT_CHECK_AND_UNSET ("USE_DRACO")
779
780   OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_DRACO")
781   OCCT_CHECK_AND_UNSET ("INSTALL_DRACO")
782 endif()
783
784 # EIGEN
785 if (CAN_USE_EIGEN)
786   if (USE_EIGEN)
787     add_definitions (-DHAVE_EIGEN)
788     OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/eigen")
789   else()
790     OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_EIGEN")
791     OCCT_CHECK_AND_UNSET ("INSTALL_EIGEN")
792   endif()
793 else()
794   OCCT_CHECK_AND_UNSET ("USE_EIGEN")
795
796   OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_EIGEN")
797   OCCT_CHECK_AND_UNSET ("INSTALL_EIGEN")
798 endif()
799
800 # Doxygen
801 if (BUILD_DOC_Overview)
802   if (NOT DEFINED INSTALL_DOC_Overview)
803     set (INSTALL_DOC_Overview OFF CACHE BOOL "${INSTALL_DOC_Overview_DESCR}")
804   endif()
805
806   if (INSTALL_DOC_Overview)
807     install (DIRECTORY "${CMAKE_BINARY_DIR}/doc/overview" DESTINATION  "${INSTALL_DIR_DOC}")
808
809     # create overview.html only for windows
810     if (WIN32 AND "${INSTALL_DIR_LAYOUT}" STREQUAL "Windows")
811       OCCT_INSTALL_FILE_OR_DIR ("dox/resources/overview.html" "${INSTALL_DIR_DOC}/..")
812     endif()
813   endif()
814
815   OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/doxygen")
816 else()
817   OCCT_CHECK_AND_UNSET ("INSTALL_DOC_Overview")
818
819   OCCT_CHECK_AND_UNSET ("3RDPARTY_DOXYGEN_EXECUTABLE")
820   OCCT_CHECK_AND_UNSET ("3RDPARTY_DOT_EXECUTABLE")
821 endif()
822
823 # bison
824 if (BUILD_YACCLEX)
825   OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/bison")
826 else()
827   OCCT_CHECK_AND_UNSET ("3RDPARTY_BISON_EXECUTABLE")
828 endif()
829
830 # flex
831 if (BUILD_YACCLEX)
832   OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/flex")
833 else()
834   OCCT_CHECK_AND_UNSET ("3RDPARTY_FLEX_EXECUTABLE")
835 endif()
836
837 # qt for inspector and samples
838 if (BUILD_Inspector OR BUILD_SAMPLES_QT)
839   # check qt 3rdparty path
840   add_definitions (-DHAVE_QT)
841   OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/qt")
842   message (STATUS "Info: Qt is used by OCCT")
843 else()
844   OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_QT")
845   OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_TQTMALLOC")
846   OCCT_CHECK_AND_UNSET ("INSTALL_QT")
847 endif()
848
849 # check all 3rdparty include paths
850 string (REGEX REPLACE ";" " " 3RDPARTY_NOT_INCLUDED "${3RDPARTY_NOT_INCLUDED}")
851 if (3RDPARTY_NOT_INCLUDED)
852   message (FATAL_ERROR "Could not find headers of used third-party products: ${3RDPARTY_NOT_INCLUDED}" )
853 endif()
854
855 if (3RDPARTY_INCLUDE_DIRS)
856   list (REMOVE_DUPLICATES 3RDPARTY_INCLUDE_DIRS)
857   string (REGEX REPLACE ";" "\n\t" 3RDPARTY_INCLUDE_DIRS_WITH_ENDS "${3RDPARTY_INCLUDE_DIRS}")
858   message (STATUS "Info: The directories of 3rdparty headers: \n\t${3RDPARTY_INCLUDE_DIRS_WITH_ENDS}")
859   include_directories (${3RDPARTY_INCLUDE_DIRS})
860 endif()
861
862 # include <cmake binary folder>/inc
863 include_directories (${CMAKE_BINARY_DIR}/${INSTALL_DIR_INCLUDE})
864
865 # check all 3rdparty library paths
866 string (REGEX REPLACE ";" " " 3RDPARTY_NO_LIBS "${3RDPARTY_NO_LIBS}")
867 if (3RDPARTY_NO_LIBS)
868   if (BUILD_SHARED_LIBS)
869     message (SEND_ERROR "Could not find libraries of used third-party products: ${3RDPARTY_NO_LIBS}" )
870   else()
871     message (WARNING "Could not find libraries of used third-party products: ${3RDPARTY_NO_LIBS}" )
872   endif()
873 endif()
874 if (3RDPARTY_LIBRARY_DIRS)
875   list (REMOVE_DUPLICATES 3RDPARTY_LIBRARY_DIRS)
876   string (REGEX REPLACE ";" "\n\t" 3RDPARTY_LIBRARY_DIRS_WITH_ENDS "${3RDPARTY_LIBRARY_DIRS}")
877   message (STATUS "Info: The directories of 3rdparty libraries: \n\t${3RDPARTY_LIBRARY_DIRS_WITH_ENDS}")
878   link_directories (${3RDPARTY_LIBRARY_DIRS})
879 endif()
880
881 # report not found 3rdparty dll paths
882 string (REGEX REPLACE ";" " " 3RDPARTY_NO_DLLS "${3RDPARTY_NO_DLLS}")
883 if (3RDPARTY_NO_DLLS)
884   message (WARNING "Could not find DLLs of used third-party products: ${3RDPARTY_NO_DLLS}" )
885 endif()
886
887 # build directories
888 if (SINGLE_GENERATOR)
889   set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/lib${BIN_LETTER}")
890   set (CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/bin${BIN_LETTER}")
891   set (CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/lib${BIN_LETTER}")
892   if (WIN32)
893     set (CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/bin${BIN_LETTER}")
894   endif()
895 endif()
896
897 set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/lib")
898 set (CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/bin")
899 set (CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/lib")
900
901 set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/libi")
902 set (CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/bini")
903 set (CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/libi")
904
905 set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/libd")
906 set (CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/bind")
907 set (CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/libd")
908
909 if (WIN32)
910   set (CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE        "${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/bin")
911   set (CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/bini")
912   set (CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG          "${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/bind")
913 endif()
914
915 string(TIMESTAMP CURRENT_TIME "%H:%M:%S")
916 message (STATUS "\nInfo: \(${CURRENT_TIME}\) Start collecting all OCCT header files into ${CMAKE_BINARY_DIR}/inc ...")
917
918 # collect all the headers to <binary dir>/inc folder
919 COLLECT_AND_INSTALL_OCCT_HEADER_FILES ("${CMAKE_BINARY_DIR}" "${BUILD_TOOLKITS}" "${CMAKE_SOURCE_DIR}/src" "${INSTALL_DIR_INCLUDE}")
920
921 string(TIMESTAMP CURRENT_TIME "%H:%M:%S")
922 message (STATUS "Info: \(${CURRENT_TIME}\) End the collecting")
923
924 list (FIND BUILD_TOOLKITS DRAWEXE DRAWEXE_INDEX)
925 if (${DRAWEXE_INDEX} GREATER -1)
926   OCCT_INSTALL_FILE_OR_DIR ("data/" "${INSTALL_DIR_DATA}")
927   OCCT_INSTALL_FILE_OR_DIR ("samples/tcl" "${INSTALL_DIR_SAMPLES}")
928 endif()
929
930 if (WIN32)
931   set (SCRIPT_EXT bat)
932 else()
933   set (SCRIPT_EXT sh)
934 endif()
935
936 # OCCT tools
937 # include the patched or original list of tools
938 # list <TOOLNAME>_TOOLKITS is created foreach tool and contains its toolkits
939 # list <OCCT_TOOLS> will contain all tools
940 if (BUILD_Inspector)
941   add_definitions (-DHAVE_Inspector)
942
943   OCCT_MODULES_AND_TOOLKITS (TOOLS "TOOL_TOOLKITS" OCCT_TOOLS)
944   foreach (OCCT_TOOL ${OCCT_TOOLS})
945     list (APPEND BUILD_TOOL_TOOLKITS ${${OCCT_TOOL}_TOOL_TOOLKITS})
946   endforeach()
947
948   # collect all the headers to <binary dir>/inc/inspector folder
949   string(TIMESTAMP CURRENT_TIME "%H:%M:%S")
950   message (STATUS "\nInfo: \(${CURRENT_TIME}\) Start collecting all OCCT tool header files into ${CMAKE_BINARY_DIR}/inc/inspector ...")
951   COLLECT_AND_INSTALL_OCCT_HEADER_FILES ("${CMAKE_BINARY_DIR}" "${BUILD_TOOL_TOOLKITS}" "${CMAKE_SOURCE_DIR}/tools" "${INSTALL_DIR_INCLUDE}/inspector")
952 endif()
953
954 # OCCT samples
955 # get absolute path from INSTALL_DIR
956 set (INSTALL_DIR_ABSOLUTE "${INSTALL_DIR}")
957 if(NOT IS_ABSOLUTE "${INSTALL_DIR_ABSOLUTE}")
958   get_filename_component(INSTALL_DIR_ABSOLUTE "${CMAKE_BINARY_DIR}/${INSTALL_DIR}" ABSOLUTE)
959 endif()
960
961 if (INSTALL_SAMPLES)
962   OCCT_CONFIGURE ("adm/templates/env.samples.${SCRIPT_EXT}.in" "env.samples.${SCRIPT_EXT}")
963   if (WIN32)
964     OCCT_INSTALL_FILE_OR_DIR ("samples/CSharp" "${INSTALL_DIR_SAMPLES}")
965     OCCT_INSTALL_FILE_OR_DIR ("samples/mfc" "${INSTALL_DIR_SAMPLES}")
966
967     if ("${CMAKE_SYSTEM_NAME}" STREQUAL "WindowsStore")
968       OCCT_INSTALL_FILE_OR_DIR ("samples/xaml" "${INSTALL_DIR_SAMPLES}")
969     endif()
970
971     install (FILES "${CMAKE_BINARY_DIR}/env.samples.${SCRIPT_EXT}" DESTINATION "${INSTALL_DIR_SAMPLES}/CSharp" RENAME "env.${SCRIPT_EXT}")
972     install (FILES "${CMAKE_BINARY_DIR}/env.samples.${SCRIPT_EXT}" DESTINATION "${INSTALL_DIR_SAMPLES}/mfc/standard" RENAME "env.${SCRIPT_EXT}")
973   endif()
974
975   OCCT_INSTALL_FILE_OR_DIR ("samples/java" "${INSTALL_DIR_SAMPLES}")
976   OCCT_INSTALL_FILE_OR_DIR ("samples/ocafsamples" "${INSTALL_DIR_SAMPLES}")
977   OCCT_INSTALL_FILE_OR_DIR ("samples/qt" "${INSTALL_DIR_SAMPLES}")
978   OCCT_INSTALL_FILE_OR_DIR ("samples/OCCTOverview/code" "${INSTALL_DIR_SAMPLES}/OCCTOverview")
979
980   install (FILES "${CMAKE_BINARY_DIR}/env.samples.${SCRIPT_EXT}" DESTINATION "${INSTALL_DIR_SAMPLES}/qt/FuncDemo" RENAME "env.${SCRIPT_EXT}")
981   install (FILES "${CMAKE_BINARY_DIR}/env.samples.${SCRIPT_EXT}" DESTINATION "${INSTALL_DIR_SAMPLES}/qt/IESample" RENAME "env.${SCRIPT_EXT}")
982   install (FILES "${CMAKE_BINARY_DIR}/env.samples.${SCRIPT_EXT}" DESTINATION "${INSTALL_DIR_SAMPLES}/qt/OCCTOverview" RENAME "env.${SCRIPT_EXT}")
983   install (FILES "${CMAKE_BINARY_DIR}/env.samples.${SCRIPT_EXT}" DESTINATION "${INSTALL_DIR_SAMPLES}/qt/Tutorial" RENAME "env.${SCRIPT_EXT}")
984 endif()
985
986 if (INSTALL_TEST_CASES)
987   OCCT_INSTALL_FILE_OR_DIR ("tests/" "${INSTALL_DIR_TESTS}")
988 endif()
989
990 list (FIND BUILD_TOOLKITS DRAWEXE DRAWEXE_INDEX)
991 if (${DRAWEXE_INDEX} GREATER -1)
992   # copy data and samples/tcl folders to install script folder
993   OCCT_INSTALL_FILE_OR_DIR ("data/" "${INSTALL_DIR_DATA}")
994   OCCT_INSTALL_FILE_OR_DIR ("samples/tcl" "${INSTALL_DIR_SAMPLES}")
995
996   # copy draw script to install script folder
997   if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/adm/templates/draw.${SCRIPT_EXT}")
998     install (FILES "${BUILD_PATCH}/adm/templates/draw.${SCRIPT_EXT}" DESTINATION  "${INSTALL_DIR_SCRIPT}"
999             PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_WRITE GROUP_EXECUTE WORLD_READ WORLD_WRITE WORLD_EXECUTE)
1000   else()
1001     install (FILES "${CMAKE_SOURCE_DIR}/adm/templates/draw.${SCRIPT_EXT}" DESTINATION  "${INSTALL_DIR_SCRIPT}"
1002             PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_WRITE GROUP_EXECUTE WORLD_READ WORLD_WRITE WORLD_EXECUTE)
1003   endif()
1004
1005   # copy draw script to CMake binary folder
1006   OCCT_COPY_FILE_OR_DIR ("adm/templates/draw.${SCRIPT_EXT}" "${CMAKE_BINARY_DIR}")
1007 endif()
1008
1009 set (SUB_CUSTOM_NAME "custom_${COMPILER}_${COMPILER_BITNESS}.${SCRIPT_EXT}")
1010
1011 if (WIN32)
1012   set (ADDITIONAL_CUSTOM_CONTENT "\nif exist \"%~dp0${SUB_CUSTOM_NAME}\" (\n  call \"%~dp0${SUB_CUSTOM_NAME}\" %1 %2 %3 \n)")
1013 else()
1014   set (ADDITIONAL_CUSTOM_CONTENT "\nif [ -e \"\${aScriptPath}/${SUB_CUSTOM_NAME}\" ]; then\n  source \"\${aScriptPath}/${SUB_CUSTOM_NAME}\" \"\$1\" \"\$2\" \nfi")
1015 endif()
1016
1017  # change custom.bat/sh
1018 if (EXISTS "${INSTALL_DIR}/${INSTALL_DIR_SCRIPT}/custom.${SCRIPT_EXT}")
1019   file (READ "${INSTALL_DIR}/${INSTALL_DIR_SCRIPT}/custom.${SCRIPT_EXT}" CUSTOM_CONTENT)
1020
1021   set (CUSTOM_CONTENT "${CUSTOM_CONTENT} ${ADDITIONAL_CUSTOM_CONTENT}")
1022
1023   file (WRITE "${INSTALL_DIR}/${INSTALL_DIR_SCRIPT}/custom.${SCRIPT_EXT}" "${CUSTOM_CONTENT}")
1024 else()
1025   OCCT_CONFIGURE_AND_INSTALL ("adm/templates/custom.${SCRIPT_EXT}.main" "custom.${SCRIPT_EXT}" "custom.${SCRIPT_EXT}" "${INSTALL_DIR_SCRIPT}")
1026 endif()
1027
1028 if (WIN32)
1029   set (THIRDPARTY_DIR_REPLACE "%THIRDPARTY_DIR%")
1030 else()
1031   set (THIRDPARTY_DIR_REPLACE "\${THIRDPARTY_DIR}")
1032 endif()
1033 get_cmake_property(USED_3RDPARTY_CACHE_VARIABLES VARIABLES)
1034 string (REGEX MATCHALL "(^|;)USED_3RDPARTY_[^;]+_DIR[^;]*" USED_3RDPARTY_CACHE_VARIABLES "${USED_3RDPARTY_CACHE_VARIABLES}")
1035 file (TO_CMAKE_PATH "${3RDPARTY_DIR}" 3RDPARTY_DIR)
1036 foreach (USED_3RDPARTY_CACHE_VARIABLE ${USED_3RDPARTY_CACHE_VARIABLES})
1037    file (TO_CMAKE_PATH "${${USED_3RDPARTY_CACHE_VARIABLE}}" ${USED_3RDPARTY_CACHE_VARIABLE})
1038    string (REPLACE "${3RDPARTY_DIR}" "${THIRDPARTY_DIR_REPLACE}" ${USED_3RDPARTY_CACHE_VARIABLE} "${${USED_3RDPARTY_CACHE_VARIABLE}}")
1039    if (NOT WIN32)
1040      string (REGEX REPLACE ";" ":" ${USED_3RDPARTY_CACHE_VARIABLE} "${${USED_3RDPARTY_CACHE_VARIABLE}}")
1041    endif()
1042 endforeach()
1043
1044 # write current custom.bat/sh (for install directory)
1045 set (SUB_CUSTOM_BUILD_NAME "custom_${COMPILER}_${COMPILER_BITNESS}.install.${SCRIPT_EXT}")
1046 OCCT_CONFIGURE_AND_INSTALL ("adm/templates/custom.install.${SCRIPT_EXT}.in" "${SUB_CUSTOM_BUILD_NAME}" "${SUB_CUSTOM_NAME}" "${INSTALL_DIR_SCRIPT}")
1047
1048 # write current custom.bat/sh (for build directory)
1049 OCCT_CONFIGURE ("adm/templates/custom.build.${SCRIPT_EXT}.in" "${SUB_CUSTOM_NAME}")
1050
1051 if (BUILD_SAMPLES_MFC OR BUILD_SAMPLES_QT)
1052   OCCT_INSTALL_FILE_OR_DIR ("adm/templates/sample.${SCRIPT_EXT}" "${INSTALL_DIR_SCRIPT}")
1053   OCCT_COPY_FILE_OR_DIR    ("adm/templates/sample.${SCRIPT_EXT}" "${CMAKE_BINARY_DIR}")
1054 endif()
1055
1056 if (WIN32)
1057   # env script for draw in building environment
1058   OCCT_CONFIGURE ("adm/templates/env.${SCRIPT_EXT}.in" "env.${SCRIPT_EXT}")
1059   # install env script
1060   install (FILES "${CMAKE_BINARY_DIR}/env.${SCRIPT_EXT}" DESTINATION "${INSTALL_DIR_SCRIPT}")
1061   # copy build.bat and install.bat scripts to CMake binary folder
1062   OCCT_COPY_FILE_OR_DIR ("adm/templates/build.bat" "${CMAKE_BINARY_DIR}")
1063   OCCT_COPY_FILE_OR_DIR ("adm/templates/install.bat" "${CMAKE_BINARY_DIR}")
1064 else()
1065   set (SUB_ENV_NAME "env.${SCRIPT_EXT}")
1066   set (SUB_ENV_BUILD_NAME "env.install.${SCRIPT_EXT}")
1067   # install env script
1068   OCCT_CONFIGURE_AND_INSTALL ("adm/templates/env.install.${SCRIPT_EXT}.in" "${SUB_ENV_BUILD_NAME}" "${SUB_ENV_NAME}" "${INSTALL_DIR_SCRIPT}")
1069   # env script for draw in building environment
1070   OCCT_CONFIGURE ("adm/templates/env.build.${SCRIPT_EXT}.in" "env.${SCRIPT_EXT}")
1071 endif()
1072
1073 # copy DrawAppliInit from OCCT source to build directory
1074 if (NOT EXISTS "${CMAKE_BINARY_DIR}/DrawAppliInit")
1075   OCCT_COPY_FILE_OR_DIR (DrawAppliInit "${CMAKE_BINARY_DIR}")
1076 endif()
1077
1078 # RESOURCES
1079 FILE_TO_LIST ("adm/RESOURCES" RESOURCES)
1080 foreach(RESOURCE ${RESOURCES})
1081   get_filename_component(RESOURCE_FOLDER ${RESOURCE} DIRECTORY)
1082   if(NOT "${RESOURCE_FOLDER}" STREQUAL "")
1083     get_filename_component(RESOURCE_FOLDER ${RESOURCE_FOLDER} NAME)
1084     OCCT_INSTALL_FILE_OR_DIR ("src/${RESOURCE}" "${INSTALL_DIR_RESOURCE}/${RESOURCE_FOLDER}")
1085   else()
1086     OCCT_INSTALL_FILE_OR_DIR ("src/${RESOURCE}" "${INSTALL_DIR_RESOURCE}")
1087   endif()
1088 endforeach()
1089
1090 if (BUILD_SAMPLES_QT)
1091   FILE_TO_LIST ("adm/SAMPLES_RESOURCES" SAMPLES_RESOURCES)
1092   foreach(RESOURCE ${SAMPLES_RESOURCES})
1093     OCCT_INSTALL_FILE_OR_DIR ("samples/${RESOURCE}" "${INSTALL_DIR_RESOURCE}/samples")
1094     #message("Copy Sample resources: samples/${RESOURCE} into ${INSTALL_DIR_RESOURCE}/samples")
1095   endforeach()
1096
1097   ## Copy sources of OCCTOverview for using in the sample
1098   OCCT_INSTALL_FILE_OR_DIR ("samples/OCCTOverview/code/DataExchangeSamples.cxx" "${INSTALL_DIR_SAMPLES}/OCCTOverview/code")
1099   OCCT_INSTALL_FILE_OR_DIR ("samples/OCCTOverview/code/OcafSamples.cxx" "${INSTALL_DIR_SAMPLES}/OCCTOverview/code")
1100   OCCT_INSTALL_FILE_OR_DIR ("samples/OCCTOverview/code/GeometrySamples.cxx" "${INSTALL_DIR_SAMPLES}/OCCTOverview/code")
1101   OCCT_INSTALL_FILE_OR_DIR ("samples/OCCTOverview/code/TopologySamples.cxx" "${INSTALL_DIR_SAMPLES}/OCCTOverview/code")
1102   OCCT_INSTALL_FILE_OR_DIR ("samples/OCCTOverview/code/TriangulationSamples.cxx" "${INSTALL_DIR_SAMPLES}/OCCTOverview/code")
1103   OCCT_INSTALL_FILE_OR_DIR ("samples/OCCTOverview/code/Viewer2dSamples.cxx" "${INSTALL_DIR_SAMPLES}/OCCTOverview/code")
1104   OCCT_INSTALL_FILE_OR_DIR ("samples/OCCTOverview/code/Viewer3dSamples.cxx" "${INSTALL_DIR_SAMPLES}/OCCTOverview/code")
1105 endif()
1106
1107
1108 # patch installed DrawDefault file if BUILD_SHARED_LIBRARY_NAME_POSTFIX is changed
1109 if (NOT "${BUILD_SHARED_LIBRARY_NAME_POSTFIX}" STREQUAL "")
1110   OCCT_UPDATE_DRAW_DEFAULT_FILE()
1111 endif()
1112
1113 # include patched toolkit projects or original ones
1114 foreach (BUILD_TOOLKIT ${BUILD_TOOLKITS})
1115   OCCT_ADD_SUBDIRECTORY ("src/${BUILD_TOOLKIT}")
1116 endforeach()
1117
1118 if (BUILD_DOC_Overview)
1119   OCCT_ADD_SUBDIRECTORY (dox)
1120 endif()
1121
1122 # patch DRAWEXE
1123 if (MSVC AND 3RDPARTY_DLL_DIRS)
1124   list (FIND BUILD_TOOLKITS DRAWEXE DRAWEXE_INDEX)
1125   if (${DRAWEXE_INDEX} GREATER -1)
1126     list (REMOVE_DUPLICATES 3RDPARTY_DLL_DIRS)
1127     set (3RDPARTY_DLL_DIRS_FOR_PATH "")
1128
1129     foreach (3RDPARTY_DLL_DIR ${3RDPARTY_DLL_DIRS})
1130       set (3RDPARTY_DLL_DIRS_FOR_PATH "${3RDPARTY_DLL_DIRS_FOR_PATH};${3RDPARTY_DLL_DIR}")
1131     endforeach()
1132
1133     OCCT_MAKE_COMPILER_BITNESS()
1134     set (X_COMPILER_BITNESS "x64")
1135     if ("${COMPILER_BITNESS}" STREQUAL "32")
1136       set (X_COMPILER_BITNESS "Win32")
1137     endif()
1138
1139     OCCT_CONFIGURE ("adm/templates/DRAWEXE.vcxproj.user.in" "${CMAKE_BINARY_DIR}/src/DRAWEXE/DRAWEXE.vcxproj.user")
1140   endif()
1141 endif()
1142
1143 # include patched toolkit projects or original ones
1144 if (BUILD_TOOL_TOOLKITS)
1145   foreach (BUILD_TOOL_TOOLKIT ${BUILD_TOOL_TOOLKITS})
1146     OCCT_ADD_SUBDIRECTORY ("tools/${BUILD_TOOL_TOOLKIT}")
1147   endforeach()
1148 endif()
1149
1150 message (STATUS "Info: \(${CURRENT_TIME}\) OCCT toolkits processed")
1151 # samples do not support patch usage
1152 if (BUILD_SAMPLES_MFC OR BUILD_SAMPLES_QT)
1153   set (OCCT_ROOT ${CMAKE_SOURCE_DIR})
1154 endif()
1155
1156 if (BUILD_SAMPLES_MFC)
1157   set (MFC_STANDARD_SAMPLES_DIR ${OCCT_ROOT}/samples/mfc/standard)
1158   set (COMMON_WINMAIN_FILE      ${MFC_STANDARD_SAMPLES_DIR}/Common/Winmain.cpp)
1159
1160   add_subdirectory(samples/mfc/standard/mfcsample)
1161   add_subdirectory(samples/mfc/standard/01_Geometry)
1162   add_subdirectory(samples/mfc/standard/02_Modeling)
1163   add_subdirectory(samples/mfc/standard/03_ImportExport)
1164   add_subdirectory(samples/mfc/standard/04_HLR)
1165
1166   message (STATUS "Info: \(${CURRENT_TIME}\) MFC Sample projects added")
1167 endif()
1168
1169 OCCT_MODULES_AND_TOOLKITS (SAMPLES "SAMPLES_TOOLKITS" OCCT_SAMPLES)
1170
1171 if (BUILD_Inspector OR BUILD_SAMPLES_QT)
1172   if (BUILD_SAMPLES_QT)
1173     if (NOT Qt5_FOUND OR "${Qt5Gui_EGL_INCLUDE_DIRS}" STREQUAL "" OR NOT WIN32)
1174       list (REMOVE_ITEM qt_SAMPLES_TOOLKITS AndroidQt)
1175       message (STATUS "Info: AndroidQt sample excluded due to OS is not Windows or Qt is configured without ANGLE")
1176     endif()
1177   else()
1178     list (REMOVE_ITEM OCCT_SAMPLES qt)
1179     message (STATUS "Info: qt samples excluded due to BUILD_SAMPLES_QT is disabled")
1180   endif()
1181
1182   foreach (OCCT_SAMPLE ${OCCT_SAMPLES})
1183     list (APPEND BUILD_SAMPLE_TOOLKITS ${${OCCT_SAMPLE}_SAMPLES_TOOLKITS})
1184
1185     # collect all the headers to <binary dir>/inc/samples folder
1186     string(TIMESTAMP CURRENT_TIME "%H:%M:%S")
1187     message (STATUS "Info: \(${CURRENT_TIME}\) ${OCCT_SAMPLE} Sample projects added")
1188
1189     # include patched toolkit projects or original ones
1190     foreach (BUILD_SAMPLE_TOOLKIT ${${OCCT_SAMPLE}_SAMPLES_TOOLKITS})
1191       OCCT_ADD_SUBDIRECTORY ("samples/${OCCT_SAMPLE}/${BUILD_SAMPLE_TOOLKIT}")
1192     endforeach()
1193   endforeach()
1194 endif()
1195
1196 if (BUILD_MODULE_UwpSample)
1197   add_subdirectory(samples/xaml)
1198 endif()
1199
1200 if (BUILD_TOOL_TOOLKITS)
1201   # copy tinspector script to install script folder
1202   if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/adm/templates/inspector.${SCRIPT_EXT}")
1203     install (FILES "${BUILD_PATCH}/adm/templates/inspector.${SCRIPT_EXT}" DESTINATION  "${INSTALL_DIR_SCRIPT}"
1204             PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_WRITE GROUP_EXECUTE WORLD_READ WORLD_WRITE WORLD_EXECUTE)
1205   else()
1206     install (FILES "${CMAKE_SOURCE_DIR}/adm/templates/inspector.${SCRIPT_EXT}" DESTINATION  "${INSTALL_DIR_SCRIPT}"
1207             PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_WRITE GROUP_EXECUTE WORLD_READ WORLD_WRITE WORLD_EXECUTE)
1208   endif()
1209
1210   set (OpenCASCADE_BINARY_DIR "${INSTALL_DIR}/${INSTALL_DIR_BIN}")
1211   # patch TInspectorEXE
1212   OCCT_CONFIGURE ("adm/templates/TInspectorEXE.vcxproj.user.in" "${CMAKE_BINARY_DIR}/tools/TInspectorEXE/TInspectorEXE.vcxproj.user")
1213 endif()
1214
1215 # Prepare variables for configuration of OpenCASCADE cmake config file
1216 set (OCCT_MODULES_ENABLED)
1217 set (OCCT_LIBRARIES)
1218 set (SET_OpenCASCADE_MODULES_TOOLKITS "\n# List of available OpenCASCADE libraries for each module\n")
1219 set (OCCT_COMPILE_DEFINITIONS)
1220
1221 foreach (OCCT_TOOLKIT ${BUILD_TOOLKITS})
1222   if (TARGET ${OCCT_TOOLKIT})
1223
1224     # get all libraries
1225     get_target_property (${OCCT_TOOLKIT}_TYPE ${OCCT_TOOLKIT} "TYPE")
1226     if ("${${OCCT_TOOLKIT}_TYPE}" STREQUAL "STATIC_LIBRARY" OR "${${OCCT_TOOLKIT}_TYPE}" STREQUAL "SHARED_LIBRARY" )
1227       list (APPEND OCCT_LIBRARIES ${OCCT_TOOLKIT})
1228
1229       # get all modules
1230       get_target_property (${OCCT_TOOLKIT}_MODULE ${OCCT_TOOLKIT} "MODULE")
1231       list (APPEND OCCT_MODULES_ENABLED ${${OCCT_TOOLKIT}_MODULE})
1232       list (APPEND OpenCASCADE_${${OCCT_TOOLKIT}_MODULE}_TOOLKITS ${OCCT_TOOLKIT})
1233
1234       # get compile definitions of target directory
1235       get_directory_property (COMPILE_DEFINITIONS DIRECTORY "${${OCCT_TOOLKIT}_SOURCE_DIR}" "COMPILE_DEFINITIONS")
1236       list (APPEND OCCT_COMPILE_DEFINITIONS ${COMPILE_DEFINITIONS})
1237     endif()
1238   endif()
1239 endforeach()
1240 list (REMOVE_DUPLICATES OCCT_MODULES_ENABLED)
1241 list (REMOVE_DUPLICATES OCCT_COMPILE_DEFINITIONS)
1242 # these macros are defined for specific tookits, not globalwise
1243 list (REMOVE_ITEM OCCT_COMPILE_DEFINITIONS HAVE_OPENGL)
1244 list (REMOVE_ITEM OCCT_COMPILE_DEFINITIONS HAVE_GLES2)
1245
1246 # export compile definitions and C/C++ flags for each configuration to OpenCASCADE config files
1247 foreach (OCCT_CONFIGURATION ${CMAKE_CONFIGURATION_TYPES})
1248   set (SET_OpenCASCADE_COMPILE_DEFINITIONS)
1249   string (TOUPPER "${OCCT_CONFIGURATION}" OCCT_CONFIGURATION_UPPER)
1250   string (TOLOWER "${OCCT_CONFIGURATION}" OCCT_CONFIGURATION_LOWER)
1251   foreach(COMPILE_DEFINITION ${OCCT_COMPILE_DEFINITIONS})
1252     string(REPLACE "(" "\\(" COMPILE_DEFINITION "${COMPILE_DEFINITION}")
1253     string(REPLACE ")" "\\)" COMPILE_DEFINITION "${COMPILE_DEFINITION}")
1254     set (SET_OpenCASCADE_COMPILE_DEFINITIONS "${SET_OpenCASCADE_COMPILE_DEFINITIONS}set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS $<$<CONFIG:${OCCT_CONFIGURATION}>:${COMPILE_DEFINITION}>)\n")
1255   endforeach()
1256   set (SET_OpenCASCADE_CMAKE_C_FLAGS "${CMAKE_C_FLAGS_${OCCT_CONFIGURATION_UPPER}}")
1257   set (SET_OpenCASCADE_CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_${OCCT_CONFIGURATION_UPPER}}")
1258   configure_file("${CMAKE_SOURCE_DIR}/adm/templates/OpenCASCADECompileDefinitionsAndFlags.cmake.in" "OpenCASCADECompileDefinitionsAndFlags-${OCCT_CONFIGURATION_LOWER}.cmake" @ONLY)
1259 endforeach()
1260 # install OpenCASCADE config file with compile definitions and C/C++ flags ONLY for current configuration
1261 install (CODE "string (TOLOWER \"\${CMAKE_INSTALL_CONFIG_NAME}\" CMAKE_INSTALL_CONFIG_NAME_LOWER)")
1262 install (CODE "file(INSTALL FILES \"${CMAKE_BINARY_DIR}/OpenCASCADECompileDefinitionsAndFlags-\${CMAKE_INSTALL_CONFIG_NAME_LOWER}.cmake\" DESTINATION \"${INSTALL_DIR}/${INSTALL_DIR_CMAKE}/\" TYPE FILE)")
1263
1264 foreach (OCCT_MODULE ${OCCT_MODULES})
1265   if (BUILD_MODULE_${OCCT_MODULE})
1266     set (SET_OpenCASCADE_MODULES_TOOLKITS "${SET_OpenCASCADE_MODULES_TOOLKITS}set (OpenCASCADE_${OCCT_MODULE}_LIBRARIES ${OpenCASCADE_${OCCT_MODULE}_TOOLKITS})\n")
1267   endif()
1268
1269   # sort enabled modules for correct work of OpenCASCADE config file
1270   list(FIND OCCT_MODULES_ENABLED "${OCCT_MODULE}" OCCT_MODULE_INDEX)
1271   if (NOT ${OCCT_MODULE_INDEX} EQUAL -1)
1272     list (APPEND OCCT_MODULES_ENABLED_SORTED ${OCCT_MODULE})
1273   endif()
1274 endforeach()
1275 set (OCCT_MODULES_ENABLED ${OCCT_MODULES_ENABLED_SORTED})
1276
1277 # Add all targets to the build-tree export set
1278 export (TARGETS ${OCCT_LIBRARIES} FILE "${CMAKE_BINARY_DIR}/OpenCASCADETargets.cmake")
1279
1280 # Export the package for use from the build-tree
1281 # (this registers the build-tree with a global CMake-registry)
1282 export(PACKAGE OpenCASCADE)
1283
1284 if (CMAKE_BUILD_TYPE)
1285   set (SET_OpenCASCADE_BUILD_TYPE "set (OpenCASCADE_BUILD_TYPE        \"${CMAKE_BUILD_TYPE}\")")
1286 endif()
1287
1288 if (BUILD_SHARED_LIBS)
1289   set (SET_OpenCASCADE_LINKER_FLAGS "set (OpenCASCADE_LINKER_FLAGS   \"${CMAKE_SHARED_LINKER_FLAGS}\")")
1290 else()
1291   set (SET_OpenCASCADE_LINKER_FLAGS "set (OpenCASCADE_LINKER_FLAGS   \"${CMAKE_STATIC_LINKER_FLAGS}\")")
1292 endif()
1293
1294 if (WIN32)
1295   set (SET_OpenCASCADE_WITH_D3D "set (OpenCASCADE_WITH_D3D       ${USE_D3D})")
1296 endif()
1297 if (APPLE)
1298   set (SET_OpenCASCADE_WITH_GLX "set (OpenCASCADE_WITH_GLX       ${USE_XLIB})")
1299 endif()
1300
1301 # Configure and install cmake config file
1302 configure_file("${CMAKE_SOURCE_DIR}/adm/templates/OpenCASCADEConfig.cmake.in" "OpenCASCADEConfig.cmake" @ONLY)
1303 install(FILES "${CMAKE_BINARY_DIR}/OpenCASCADEConfig.cmake" DESTINATION  "${INSTALL_DIR_CMAKE}")
1304
1305 # Configure cmake version file
1306 include(CMakePackageConfigHelpers)
1307 write_basic_package_version_file( ${CMAKE_BINARY_DIR}/OpenCASCADEConfigVersion.cmake
1308                                   VERSION ${OCC_VERSION_MAJOR}.${OCC_VERSION_MINOR}.${OCC_VERSION_MAINTENANCE}
1309                                   COMPATIBILITY ExactVersion )
1310
1311 # Install cmake version file
1312 install (FILES "${CMAKE_BINARY_DIR}/OpenCASCADEConfigVersion.cmake" DESTINATION "${INSTALL_DIR_CMAKE}")
1313
1314 # Install the export set for use with the install-tree for each configuration
1315 foreach (OCCT_MODULE ${OCCT_MODULES_ENABLED})
1316   install(EXPORT OpenCASCADE${OCCT_MODULE}Targets DESTINATION "${INSTALL_DIR_CMAKE}")
1317 endforeach()
1318
1319 # Update generated OpenCASCADETargets-*.cmake files
1320 # to have correct paths to libraries depending on the configuration
1321 OCCT_UPDATE_TARGET_FILE ()
1322
1323 message (STATUS "Info: \(${CURRENT_TIME}\) OCCT configuration files prepared")