0026443: Offset surface hangs up
[occt.git] / CMakeLists.txt
index 70cc241..7509a5b 100644 (file)
-cmake_minimum_required ( VERSION 2.6)
+cmake_minimum_required (VERSION 2.8.12 FATAL_ERROR)
 
-if (NOT BUILD_TYPE)
-  set(BUILD_TYPE "Release" CACHE STRING "Build type of the OCCT" FORCE)
-  SET_PROPERTY(CACHE BUILD_TYPE PROPERTY STRINGS Release Debug)
+set (CMAKE_SUPPRESS_REGENERATION TRUE)
+
+set (CMAKE_CONFIGURATION_TYPES Release Debug RelWithDebInfo CACHE INTERNAL "" FORCE)
+
+# macro: include patched file if it exists
+macro (OCCT_INCLUDE_CMAKE_FILE BEING_INCLUDED_FILE)
+  if (APPLY_OCCT_PATCH_DIR AND EXISTS "${APPLY_OCCT_PATCH_DIR}/${BEING_INCLUDED_FILE}.cmake")
+    include (${APPLY_OCCT_PATCH_DIR}/${BEING_INCLUDED_FILE}.cmake)
+  else()
+    include (${CMAKE_SOURCE_DIR}/${BEING_INCLUDED_FILE}.cmake)
+  endif()
+endmacro()
+
+# include variable description
+OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/vardescr")
+
+# set type of OCCT libraries
+if (NOT BUILD_LIBRARY_TYPE)
+  set (BUILD_LIBRARY_TYPE "Shared" CACHE STRING "${BUILD_LIBRARY_TYPE_DESCR}" FORCE)
+  SET_PROPERTY(CACHE BUILD_LIBRARY_TYPE PROPERTY STRINGS Shared Static)
+endif()
+
+if ("${BUILD_LIBRARY_TYPE}" STREQUAL "Shared")
+  set (BUILD_SHARED_LIBS ON)
+else()
+  unset (BUILD_SHARED_LIBS)
 endif()
 
-set(CMAKE_CONFIGURATION_TYPES ${BUILD_TYPE} CACHE INTERNAL "" FORCE)
+# the name of the project
+project (OCCT)
 
-project(OCCT)
+# Solution folder property
+set_property (GLOBAL PROPERTY USE_FOLDERS ON)
 
-set_property(GLOBAL PROPERTY 3RDPARTY_USE_FOLDERS ON)
+set (INSTALL_OCCT_TEST_CASES OFF CACHE BOOL "${INSTALL_OCCT_TEST_CASES_DESCR}")
+# a single-configuration generator like the Makefile generator defines CMAKE_BUILD_TYPE variable
+# check this variable and set if it's required
+if (DEFINED CMAKE_BUILD_TYPE AND NOT CMAKE_BUILD_TYPE) # single-configuration generator.
+  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)
+endif()
 
-set(BUILD_SHARED_LIBS ON)
+# enable extended messages of many OCCT algorithms
+set (OCCT_ALGO_EXTENDED_OUTPUT OFF CACHE BOOL "${OCCT_ALGO_EXTENDED_OUTPUT_DESCR}")
+if (OCCT_ALGO_EXTENDED_OUTPUT)
+  add_definitions (-DOCCT_DEBUG)
+endif()
 
-IF("${BUILD_TYPE}" STREQUAL "${CMAKE_BUILD_TYPE}")
-  SET(CHANGES_ARE_NEEDED OFF)
-ELSE()
-  SET(CHANGES_ARE_NEEDED ON)
-ENDIF()
+# copy samples to install directory
+set (INSTALL_OCCT_SAMPLES OFF CACHE BOOL "${INSTALL_OCCT_SAMPLES_DESCR}")
 
-MATH(EXPR COMPILER_BITNESS "32 + 32*(${CMAKE_SIZEOF_VOID_P}/8)")
+# install dir of the built project
+set (INSTALL_DIR "" CACHE PATH "${INSTALL_DIR_DESCR}" )
+set (CMAKE_INSTALL_PREFIX "${INSTALL_DIR}" CACHE INTERNAL "" FORCE )
 
-SET( CMAKE_BUILD_TYPE ${BUILD_TYPE} CACHE INTERNAL "Build type of the OCCT" FORCE )
+set (APPLY_OCCT_PATCH_DIR "" CACHE PATH "${APPLY_OCCT_PATCH_DIR_DESCR}")
 
-SET( INSTALL_DIR "" CACHE PATH "Directory contains install files of the OCCT" )
-SET( CMAKE_INSTALL_PREFIX "${INSTALL_DIR}" CACHE INTERNAL "" FORCE )
+# the list of being built toolkits
+set (BUILD_ADDITIONAL_TOOLKITS "" CACHE STRING "${BUILD_ADDITIONAL_TOOLKITS_DESCR}")
+separate_arguments (BUILD_ADDITIONAL_TOOLKITS)
 
-set (BUILD_TOOLKITS "" CACHE STRING "Toolkits are included in OCCT")
-separate_arguments(BUILD_TOOLKITS)
+if (MSVC)
+  set (BUILD_MODULE_OcctMfcSamples OFF CACHE BOOL "${BUILD_MODULE_OcctMfcSamples_DESCR}")
+endif()
 
-include(adm/cmake/CMakeModules.txt)
+# whether use optional 3rdparty or not
+if (APPLE)
+  set (USE_GLX OFF CACHE BOOL "${USE_GLX_DESCR}")
+endif()
 
-if (WIN32)
-  set(SCRIPT_EXT bat)
-else()
-  set(SCRIPT_EXT sh)
-endif()
-
-if (DEFINED MSVC70)
-  SET(COMPILER vc7)
-  add_definitions(/arch:SSE2)
-elseif (DEFINED MSVC80)
-  SET(COMPILER vc8)
-  add_definitions(/arch:SSE2)
-elseif (DEFINED MSVC90)
-  SET(COMPILER vc9)
-  add_definitions(/arch:SSE2)
-elseif (DEFINED MSVC10)
-  SET(COMPILER vc10)
-  add_definitions(/arch:SSE2)
-elseif (DEFINED MSVC11)
-  SET(COMPILER vc11)
-else()
-  SET(COMPILER ${CMAKE_GENERATOR})
+set (USE_VTK OFF CACHE BOOL "${USE_VTK_DESCR}")
+
+# include occt macros
+OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/occt_macros")
+
+# include the patched or original list of modules
+# list <MODULENAME>_TOOLKITS is created foreach module and contains its toolkits
+# list <OCCT_MODULES> will contain all modules
+OCCT_MODULES_AND_TOOLKITS (OCCT_MODULES)
+
+foreach (OCCT_MODULE ${OCCT_MODULES})
+  BUILD_MODULE (${OCCT_MODULE})
+endforeach()
+
+# Overview
+set (BUILD_DOC_OcctOverview OFF CACHE BOOL "${BUILD_DOC_OcctOverview_DESCR}")
+
+if (NOT USE_VTK)
+  list (REMOVE_ITEM Visualization_TOOLKITS TKIVtk)
+  list (REMOVE_ITEM Draw_TOOLKITS TKIVtkDraw)
 endif()
 
-if (${COMPILER_BITNESS} STREQUAL 64)
-  add_definitions(-D_OCC64)
+# accumulate used toolkits (first level) in BUILD_TOOLKITS variable
+list (APPEND BUILD_TOOLKITS ${BUILD_ADDITIONAL_TOOLKITS})
+
+foreach (OCCT_MODULE ${OCCT_MODULES})
+  if (BUILD_MODULE_${OCCT_MODULE})
+    list (APPEND BUILD_TOOLKITS ${${OCCT_MODULE}_TOOLKITS})
+  endif()
+endforeach()
+
+# DRAWEXE excluded when library build is static
+if (NOT BUILD_SHARED_LIBS)
+  list (REMOVE_ITEM BUILD_TOOLKITS DRAWEXE)
+  message (STATUS "Info: DRAWEXE is not included due to ${BUILD_LIBRARY_TYPE} build library type")
 endif()
 
-add_definitions(-DCSFDB)
-if(WIN32)
-  add_definitions(/DWNT -wd4996)
-elseif(APPLE)
-  add_definitions(-fexceptions -fPIC -DOCC_CONVERT_SIGNALS -DHAVE_WOK_CONFIG_H -DHAVE_CONFIG_H)
+# accumulate all used toolkits
+list (REMOVE_DUPLICATES BUILD_TOOLKITS)
+set (RAW_BUILD_TOOLKITS)
+foreach(BUILD_TOOLKIT ${BUILD_TOOLKITS})
+  OCCT_TOOLKIT_FULL_DEP (${BUILD_TOOLKIT} TOOLKIT_FULL_DEPS)
+  list (APPEND RAW_BUILD_TOOLKITS ${BUILD_TOOLKIT} ${TOOLKIT_FULL_DEPS})
+endforeach()
+
+list (REMOVE_DUPLICATES RAW_BUILD_TOOLKITS)
+set (BUILD_TOOLKITS ${RAW_BUILD_TOOLKITS})
+
+# include the patched or original list of definitions and flags
+OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/occt_defs_flags")
+
+OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/3rdparty_macro")
+
+# Rebuild *.yacc and *.lex files that are contained by TKMath toolkit
+list (FIND BUILD_TOOLKITS TKMath   CAN_REBUILD_PDC_FOR_TKMATH)
+list (FIND BUILD_TOOLKITS StepFile CAN_REBUILD_PDC_FOR_STEPFILE)
+
+if (NOT "${CAN_REBUILD_PDC_FOR_TKMATH}" STREQUAL "-1" OR NOT "${CAN_REBUILD_PDC_FOR_STEPFILE}" STREQUAL "-1")
+  set (REBUILD_PLATFORM_DEPENDENT_CODE OFF CACHE BOOL "${REBUILD_PLATFORM_DEPENDENT_CODE_DESCR}")
 else()
-  add_definitions(-fexceptions -fPIC -DOCC_CONVERT_SIGNALS -DHAVE_WOK_CONFIG_H -DHAVE_CONFIG_H -DLIN)
-endif()
-
-string(REGEX MATCH "EHsc" ISFLAG "${CMAKE_CXX_FLAGS}")
-IF(ISFLAG)
-  STRING(REGEX REPLACE "EHsc" "EHa" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
-ELSEIF(WIN32)
-  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -EHa")
-ENDIF()
-
-IF(WIN32)
-  IF(NOT DEFINED MSVC70 AND NOT DEFINED MSVC80)
-    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -MP")
-  ENDIF()
-ENDIF()
-
-# warning level 4
-IF(MSVC)
-  if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
-    string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
-  else()
-    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
+  OCCT_CHECK_AND_UNSET (REBUILD_PLATFORM_DEPENDENT_CODE)
+endif()
+
+if (NOT DEFINED 3RDPARTY_DIR)
+  set (3RDPARTY_DIR "" CACHE PATH ${3RDPARTY_DIR_DESCR})
+endif()
+
+# search for 3rdparty dir
+if ("${3RDPARTY_DIR}" STREQUAL "")
+  if (DEFINED ENV{3RDPARTY_DIR})
+    set (3RDPARTY_DIR "$ENV{3RDPARTY_DIR}" CACHE PATH ${3RDPARTY_DIR_DESCR} FORCE)
+  elseif (EXISTS "${CMAKE_SOURCE_DIR}/../")
+    # in version 6.7.0 and above, occt parent directory contains 3rdparties
+    get_filename_component (3RDPARTY_DIR "${CMAKE_SOURCE_DIR}/../" ABSOLUTE)
+    set (3RDPARTY_DIR "${3RDPARTY_DIR}" CACHE PATH ${3RDPARTY_DIR_DESCR} FORCE)
   endif()
-elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
-  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
 endif()
 
-SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNo_Exception")
-SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DNo_Exception")
+# search for CSF_TclLibs variable in EXTERNLIB of each being used toolkit
+OCCT_IS_PRODUCT_REQUIRED (CSF_TclLibs USE_TCL)
+
+if ("${USE_TCL}" STREQUAL ON)
+  message (STATUS "Info: TCL is used by OCCT")
+  OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/tcl")
+else()
+  OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_TCL")
+  OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_TK")
+
+  OCCT_CHECK_AND_UNSET ("INSTALL_TCL")
+endif()
 
-SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEB")
-SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DDEB")
+# search for CSF_FREETYPE variable in EXTERNLIB of each being used toolkit
+OCCT_IS_PRODUCT_REQUIRED (CSF_FREETYPE USE_FREETYPE)
 
-set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/out/lib)
-set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/out/lib)
-set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/out/bin)
+if ("${USE_FREETYPE}" STREQUAL ON)
+  message (STATUS "Info: Freetype is used by OCCT")
+  OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/freetype")
+else()
+  OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_FREETYPE")
+  OCCT_CHECK_AND_UNSET ("3RDPARTY_FREETYPE_INCLUDE_DIR_freetype2")
+  OCCT_CHECK_AND_UNSET ("3RDPARTY_FREETYPE_INCLUDE_DIR_ft2build")
+  OCCT_CHECK_AND_UNSET ("INSTALL_FREETYPE")
+endif()
 
-# RESOURCES
-install(DIRECTORY "${CMAKE_SOURCE_DIR}/src/DrawResources" DESTINATION  "${INSTALL_DIR}/src" )
-install(DIRECTORY "${CMAKE_SOURCE_DIR}/src/StdResource" DESTINATION  "${INSTALL_DIR}/src" )
-install(DIRECTORY "${CMAKE_SOURCE_DIR}/src/SHMessage" DESTINATION  "${INSTALL_DIR}/src" )
-install(DIRECTORY "${CMAKE_SOURCE_DIR}/src/Textures" DESTINATION  "${INSTALL_DIR}/src" )
-install(DIRECTORY "${CMAKE_SOURCE_DIR}/src/XSMessage" DESTINATION  "${INSTALL_DIR}/src" )
-install(DIRECTORY "${CMAKE_SOURCE_DIR}/src/TObj" DESTINATION  "${INSTALL_DIR}/src" )
-install(DIRECTORY "${CMAKE_SOURCE_DIR}/src/XSTEPResource" DESTINATION  "${INSTALL_DIR}/src" )
-install(DIRECTORY "${CMAKE_SOURCE_DIR}/src/XmlOcafResource" DESTINATION  "${INSTALL_DIR}/src" )
-
-install(FILES "${CMAKE_SOURCE_DIR}/src/UnitsAPI/Lexi_Expr.dat" DESTINATION  "${INSTALL_DIR}/src/UnitsAPI" )
-install(FILES "${CMAKE_SOURCE_DIR}/src/UnitsAPI/Units.dat"     DESTINATION  "${INSTALL_DIR}/src/UnitsAPI" )
-
-IF("${BUILD_TYPE}" STREQUAL "Release") 
-  SET(BUILD_SUFFIX "")
-ELSE()
-  SET(BUILD_SUFFIX "") # debug == release
-ENDIF()
-
-FUNCTION(SUBDIRECTORY_NAMES MAIN_DIRECTORY RESULT)
-  file(GLOB SUB_ITEMS "${MAIN_DIRECTORY}/*")
-  
-  foreach(ITEM ${SUB_ITEMS})
-    if(IS_DIRECTORY "${ITEM}")
-      GET_FILENAME_COMPONENT(ITEM_NAME "${ITEM}" NAME)
-      LIST(APPEND LOCAL_RESULT "${ITEM_NAME}")
-    endif()
-  endforeach()
-  set (${RESULT} ${LOCAL_RESULT} PARENT_SCOPE)
-ENDFUNCTION()
-
-FUNCTION(FIND_PRODUCT_DIR ROOT_DIR PRODUCT_NAME RESULT)
-  string( TOLOWER "${PRODUCT_NAME}" lower_PRODUCT_NAME )
-  
-  LIST(APPEND SEARCH_TEMPLATES "${lower_PRODUCT_NAME}.*${COMPILER}.*${COMPILER_BITNESS}")
-  LIST(APPEND SEARCH_TEMPLATES "${lower_PRODUCT_NAME}.*[0-9.]+.*${COMPILER}.*${COMPILER_BITNESS}")
-  LIST(APPEND SEARCH_TEMPLATES "${lower_PRODUCT_NAME}.*[0-9.]+.*${COMPILER_BITNESS}")
-  LIST(APPEND SEARCH_TEMPLATES "${lower_PRODUCT_NAME}.*[0-9.]+")
-  LIST(APPEND SEARCH_TEMPLATES "${lower_PRODUCT_NAME}")
-  
-  SUBDIRECTORY_NAMES( "${ROOT_DIR}" SUBDIR_NAME_LIST)
-  
-  FOREACH( SEARCH_TEMPLATE ${SEARCH_TEMPLATES})
-    IF(LOCAL_RESULT)
-      BREAK()
-    ENDIF()
-    
-    FOREACH(SUBDIR_NAME ${SUBDIR_NAME_LIST})
-      string( TOLOWER "${SUBDIR_NAME}" lower_SUBDIR_NAME )
-      
-      STRING(REGEX MATCH "${SEARCH_TEMPLATE}" DUMMY_VAR "${lower_SUBDIR_NAME}")
-      IF(DUMMY_VAR)
-        LIST(APPEND LOCAL_RESULT ${SUBDIR_NAME})
-      ENDIF()
-    ENDFOREACH()
-  ENDFOREACH()
-  
-  IF(LOCAL_RESULT)
-    LIST(LENGTH "${LOCAL_RESULT}" LOC_LEN)
-    MATH(EXPR LAST_ELEMENT_INDEX "${LOC_LEN}-1")
-    LIST(GET LOCAL_RESULT ${LAST_ELEMENT_INDEX} DUMMY)
-    SET(${RESULT} ${DUMMY} PARENT_SCOPE)
-  ENDIF()  
-ENDFUNCTION()
-
-IF(WIN32)
-  SET(DLL_SO "dll")
-  SET(DLL_SO_FOLDER "bin")
-  SET(DLL_SO_PREFIX "")
-ELSEIF(APPLE)
-  SET(DLL_SO "dylib")
-  SET(DLL_SO_FOLDER "lib")
-  SET(DLL_SO_PREFIX "lib")
-ELSE()
-  SET(DLL_SO "so")
-  SET(DLL_SO_FOLDER "lib")
-  SET(DLL_SO_PREFIX "lib")
-ENDIF()
-
-SET(3RDPARTY_DIR "" CACHE PATH "Directory contains required 3rdparty products")
-SET(3RDPARTY_INCLUDE_DIRS "")
-SET(3RDPARTY_NOT_INCLUDED)
-
-IF(APPLE)
-  SET(3RDPARTY_USE_GLX OFF CACHE BOOL "whether use X11 OpenGL on OSX or not")
-ENDIF()
-
-SET(3RDPARTY_USE_GL2PS OFF CACHE BOOL "whether use gl2ps product or not")
-SET(3RDPARTY_USE_FREEIMAGE OFF CACHE BOOL "whether use freeimage product or not")
-SET(3RDPARTY_USE_TBB OFF CACHE BOOL "whether use tbb product or not")
-
-SET(INSTALL_TESTS OFF CACHE BOOL "Is tests copy to install directory")
-
-MACRO(THIRDPARTY_PRODUCT PRODUCT_NAME HEADER_NAME LIBRARY_NAME)
-  IF(NOT DEFINED 3RDPARTY_${PRODUCT_NAME}_DIR)
-    SET(3RDPARTY_${PRODUCT_NAME}_DIR "" CACHE PATH "Directory contains ${PRODUCT_NAME} product")
-  ENDIF()
-  
-  IF(3RDPARTY_DIR AND ("${3RDPARTY_${PRODUCT_NAME}_DIR}" STREQUAL "" OR CHANGES_ARE_NEEDED))
-    FIND_PRODUCT_DIR("${3RDPARTY_DIR}" ${PRODUCT_NAME} ${PRODUCT_NAME}_DIR_NAME)
-    IF("${${PRODUCT_NAME}_DIR_NAME}" STREQUAL "")
-      MESSAGE(STATUS "${PRODUCT_NAME} DON'T FIND")
-    ELSE()
-      SET(3RDPARTY_${PRODUCT_NAME}_DIR "${3RDPARTY_DIR}/${${PRODUCT_NAME}_DIR_NAME}" CACHE PATH "Directory contains ${PRODUCT_NAME} product" FORCE)
-    ENDIF()
-  ENDIF()
-  
-  SET(INSTALL_${PRODUCT_NAME} OFF CACHE BOOL "Is ${PRODUCT_NAME} lib copy to install directory")
-
-  IF(3RDPARTY_${PRODUCT_NAME}_DIR)
-    IF("${3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR}" STREQUAL "" OR CHANGES_ARE_NEEDED OR "${3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR}" STREQUAL "3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR-NOTFOUND")
-      SET(3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR "3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR-NOTFOUND" CACHE FILEPATH "Directory contains headers of the ${PRODUCT_NAME} product" FORCE)
-      FIND_PATH(3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR ${HEADER_NAME} PATHS "${3RDPARTY_${PRODUCT_NAME}_DIR}/include" NO_DEFAULT_PATH)
-      
-      IF("${3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR}" STREQUAL "3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR-NOTFOUND")
-        FIND_PATH(3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR ${HEADER_NAME})
-      ENDIF()
-      
-    ENDIF()
-    
-    IF("${3RDPARTY_${PRODUCT_NAME}_LIBRARY}" STREQUAL "" OR CHANGES_ARE_NEEDED OR "${3RDPARTY_${PRODUCT_NAME}_LIBRARY}" STREQUAL "3RDPARTY_${PRODUCT_NAME}_LIBRARY-NOTFOUND")
-      SET(3RDPARTY_${PRODUCT_NAME}_LIBRARY "3RDPARTY_${PRODUCT_NAME}_LIBRARY-NOTFOUND" CACHE FILEPATH "Directory contains library of the ${PRODUCT_NAME} product" FORCE)
-      FIND_LIBRARY(3RDPARTY_${PRODUCT_NAME}_LIBRARY ${LIBRARY_NAME}  PATHS "${3RDPARTY_${PRODUCT_NAME}_DIR}/lib" NO_DEFAULT_PATH)
-      
-      # check default path for library search
-      IF("${3RDPARTY_${PRODUCT_NAME}_LIBRARY}" STREQUAL "3RDPARTY_${PRODUCT_NAME}_LIBRARY-NOTFOUND")
-        FIND_LIBRARY(3RDPARTY_${PRODUCT_NAME}_LIBRARY ${LIBRARY_NAME})
-      ENDIF()
-    ENDIF()
-    
-    IF("${3RDPARTY_${PRODUCT_NAME}_DLL}" STREQUAL "" OR CHANGES_ARE_NEEDED OR "${3RDPARTY_${PRODUCT_NAME}_DLL}" STREQUAL "3RDPARTY_${PRODUCT_NAME}_DLL-NOTFOUND")
-      SET(3RDPARTY_${PRODUCT_NAME}_DLL "3RDPARTY_${PRODUCT_NAME}_DLL-NOTFOUND" CACHE FILEPATH "Directory contains shared library of the ${PRODUCT_NAME} product" FORCE)
-      FIND_FILE(3RDPARTY_${PRODUCT_NAME}_DLL "${DLL_SO_PREFIX}${LIBRARY_NAME}.${DLL_SO}"  PATHS "${3RDPARTY_${PRODUCT_NAME}_DIR}/${DLL_SO_FOLDER}" NO_DEFAULT_PATH)
-      
-      IF("${3RDPARTY_${PRODUCT_NAME}_DLL}" STREQUAL "3RDPARTY_${PRODUCT_NAME}_DLL-NOTFOUND")
-        FIND_FILE(3RDPARTY_${PRODUCT_NAME}_DLL "${DLL_SO_PREFIX}${LIBRARY_NAME}.${DLL_SO}")
-      ENDIF()
-    ENDIF()
-    MARK_AS_ADVANCED(3RDPARTY_${PRODUCT_NAME}_DIR)
-  ENDIF()
-
-  IF(3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR)
-    SET(3RDPARTY_INCLUDE_DIRS "${3RDPARTY_INCLUDE_DIRS};${3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR}")
-  ELSE()
-    LIST(APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR)
-  ENDIF()
-
-  IF(3RDPARTY_${PRODUCT_NAME}_LIBRARY)
-    GET_FILENAME_COMPONENT(3RDPARTY_${PRODUCT_NAME}_LIBRARY_DIR "${3RDPARTY_${PRODUCT_NAME}_LIBRARY}" PATH)
-    SET(3RDPARTY_LIBRARY_DIRS "${3RDPARTY_LIBRARY_DIRS};${3RDPARTY_${PRODUCT_NAME}_LIBRARY_DIR}")
-  ELSE()
-    LIST(APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_${PRODUCT_NAME}_LIBRARY)
-  ENDIF()
-  
-  IF(3RDPARTY_${PRODUCT_NAME}_DLL)
-    #
-  ELSE()
-    LIST(APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_${PRODUCT_NAME}_DLL)
-  ENDIF()
-
-  IF(INSTALL_${PRODUCT_NAME})
-    INSTALL(FILES "${3RDPARTY_${PRODUCT_NAME}_DLL}" DESTINATION "${INSTALL_DIR}/${DLL_SO_FOLDER}")
-    SET(3RDPARTY_${PRODUCT_NAME}_DLL_DIR "")
-  ELSE()
-    GET_FILENAME_COMPONENT(3RDPARTY_${PRODUCT_NAME}_DLL_DIR "${3RDPARTY_${PRODUCT_NAME}_DLL}" PATH)
-  ENDIF()
-ENDMACRO()
-
-# TCL
-
-#tcl85 - win; tcl8.5 - lin
-IF(WIN32)
-  SET(TCL_SEP "")
-ELSE()
-  SET(TCL_SEP ".")
-ENDIF()
-  
-THIRDPARTY_PRODUCT("TCL" "tcl.h" "tcl8${TCL_SEP}5")
-
-#install tk and libs
-IF(INSTALL_TCL)
-  GET_FILENAME_COMPONENT(3RDPARTY_TK_LIB_DIR "${3RDPARTY_TCL_LIBRARY}" PATH)
-  GET_FILENAME_COMPONENT(3RDPARTY_TK_DLL_DIR "${3RDPARTY_TCL_DLL}" PATH)
-  
-  INSTALL(FILES "${3RDPARTY_TK_DLL_DIR}/${DLL_SO_PREFIX}tk8${TCL_SEP}5.${DLL_SO}" DESTINATION "${INSTALL_DIR}/${DLL_SO_FOLDER}")
-  INSTALL(DIRECTORY "${3RDPARTY_TK_LIB_DIR}/tcl8.5" DESTINATION "${INSTALL_DIR}/lib")
-  INSTALL(DIRECTORY "${3RDPARTY_TK_LIB_DIR}/tk8.5" DESTINATION "${INSTALL_DIR}/lib")
-ENDIF()
+# VTK
+if (USE_VTK)
+  add_definitions (-DHAVE_VTK)
+  OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/vtk")
+else()
+  OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_VTK")
+  OCCT_CHECK_AND_UNSET ("INSTALL_VTK")
+endif()
 
 # GLX
-IF(3RDPARTY_USE_GLX)
-  ADD_DEFINITIONS(-DMACOSX_USE_GLX)
-  
-  IF(NOT DEFINED 3RDPARTY_GLX_DIR)
-    SET(3RDPARTY_GLX_DIR "" CACHE PATH "Directory contains GLX product")
-  ENDIF()
-  
-  IF(3RDPARTY_DIR AND ("${3RDPARTY_GLX_DIR}" STREQUAL "" OR CHANGES_ARE_NEEDED))
-    FIND_PRODUCT_DIR("${3RDPARTY_DIR}" GLX GLX_DIR_NAME)
-    IF("${GLX_DIR_NAME}" STREQUAL "")
-      MESSAGE(STATUS "GLX DON'T FIND")
-    ELSE()
-      SET(3RDPARTY_GLX_DIR "${3RDPARTY_DIR}/${GLX_DIR_NAME}" CACHE PATH "Directory contains GLX product" FORCE)
-    ENDIF()
-  ENDIF()
-  
-  IF(3RDPARTY_GLX_DIR)
-    SET(3RDPARTY_GLX_INCLUDE_DIR "${3RDPARTY_GLX_DIR}/include" CACHE FILEPATH "Directory contains headers of the GLX product" FORCE)
-    SET(3RDPARTY_GLX_LIBRARY_DIR "${3RDPARTY_GLX_DIR}/lib"     CACHE FILEPATH "Directory contains library of the GLX product" FORCE)
-    
-    SET(3RDPARTY_INCLUDE_DIRS "${3RDPARTY_INCLUDE_DIRS};${3RDPARTY_GLX_INCLUDE_DIR}")
-    SET(3RDPARTY_LIBRARY_DIRS "${3RDPARTY_LIBRARY_DIRS};${3RDPARTY_GLX_LIBRARY_DIR}")
-    
-    MARK_AS_ADVANCED(3RDPARTY_GLX_DIR)
-  ELSE()
-    LIST(APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_GLX_INCLUDE_DIR)
-    LIST(APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_GLX_LIBRARY_DIR)
-  ENDIF()
-ENDIF()
-
-# FREETYPE
-THIRDPARTY_PRODUCT("FREETYPE" "ft2build.h" "freetype${BUILD_SUFFIX}")
-
-IF("${3RDPARTY_FREETYPE_INCLUDE_DIR}" STREQUAL "" OR "${3RDPARTY_FREETYPE_INCLUDE_DIR}" STREQUAL "3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR-NOTFOUND")
-  
-ELSEIF(EXISTS "${3RDPARTY_FREETYPE_INCLUDE_DIR}/freetype2/")
-  SET(3RDPARTY_INCLUDE_DIRS "${3RDPARTY_INCLUDE_DIRS};${3RDPARTY_FREETYPE_INCLUDE_DIR}/freetype2")
-ENDIF()
+if (USE_GLX)
+  add_definitions (-DMACOSX_USE_GLX)
+  OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/glx")
+endif()
 
 # FREEIMAGE
-IF(3RDPARTY_USE_FREEIMAGE)
-  ADD_DEFINITIONS(-DHAVE_FREEIMAGE) 
-
-  THIRDPARTY_PRODUCT("FREEIMAGE" "FreeImage.h" "freeimage${BUILD_SUFFIX}")
-  IF(WIN32)
-    IF("${3RDPARTY_FREEIMAGE_DIR}" STREQUAL "")
-    ELSE()
-      SET (3RDPARTY_FREEIMAGEPLUS_DIR "${3RDPARTY_FREEIMAGE_DIR}")
-    ENDIF()
-    
-    THIRDPARTY_PRODUCT("FREEIMAGEPLUS" "FreeImagePlus.h" "freeimageplus${BUILD_SUFFIX}")
-    
-  ENDIF()
-ENDIF()
+# search for CSF_FREEIMAGE variable in EXTERNLIB of each being used toolkit
+OCCT_IS_PRODUCT_REQUIRED (CSF_FREEIMAGE     CAN_USE_FREEIMAGE)
+OCCT_IS_PRODUCT_REQUIRED (CSF_FreeImagePlus CAN_USE_FREEIMAGEPLUS)
+
+if (CAN_USE_FREEIMAGE OR CAN_USE_FREEIMAGEPLUS)
+  set (USE_FREEIMAGE OFF CACHE BOOL "${USE_FREEIMAGE_DESCR}")
+
+  if (USE_FREEIMAGE)
+    add_definitions (-DHAVE_FREEIMAGE)
+    OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/freeimage")
+    OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/freeimageplus")
+  else()
+    OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_FREEIMAGE")
+    OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_FREEIMAGEPLUS")
+    OCCT_CHECK_AND_UNSET ("INSTALL_FREEIMAGE")
+    OCCT_CHECK_AND_UNSET ("INSTALL_FREEIMAGEPLUS")
+  endif()
+else()
+  OCCT_CHECK_AND_UNSET ("USE_FREEIMAGE")
+
+  OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_FREEIMAGE")
+  OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_FREEIMAGEPLUS")
+  OCCT_CHECK_AND_UNSET ("INSTALL_FREEIMAGE")
+  OCCT_CHECK_AND_UNSET ("INSTALL_FREEIMAGEPLUS")
+endif()
 
 # GL2PS
-IF(3RDPARTY_USE_GL2PS)
-  ADD_DEFINITIONS(-DHAVE_GL2PS)
-  THIRDPARTY_PRODUCT("GL2PS" "gl2ps.h" "gl2ps${BUILD_SUFFIX}")
-ENDIF()
+# search for CSF_GL2PS variable in EXTERNLIB of each being used toolkit
+OCCT_IS_PRODUCT_REQUIRED (CSF_GL2PS CAN_USE_GL2PS)
+
+if (NOT DEFINED ANDROID AND CAN_USE_GL2PS)
+  set (USE_GL2PS OFF CACHE BOOL "${USE_GL2PS_DESCR}")
+
+  if (USE_GL2PS)
+    add_definitions (-DHAVE_GL2PS)
+    OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/gl2ps")
+  else()
+    OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_GL2PS")
+    OCCT_CHECK_AND_UNSET ("INSTALL_GL2PS")
+  endif()
+else()
+  OCCT_CHECK_AND_UNSET ("USE_GL2PS")
+
+  OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_GL2PS")
+  OCCT_CHECK_AND_UNSET ("INSTALL_GL2PS")
+endif()
 
 # TBB
-IF (3RDPARTY_USE_TBB)
-  ADD_DEFINITIONS(-DHAVE_TBB)
-
-  IF(${COMPILER_BITNESS} STREQUAL 32)
-    SET (TBB_ARCH_NAME ia32)
-  ELSE()
-    SET (TBB_ARCH_NAME intel64)
-  ENDIF()
-  
-  IF(NOT DEFINED 3RDPARTY_TBB_DIR)
-    SET(3RDPARTY_TBB_DIR "" CACHE PATH "Directory contains tbb product")
-  ENDIF()
-  
-  SET(3RDPARTY_TBB_DIR_NAME "")
-  IF(3RDPARTY_DIR AND ("${3RDPARTY_TBB_DIR}" STREQUAL "" OR CHANGES_ARE_NEEDED))
-    FIND_PRODUCT_DIR("${3RDPARTY_DIR}" "TBB" 3RDPARTY_TBB_DIR_NAME)
-    IF("${3RDPARTY_TBB_DIR_NAME}" STREQUAL "")
-      MESSAGE(STATUS "TBB DON'T FIND")
-    ELSE()
-      SET(3RDPARTY_TBB_DIR "${3RDPARTY_DIR}/${3RDPARTY_TBB_DIR_NAME}" CACHE PATH "Directory contains tbb product" FORCE)
-    ENDIF()
-  ENDIF()
-  
-  SET(INSTALL_TBB OFF CACHE BOOL "Is tbb lib copy to install directory")
-
-  IF(3RDPARTY_TBB_DIR)
-    IF("${3RDPARTY_TBB_INCLUDE_DIR}" STREQUAL "" OR CHANGES_ARE_NEEDED)
-      SET(3RDPARTY_TBB_INCLUDE_DIR "3RDPARTY_TBB_INCLUDE_DIR-NOTFOUND" CACHE PATH "Directory contains headers of the tbb product" FORCE)
-      FIND_PATH(3RDPARTY_TBB_INCLUDE_DIR tbb/tbb.h PATHS "${3RDPARTY_TBB_DIR}/include")
-    ENDIF()
-
-    SET(TBB_DEBUG_POSTFIX "")
-    if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
-      SET(TBB_DEBUG_POSTFIX "") # _debug postfix removed
-    ENDIF()
-    
-    IF("${3RDPARTY_TBB_LIBRARY}" STREQUAL "" OR CHANGES_ARE_NEEDED OR "${3RDPARTY_TBB_LIBRARY}" STREQUAL "3RDPARTY_TBB_LIBRARY-NOTFOUND")
-      SET(3RDPARTY_TBB_LIBRARY "3RDPARTY_TBB_LIBRARY-NOTFOUND" CACHE PATH "Directory contains library of the tbb product" FORCE)
-      FIND_LIBRARY(3RDPARTY_TBB_LIBRARY tbb${TBB_DEBUG_POSTFIX} PATHS "${3RDPARTY_TBB_DIR}/lib/${TBB_ARCH_NAME}/${COMPILER}" NO_DEFAULT_PATH)
-      
-      IF("${3RDPARTY_TBB_LIBRARY}" STREQUAL "3RDPARTY_TBB_LIBRARY-NOTFOUND")
-        FIND_LIBRARY(3RDPARTY_TBB_LIBRARY tbb${TBB_DEBUG_POSTFIX})
-      ENDIF()
-    ENDIF()
-
-    IF("${3RDPARTY_TBB_MALLOC_LIBRARY}" STREQUAL "" OR CHANGES_ARE_NEEDED OR "${3RDPARTY_TBB_MALLOC_LIBRARY}" STREQUAL "3RDPARTY_TBB_MALLOC_LIBRARY-NOTFOUND")
-      SET(3RDPARTY_TBB_MALLOC_LIBRARY "3RDPARTY_TBB_MALLOC_LIBRARY-NOTFOUND" CACHE PATH "Directory contains library of the tbb malloc product" FORCE)
-      FIND_LIBRARY(3RDPARTY_TBB_MALLOC_LIBRARY tbbmalloc${TBB_DEBUG_POSTFIX} PATHS "${3RDPARTY_TBB_DIR}/lib/${TBB_ARCH_NAME}/${COMPILER}" NO_DEFAULT_PATH)
-      
-      IF("${3RDPARTY_TBB_MALLOC_LIBRARY}" STREQUAL "3RDPARTY_TBB_MALLOC_LIBRARY-NOTFOUND")
-        FIND_LIBRARY(3RDPARTY_TBB_MALLOC_LIBRARY tbbmalloc${TBB_DEBUG_POSTFIX})
-      ENDIF()
-    ENDIF()
-    
-    
-    
-    IF("${3RDPARTY_TBB_DLL}" STREQUAL "" OR CHANGES_ARE_NEEDED)
-      SET(3RDPARTY_TBB_DLL "3RDPARTY_TBB_DLL-NOTFOUND" CACHE PATH "Directory contains shared library of the tbb product" FORCE)
-      FIND_FILE(3RDPARTY_TBB_DLL "${DLL_SO_PREFIX}tbb${TBB_DEBUG_POSTFIX}.${DLL_SO}" PATHS "${3RDPARTY_TBB_DIR}/${DLL_SO_FOLDER}/${TBB_ARCH_NAME}/${COMPILER}" NO_DEFAULT_PATH)
-      
-      IF("${3RDPARTY_TBB_DLL}" STREQUAL "3RDPARTY_TBB_DLL-NOTFOUND")
-        FIND_FILE(3RDPARTY_TBB_DLL "${DLL_SO_PREFIX}tbb${TBB_DEBUG_POSTFIX}.${DLL_SO}")
-      ENDIF()
-    ENDIF()
-    
-    IF("${3RDPARTY_TBB_MALLOC_DLL}" STREQUAL "" OR CHANGES_ARE_NEEDED)
-      SET(3RDPARTY_TBB_MALLOC_DLL "3RDPARTY_TBB_MALLOC_DLL-NOTFOUND" CACHE PATH "Directory contains shared library of the tbb malloc product" FORCE)
-      FIND_FILE(3RDPARTY_TBB_MALLOC_DLL "${DLL_SO_PREFIX}tbbmalloc${TBB_DEBUG_POSTFIX}.${DLL_SO}" PATHS "${3RDPARTY_TBB_DIR}/${DLL_SO_FOLDER}/${TBB_ARCH_NAME}/${COMPILER}" NO_DEFAULT_PATH)
-      
-      IF("${3RDPARTY_TBB_MALLOC_DLL}" STREQUAL "3RDPARTY_TBB_MALLOC_DLL-NOTFOUND")
-        FIND_FILE(3RDPARTY_TBB_MALLOC_DLL "${DLL_SO_PREFIX}tbbmalloc${TBB_DEBUG_POSTFIX}.${DLL_SO}")
-      ENDIF()
-    ENDIF()
-
-    MARK_AS_ADVANCED(3RDPARTY_TBB_DIR_NAME)
-  ELSE()
-    LIST(APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_TBB_DIR)
-  ENDIF()
-
-  IF(3RDPARTY_TBB_INCLUDE_DIR)
-    SET(3RDPARTY_INCLUDE_DIRS "${3RDPARTY_INCLUDE_DIRS};${3RDPARTY_TBB_INCLUDE_DIR}")
-  ELSE()
-    LIST(APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_TBB_INCLUDE_DIR)
-  ENDIF()
-
-  IF(3RDPARTY_TBB_LIBRARY)
-    GET_FILENAME_COMPONENT(3RDPARTY_TBB_LIBRARY_DIR "${3RDPARTY_TBB_LIBRARY}" PATH)
-    SET(3RDPARTY_LIBRARY_DIRS "${3RDPARTY_LIBRARY_DIRS};${3RDPARTY_TBB_LIBRARY_DIR}")
-  ELSE()
-    LIST(APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_TBB_LIBRARY)
-  ENDIF()
-  
-  IF(3RDPARTY_TBB_MALLOC_LIBRARY)
-    GET_FILENAME_COMPONENT(3RDPARTY_TBB_LIBRARY_DIR "${3RDPARTY_TBB_MALLOC_LIBRARY}" PATH)
-    SET(3RDPARTY_LIBRARY_DIRS "${3RDPARTY_LIBRARY_DIRS};${3RDPARTY_TBB_LIBRARY_DIR}")
-  ELSE()
-    LIST(APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_TBB_MALLOC_LIBRARY)
-  ENDIF()
-  
-  IF(3RDPARTY_TBB_DLL)
-    #
-  ELSE()
-    LIST(APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_TBB_DLL)
-  ENDIF()
-  
-  IF(3RDPARTY_TBB_MALLOC_DLL)
-    #
-  ELSE()
-    LIST(APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_TBB_MALLOC_DLL)
-  ENDIF()
-
-  IF(INSTALL_TBB)
-    INSTALL(FILES "${3RDPARTY_TBB_DLL}" "${3RDPARTY_TBB_MALLOC_DLL}" DESTINATION "${INSTALL_DIR}/${DLL_SO_FOLDER}")
-
-    SET(3RDPARTY_TBB_DLL_DIR "")
-    SET(3RDPARTY_TBB_MALLOC_DLL_DIR "")
-  ELSE()
-    GET_FILENAME_COMPONENT(3RDPARTY_TBB_DLL_DIR "${3RDPARTY_TBB_DLL}" PATH)
-    GET_FILENAME_COMPONENT(3RDPARTY_TBB_MALLOC_DLL_DIR "${3RDPARTY_TBB_MALLOC_DLL}" PATH)
-  ENDIF()
-ENDIF()
-
-string( REGEX REPLACE ";" " " 3RDPARTY_NOT_INCLUDED "${3RDPARTY_NOT_INCLUDED}")
-
-#CHECK ALL 3RDPARTY PATHS
-IF(3RDPARTY_NOT_INCLUDED)
-  MESSAGE(FATAL_ERROR "NOT FOUND: ${3RDPARTY_NOT_INCLUDED}" )
-ENDIF()
-
-list(REMOVE_DUPLICATES 3RDPARTY_INCLUDE_DIRS)
-string( REGEX REPLACE ";" "\n\t" 3RDPARTY_INCLUDE_DIRS_WITH_ENDS "${3RDPARTY_INCLUDE_DIRS}")
-MESSAGE(STATUS "3RDPARTY_INCLUDE_DIRS: ${3RDPARTY_INCLUDE_DIRS_WITH_ENDS}")
-include_directories( ${3RDPARTY_INCLUDE_DIRS} )
-
-list(REMOVE_DUPLICATES 3RDPARTY_LIBRARY_DIRS)
-string( REGEX REPLACE ";" "\n\t" 3RDPARTY_LIBRARY_DIRS_WITH_ENDS "${3RDPARTY_LIBRARY_DIRS}")
-MESSAGE(STATUS "3RDPARTY_LIBRARY_DIRS: ${3RDPARTY_LIBRARY_DIRS_WITH_ENDS}")
-link_directories( ${3RDPARTY_LIBRARY_DIRS} )
-
-#
-SET(RUN_PROJECT "")
-SET(CASROOT_DEFINITION "set \"CASROOT=${CMAKE_SOURCE_DIR}\"")
-SET(BIN_DIR_POSTFIX "bin")
-SET(RESOURCE_DIR_PREFIX "%SCRIPTROOT%\\src")
-
-IF("${INSTALL_DIR}" STREQUAL "")
-  MESSAGE(FATAL_ERROR "INSTALL_DIR is empty")
-ELSE()
-  # inc,data,tests DIRECTORY
-  install(DIRECTORY "${CMAKE_SOURCE_DIR}/inc"   DESTINATION  "${INSTALL_DIR}" )
-  install(DIRECTORY "${CMAKE_SOURCE_DIR}/data"  DESTINATION  "${INSTALL_DIR}" )
-  IF(INSTALL_TESTS)
-    install(DIRECTORY "${CMAKE_SOURCE_DIR}/tests" DESTINATION  "${INSTALL_DIR}" )
-  ENDIF()
-
-  # DRAW.BAT or DRAW.SH
-  install(FILES "${CMAKE_SOURCE_DIR}/adm/cmake/draw.${SCRIPT_EXT}" DESTINATION  "${INSTALL_DIR}" PERMISSIONS  OWNER_READ OWNER_WRITE OWNER_EXECUTE 
-                                                                              GROUP_READ GROUP_WRITE GROUP_EXECUTE 
-                                                                              WORLD_READ WORLD_WRITE WORLD_EXECUTE)
-
-  configure_file("${CMAKE_SOURCE_DIR}/adm/cmake/env.${SCRIPT_EXT}.in" env.${SCRIPT_EXT} @ONLY)
-  install(FILES "${OCCT_BINARY_DIR}/env.${SCRIPT_EXT}" DESTINATION  "${INSTALL_DIR}" )
-ENDIF()
-
-IF(MSVC AND "${BUILD_TYPE}" STREQUAL "Debug")
-  SET(RUN_PROJECT "start OCCT.sln")
-  SET(BIN_DIR_POSTFIX "out\\bin\\Debug")
-  SET(RESOURCE_DIR_PREFIX "%CASROOT%\\src")
-  configure_file("${CMAKE_SOURCE_DIR}/adm/cmake/env.bat.in" OCCT.bat @ONLY)
-ENDIF()
-
-include(adm/cmake/CMakeToolKitsDeps.txt)
+# search for CSF_TBB variable in EXTERNLIB of each being used toolkit
+OCCT_IS_PRODUCT_REQUIRED (CSF_TBB CAN_USE_TBB)
+
+if (NOT DEFINED ANDROID AND CAN_USE_TBB)
+  set (USE_TBB OFF CACHE BOOL "${USE_TBB_DESCR}")
+
+  if (USE_TBB)
+    add_definitions (-DHAVE_TBB)
+    OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/tbb")
+  else()
+    OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_TBB")
+    OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_TBBMALLOC")
+    OCCT_CHECK_AND_UNSET ("INSTALL_TBB")
+  endif()
+else()
+  OCCT_CHECK_AND_UNSET ("USE_TBB")
+
+  OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_TBB")
+  OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_TBBMALLOC")
+  OCCT_CHECK_AND_UNSET ("INSTALL_TBB")
+endif()
+
+# Doxygen
+if (BUILD_DOC_OcctOverview)
+  if (NOT DEFINED INSTALL_DOC_OcctOverview)
+    set (INSTALL_DOC_OcctOverview OFF CACHE BOOL "${INSTALL_DOC_OcctOverview_DESCR}")
+  endif()
+
+  if (INSTALL_DOC_OcctOverview)
+    install (DIRECTORY "${CMAKE_BINARY_DIR}/doc/overview" DESTINATION  "${INSTALL_DIR}/doc")
+
+    OCCT_INSTALL_FILE_OR_DIR ("dox/resources/overview.html" "${INSTALL_DIR}")
+  endif()
+
+  OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/doxygen")
+else()
+  OCCT_CHECK_AND_UNSET ("INSTALL_DOC_OcctOverview")
+
+  OCCT_CHECK_AND_UNSET ("3RDPARTY_DOXYGEN_EXECUTABLE")
+  OCCT_CHECK_AND_UNSET ("3RDPARTY_DOXYGEN_DOT_EXECUTABLE")
+endif()
+
+# bison 
+if (REBUILD_PLATFORM_DEPENDENT_CODE)
+  OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/bison")
+else()
+  OCCT_CHECK_AND_UNSET ("3RDPARTY_BISON_EXECUTABLE")
+endif()
+
+# flex 
+if (REBUILD_PLATFORM_DEPENDENT_CODE)
+  OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/flex")
+else()
+  OCCT_CHECK_AND_UNSET ("3RDPARTY_FLEX_EXECUTABLE")
+endif()
+
+string (REGEX REPLACE ";" " " 3RDPARTY_NOT_INCLUDED "${3RDPARTY_NOT_INCLUDED}")
+
+# check all 3rdparty paths
+if (3RDPARTY_NOT_INCLUDED)
+  message (FATAL_ERROR "NOT FOUND: ${3RDPARTY_NOT_INCLUDED}" )
+endif()
+
+if (3RDPARTY_INCLUDE_DIRS)
+  list (REMOVE_DUPLICATES 3RDPARTY_INCLUDE_DIRS)
+  string (REGEX REPLACE ";" "\n\t" 3RDPARTY_INCLUDE_DIRS_WITH_ENDS "${3RDPARTY_INCLUDE_DIRS}")
+  message (STATUS "The directories containing 3rdparty headers: ${3RDPARTY_INCLUDE_DIRS_WITH_ENDS}")
+  include_directories (${3RDPARTY_INCLUDE_DIRS})
+endif()
+
+# include <cmake binary folder>/inc
+include_directories (${CMAKE_BINARY_DIR}/inc)
+
+if (3RDPARTY_LIBRARY_DIRS)
+  list (REMOVE_DUPLICATES 3RDPARTY_LIBRARY_DIRS)
+  string (REGEX REPLACE ";" "\n\t" 3RDPARTY_LIBRARY_DIRS_WITH_ENDS "${3RDPARTY_LIBRARY_DIRS}")
+  message (STATUS "The directories containing 3rdparty libraries: ${3RDPARTY_LIBRARY_DIRS_WITH_ENDS}")
+  link_directories (${3RDPARTY_LIBRARY_DIRS})
+endif()
+
+# Get all used variables: OS_WITH_BIT, COMPILER
+OCCT_MAKE_OS_WITH_BITNESS()
+OCCT_MAKE_COMPILER_SHORT_NAME()
+
+# build directories
+set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/lib")
+set (CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/bin")
+set (CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/lib")
+
+set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/libi")
+set (CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/bini")
+set (CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/libi")
+
+set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/libd")
+set (CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/bind")
+set (CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/libd")
+
+if (WIN32) 
+  set (CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE        "${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/bin")
+  set (CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/bini")
+  set (CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG          "${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/bind")
+endif()
+
+if ("${INSTALL_DIR}" STREQUAL "")
+  get_filename_component (CMAKE_BINARY_DIR_PARENT ${CMAKE_BINARY_DIR} DIRECTORY)
+
+  set (INSTALL_DIR "${CMAKE_BINARY_DIR_PARENT}/install" CACHE PATH "${INSTALL_DIR_DESCR}" FORCE)
+  set (CMAKE_INSTALL_PREFIX "${INSTALL_DIR}" CACHE INTERNAL "" FORCE )
+
+  message (STATUS "Info: INSTALL_DIR has been set as ${INSTALL_DIR}")
+endif()
+
+message (STATUS "\nInfo: Collecting all OCCT header files into ${CMAKE_BINARY_DIR}/inc ...")
+
+# collect all the headers to <binary dir>/inc folder
+COLLECT_AND_INSTALL_OCCT_HEADER_FILES ("${CMAKE_BINARY_DIR}" "${BUILD_TOOLKITS}")
+
+OCCT_INSTALL_FILE_OR_DIR ("data" "${INSTALL_DIR}")
+OCCT_INSTALL_FILE_OR_DIR ("samples/tcl" "${INSTALL_DIR}/samples")
+
+if (INSTALL_OCCT_SAMPLES)
+  OCCT_INSTALL_FILE_OR_DIR ("samples" "${INSTALL_DIR}")
+endif()
+
+if (INSTALL_OCCT_TEST_CASES)
+  OCCT_INSTALL_FILE_OR_DIR ("tests" "${INSTALL_DIR}")
+endif()
+
+if (WIN32)
+  set (SCRIPT_EXT bat)
+else()
+  set (SCRIPT_EXT sh)
+endif()
+
+# DRAW.BAT or DRAW.SH
+if (APPLY_OCCT_PATCH_DIR AND EXISTS "${APPLY_OCCT_PATCH_DIR}/adm/templates/draw.${SCRIPT_EXT}")
+  install (FILES "${APPLY_OCCT_PATCH_DIR}/adm/templates/draw.${SCRIPT_EXT}" DESTINATION  "${INSTALL_DIR}" PERMISSIONS
+          OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_WRITE GROUP_EXECUTE WORLD_READ WORLD_WRITE WORLD_EXECUTE)
+else()
+  install (FILES "${CMAKE_SOURCE_DIR}/adm/templates/draw.${SCRIPT_EXT}" DESTINATION  "${INSTALL_DIR}" PERMISSIONS
+          OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_WRITE GROUP_EXECUTE WORLD_READ WORLD_WRITE WORLD_EXECUTE)
+endif()
+OCCT_COPY_FILE_OR_DIR ("adm/templates/draw.${SCRIPT_EXT}" "${CMAKE_BINARY_DIR}")
+
+set (SUB_CUSTOM_NAME "custom_${COMPILER}_${COMPILER_BITNESS}.${SCRIPT_EXT}")
+
+if (WIN32)
+  set (ADDITIONAL_CUSTOM_CONTENT "\nif exist \"%~dp0${SUB_CUSTOM_NAME}\" (\n  call \"%~dp0${SUB_CUSTOM_NAME}\" %VCVER% %ARCH% %CASDEB% \n)")
+else()
+  set (ADDITIONAL_CUSTOM_CONTENT "\nif [ -e \"\${aScriptPath}/${SUB_CUSTOM_NAME}\" ]; then\n  source \"\${aScriptPath}/${SUB_CUSTOM_NAME}\" \"\${COMPILER}\" \"\${WOKSTATION}\${ARCH}\" \"\${CASDEB}\" \nfi")
+endif()
+
+ # change custom.bat/sh
+if (EXISTS "${INSTALL_DIR}/custom.${SCRIPT_EXT}")
+  file (READ "${INSTALL_DIR}/custom.${SCRIPT_EXT}" CUSTOM_CONTENT)
+
+  set (CUSTOM_CONTENT "${CUSTOM_CONTENT} ${ADDITIONAL_CUSTOM_CONTENT}")
+
+  file (WRITE "${INSTALL_DIR}/custom.${SCRIPT_EXT}" "${CUSTOM_CONTENT}")
+else()
+  OCCT_CONFIGURE_AND_INSTALL ("adm/templates/custom.${SCRIPT_EXT}.main" "custom.${SCRIPT_EXT}" "custom.${SCRIPT_EXT}" "${INSTALL_DIR}")
+endif()
+
+# write current custom.bat/sh (for install directory)
+set (SUB_CUSTOM_BUILD_NAME "custom_${COMPILER}_${COMPILER_BITNESS}.install.${SCRIPT_EXT}")
+OCCT_CONFIGURE_AND_INSTALL ("adm/templates/custom.install.${SCRIPT_EXT}.in" "${SUB_CUSTOM_BUILD_NAME}" "${SUB_CUSTOM_NAME}" "${INSTALL_DIR}")
+
+# write current custom.bat/sh (for build directory)
+OCCT_CONFIGURE ("adm/templates/custom.build.${SCRIPT_EXT}.in" "${SUB_CUSTOM_NAME}")
+
+if (BUILD_MODULE_OcctMfcSamples)
+  OCCT_INSTALL_FILE_OR_DIR ("adm/templates/sample.bat" "${INSTALL_DIR}")
+  OCCT_COPY_FILE_OR_DIR    ("adm/templates/sample.bat" "${CMAKE_BINARY_DIR}")
+endif()
+
+# env script for draw in building environment
+OCCT_CONFIGURE ("adm/templates/env.build.${SCRIPT_EXT}.in" "env.${SCRIPT_EXT}")
+
+# end script for draw in standalone environment
+# release version
+set (BUILD_LETTER "")
+OCCT_CONFIGURE ("adm/templates/env.install.${SCRIPT_EXT}.in" "env.install.release.${SCRIPT_EXT}")
+install (FILES "${CMAKE_BINARY_DIR}/env.install.release.${SCRIPT_EXT}" 
+         CONFIGURATIONS Release
+         DESTINATION  "${INSTALL_DIR}"
+         RENAME "env.${SCRIPT_EXT}")
+
+# debug version
+set (BUILD_LETTER "d")
+OCCT_CONFIGURE ("adm/templates/env.install.${SCRIPT_EXT}.in" "env.install.debug.${SCRIPT_EXT}")
+install (FILES "${CMAKE_BINARY_DIR}/env.install.debug.${SCRIPT_EXT}" 
+         CONFIGURATIONS Debug
+         DESTINATION  "${INSTALL_DIR}"
+         RENAME "env.${SCRIPT_EXT}")
+
+# release with debug info version
+set (BUILD_LETTER "i")
+OCCT_CONFIGURE ("adm/templates/env.install.${SCRIPT_EXT}.in" "env.install.relwithdebinfo.${SCRIPT_EXT}")
+install (FILES "${CMAKE_BINARY_DIR}/env.install.relwithdebinfo.${SCRIPT_EXT}" 
+         CONFIGURATIONS RelWithDebInfo
+         DESTINATION  "${INSTALL_DIR}"
+         RENAME "env.${SCRIPT_EXT}")
+
+# copy DrawAppliInit from OCCT source to build directory
+if (NOT EXISTS "${CMAKE_BINARY_DIR}/DrawAppliInit")
+  OCCT_COPY_FILE_OR_DIR (DrawAppliInit "${CMAKE_BINARY_DIR}")
+endif()
+
+# RESOURCES
+FILE_TO_LIST ("adm/RESOURCES" RESOURCES)
+foreach(RESOURCE ${RESOURCES})
+  get_filename_component(RESOURCE_FOLDER ${RESOURCE} DIRECTORY)
+  if(NOT "${RESOURCE_FOLDER}" STREQUAL "")
+    get_filename_component(RESOURCE_FOLDER ${RESOURCE_FOLDER} NAME)
+    OCCT_INSTALL_FILE_OR_DIR ("src/${RESOURCE}" "${INSTALL_DIR}/src/${RESOURCE_FOLDER}")
+  else()
+    OCCT_INSTALL_FILE_OR_DIR ("src/${RESOURCE}" "${INSTALL_DIR}/src")
+  endif()
+endforeach()
+
+# include patched toolkit projects or original ones
+foreach (BUILD_TOOLKIT ${BUILD_TOOLKITS})
+  OCCT_ADD_SUBDIRECTORY ("src/${BUILD_TOOLKIT}")
+endforeach()
+
+if (BUILD_DOC_OcctOverview)
+  OCCT_ADD_SUBDIRECTORY (dox)
+endif()
+
+# patch DRAWEXE
+if (MSVC AND 3RDPARTY_DLL_DIRS)
+  list (FIND BUILD_TOOLKITS DRAWEXE DRAWEXE_INDEX)
+  if (${DRAWEXE_INDEX} GREATER -1)
+    list (REMOVE_DUPLICATES 3RDPARTY_DLL_DIRS)
+    set (3RDPARTY_DLL_DIRS_FOR_PATH "")
+
+    foreach (3RDPARTY_DLL_DIR ${3RDPARTY_DLL_DIRS})
+      set (3RDPARTY_DLL_DIRS_FOR_PATH "${3RDPARTY_DLL_DIRS_FOR_PATH};${3RDPARTY_DLL_DIR}")
+    endforeach()
+
+    OCCT_MAKE_COMPILER_BITNESS()
+    set (X_COMPILER_BITNESS "x64")
+    if ("${COMPILER_BITNESS}" STREQUAL "32")
+      set (X_COMPILER_BITNESS "Win32")
+    endif()
+
+    OCCT_CONFIGURE ("adm/templates/DRAWEXE.vcxproj.user.in" "${CMAKE_BINARY_DIR}/src/DRAWEXE/DRAWEXE.vcxproj.user")
+  endif()
+endif()
+
+# samples do not support patch usage
+if (BUILD_MODULE_OcctMfcSamples)
+  set (OCCT_ROOT ${CMAKE_SOURCE_DIR})
+
+  set (MFC_STANDARD_SAMPLES_DIR ${OCCT_ROOT}/samples/mfc/standard)
+  set (COMMON_WINMAIN_FILE      ${MFC_STANDARD_SAMPLES_DIR}/Common/Winmain.cpp)
+
+  add_subdirectory(samples/mfc/standard/mfcsample)
+  add_subdirectory(samples/mfc/standard/01_Geometry)
+  add_subdirectory(samples/mfc/standard/02_Modeling)
+  add_subdirectory(samples/mfc/standard/03_Viewer2d)
+  add_subdirectory(samples/mfc/standard/04_Viewer3d)
+  add_subdirectory(samples/mfc/standard/05_ImportExport)
+  add_subdirectory(samples/mfc/standard/06_Ocaf)
+  add_subdirectory(samples/mfc/standard/07_Triangulation)
+  add_subdirectory(samples/mfc/standard/08_HLR)
+  add_subdirectory(samples/mfc/standard/09_Animation)
+  add_subdirectory(samples/mfc/standard/10_Convert)
+endif()