0026443: Offset surface hangs up
[occt.git] / CMakeLists.txt
index daf1252..7509a5b 100644 (file)
@@ -2,17 +2,23 @@ cmake_minimum_required (VERSION 2.8.12 FATAL_ERROR)
 
 set (CMAKE_SUPPRESS_REGENERATION TRUE)
 
-# set build configurations list
-if (NOT BUILD_CONFIGURATION)
-  set (BUILD_CONFIGURATION "Release" CACHE STRING "Build type of OCCT" FORCE)
-  SET_PROPERTY(CACHE BUILD_CONFIGURATION PROPERTY STRINGS Release Debug RelWithDebInfo)
-endif()
+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()
 
-set (CMAKE_CONFIGURATION_TYPES ${BUILD_CONFIGURATION} CACHE INTERNAL "" FORCE)
+# 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 "The type of OCCT libraries" FORCE)
+  set (BUILD_LIBRARY_TYPE "Shared" CACHE STRING "${BUILD_LIBRARY_TYPE_DESCR}" FORCE)
   SET_PROPERTY(CACHE BUILD_LIBRARY_TYPE PROPERTY STRINGS Shared Static)
 endif()
 
@@ -28,174 +34,152 @@ project (OCCT)
 # Solution folder property
 set_property (GLOBAL PROPERTY USE_FOLDERS ON)
 
-# Generate documentation
-# Overview and User Guides
-set (DOC_GENERATE_OVERVIEW OFF CACHE BOOL "Generate Overview and User Guides")
-if (NOT DOC_OVERVIEW_OUTPUT_FORMAT)
-  set (DOC_OVERVIEW_OUTPUT_FORMAT "html" CACHE STRING "Output format of Overview and User Guides" FORCE)
-  SET_PROPERTY (CACHE DOC_OVERVIEW_OUTPUT_FORMAT PROPERTY STRINGS html chm pdf)
-endif()
-# class Reference Manual
-set (DOC_GENERATE_REFMAN OFF CACHE BOOL "Generate class Reference Manual")
-
-# Tests
-set (TESTS_RUN OFF CACHE BOOL "Run tests or not")
-set (TESTS_INSTALL OFF CACHE BOOL "Copy tests to folder install")
-set (TESTS_SHAPES_DIR "" CACHE PATH "Directory that will contain shapes for tests" )
-
-# Find Bison and Flex executables to rebuild *.yacc and *.lex files if it is necessary (BUILD_BISON_FLEX_FILES is ON)
-set (BUILD_BISON_FLEX_FILES OFF CACHE BOOL "Build *.yacc/*.lex files")
-if (${BUILD_BISON_FLEX_FILES})
-  foreach (aTool BISON FLEX)
-    list (APPEND CMAKE_PROGRAM_PATH ${BUILD_BISON_FLEX_DIR})
-    find_package (${aTool})
-    if (NOT ${${aTool}_FOUND})
-      message ("Warning : set BUILD_BISON_FLEX_DIR directory")
-      set (BUILD_BISON_FLEX_DIR "" CACHE PATH "Filepath to BISON and FLEX executables")
-      set (BUILD_BISON_FLEX_FILES OFF)
-    endif()
-  endforeach()
+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()
 
-# group include files in folder install
-set (INSTALL_GROUP_INC ON CACHE BOOL "In include files grouped in install folder")
+# 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()
 
 # copy samples to install directory
-set (INSTALL_SAMPLES OFF CACHE BOOL "Copy samples to install directory")
-
-set (CMAKE_BUILD_TYPE ${BUILD_CONFIGURATION} CACHE INTERNAL "Build type of OCCT" FORCE )
+set (INSTALL_OCCT_SAMPLES OFF CACHE BOOL "${INSTALL_OCCT_SAMPLES_DESCR}")
 
 # install dir of the built project
-set (INSTALL_DIR "" CACHE PATH "Directory that will contain install files of OCCT" )
+set (INSTALL_DIR "" CACHE PATH "${INSTALL_DIR_DESCR}" )
 set (CMAKE_INSTALL_PREFIX "${INSTALL_DIR}" CACHE INTERNAL "" FORCE )
 
-set (BUILD_PATCH_DIR "" CACHE PATH "directory with occt patch")
+set (APPLY_OCCT_PATCH_DIR "" CACHE PATH "${APPLY_OCCT_PATCH_DIR_DESCR}")
 
 # the list of being built toolkits
-set (BUILD_TOOLKITS "" CACHE STRING "Toolkits are also included in OCCT")
-separate_arguments (BUILD_TOOLKITS)
+set (BUILD_ADDITIONAL_TOOLKITS "" CACHE STRING "${BUILD_ADDITIONAL_TOOLKITS_DESCR}")
+separate_arguments (BUILD_ADDITIONAL_TOOLKITS)
 
 if (MSVC)
-  set (BUILD_MFC_SAMPLES OFF CACHE BOOL "OCCT samples building")
+  set (BUILD_MODULE_OcctMfcSamples OFF CACHE BOOL "${BUILD_MODULE_OcctMfcSamples_DESCR}")
 endif()
 
 # whether use optional 3rdparty or not
 if (APPLE)
-  set (USE_GLX OFF CACHE BOOL "Are X11 OpenGL used on OSX or not")
+  set (USE_GLX OFF CACHE BOOL "${USE_GLX_DESCR}")
 endif()
 
-set (USE_FREEIMAGE OFF CACHE BOOL "Is freeimage used or not")
-set (USE_VTK OFF CACHE BOOL "Is VTK used or not")
-
-if (NOT DEFINED ANDROID)
-  set (USE_GL2PS OFF CACHE BOOL "Is gl2ps used or not")
-  set (USE_TBB OFF CACHE BOOL "Is tbb used or not")
-  #set (USE_OPENCL OFF CACHE BOOL "Is OpenCL used or not")
-endif()
-
-# macro: include patched file if it exists
-macro (OCCT_INCLUDE_CMAKE_FILE BEING_INCLUDED_FILE)
-  if (NOT "${BUILD_PATCH_DIR}" STREQUAL "" AND EXISTS "${BUILD_PATCH_DIR}/${BEING_INCLUDED_FILE}.cmake")
-    include (${BUILD_PATCH_DIR}/${BEING_INCLUDED_FILE}.cmake)
-  else()
-    include (${BEING_INCLUDED_FILE}.cmake)
-  endif()
-endmacro()
+set (USE_VTK OFF CACHE BOOL "${USE_VTK_DESCR}")
 
 # include occt macros
 OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/occt_macros")
 
-# BUILD_POSTFIX variable is used by all toolkit cmakelists.txt projects
-OCCT_MAKE_BUILD_POSTFIX()
-
 # 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 (MODULE ${OCCT_MODULES})
-  set (BUILD_${MODULE} ON CACHE BOOL "include ${MODULE}")
+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()
 
-# accumulate used toolkits (first level) in USED_TOOLKITS variable
-list (APPEND USED_TOOLKITS ${BUILD_TOOLKITS})
+# accumulate used toolkits (first level) in BUILD_TOOLKITS variable
+list (APPEND BUILD_TOOLKITS ${BUILD_ADDITIONAL_TOOLKITS})
 
-foreach (MODULE ${OCCT_MODULES})
-  if (BUILD_${MODULE})
-    list (APPEND USED_TOOLKITS ${${MODULE}_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 USED_TOOLKITS DRAWEXE)
+  list (REMOVE_ITEM BUILD_TOOLKITS DRAWEXE)
   message (STATUS "Info: DRAWEXE is not included due to ${BUILD_LIBRARY_TYPE} build library type")
 endif()
 
 # accumulate all used toolkits
-list (REMOVE_DUPLICATES USED_TOOLKITS)
-set (RAW_USED_TOOLKIT)
-foreach(USED_TOOLKIT ${USED_TOOLKITS})
-  OCCT_TOOLKIT_FULL_DEP (${USED_TOOLKIT} TOOLKIT_FULL_DEPS)
-  list (APPEND RAW_USED_TOOLKIT ${USED_TOOLKIT} ${TOOLKIT_FULL_DEPS})
+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_USED_TOOLKIT)
-set (USED_TOOLKITS ${RAW_USED_TOOLKIT})
+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")
 
-set (3RDPARTY_DIR_LABEL "The directory containing required 3rdparty products")
+# 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()
+  OCCT_CHECK_AND_UNSET (REBUILD_PLATFORM_DEPENDENT_CODE)
+endif()
+
 if (NOT DEFINED 3RDPARTY_DIR)
-  set (3RDPARTY_DIR "" CACHE PATH ${3RDPARTY_DIR_LABEL})
+  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_LABEL} FORCE)
+    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_LABEL} FORCE)
+    set (3RDPARTY_DIR "${3RDPARTY_DIR}" CACHE PATH ${3RDPARTY_DIR_DESCR} FORCE)
   endif()
 endif()
 
 # search for CSF_TclLibs variable in EXTERNLIB of each being used toolkit
-OCCT_IS_PRODUCT_REQUIRED(CSF_TclLibs USE_TCL)
+OCCT_IS_PRODUCT_REQUIRED (CSF_TclLibs USE_TCL)
 
 if ("${USE_TCL}" STREQUAL ON)
-  message (STATUS "Info: tcl is used by OCCT")
+  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()
 
 # search for CSF_FREETYPE variable in EXTERNLIB of each being used toolkit
-OCCT_IS_PRODUCT_REQUIRED(CSF_FREETYPE USE_FREETYPE)
+OCCT_IS_PRODUCT_REQUIRED (CSF_FREETYPE USE_FREETYPE)
 
 if ("${USE_FREETYPE}" STREQUAL ON)
-  message (STATUS "Info: freetype is used by OCCT")
+  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()
 
 # 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
@@ -205,11 +189,26 @@ if (USE_GLX)
 endif()
 
 # FREEIMAGE
-if (USE_FREEIMAGE)
-  add_definitions (-DHAVE_FREEIMAGE)
-  OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/freeimage")
-  OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/freeimageplus")
+# 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")
@@ -217,35 +216,83 @@ else()
 endif()
 
 # GL2PS
-if (USE_GL2PS)
-  add_definitions (-DHAVE_GL2PS)
-  OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/gl2ps")
+# 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()
 
-# OPENCL
-#if (USE_OPENCL)
-#  add_definitions (-DHAVE_OPENCL)
-#  OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/opencl")
-#else()
-#  OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_OPENCL")
-#  OCCT_CHECK_AND_UNSET ("3RDPARTY_OPENCL_ADDITIONAL_PATH_FOR_HEADER")
-#  OCCT_CHECK_AND_UNSET ("3RDPARTY_OPENCL_ADDITIONAL_PATH_FOR_LIB")
-#  OCCT_CHECK_AND_UNSET ("INSTALL_OPENCL")
-#endif()
-
 # TBB
-if (USE_TBB)
-  add_definitions (-DHAVE_TBB)
-  OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/tbb")
+# 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
@@ -260,6 +307,9 @@ if (3RDPARTY_INCLUDE_DIRS)
   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}")
@@ -267,143 +317,132 @@ if (3RDPARTY_LIBRARY_DIRS)
   link_directories (${3RDPARTY_LIBRARY_DIRS})
 endif()
 
-# Get all used variables: OS_WITH_BIT, COMPILER, BUILD_POSTFIX
-OCCT_MAKE_BUILD_POSTFIX()
+# Get all used variables: OS_WITH_BIT, COMPILER
 OCCT_MAKE_OS_WITH_BITNESS()
 OCCT_MAKE_COMPILER_SHORT_NAME()
 
 # build directories
-string (TOUPPER "${BUILD_CONFIGURATION}" TAIL_OF_OUTPUT_VARNAME)
-
-set (OUTPUT_LIBRARY_DIR ${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/lib${BUILD_POSTFIX})
-set (OUTPUT_BINARY_DIR ${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/bin${BUILD_POSTFIX})
-
-set ("CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${TAIL_OF_OUTPUT_VARNAME}" "${OUTPUT_LIBRARY_DIR}")
-set ("CMAKE_RUNTIME_OUTPUT_DIRECTORY_${TAIL_OF_OUTPUT_VARNAME}" "${OUTPUT_BINARY_DIR}")
-set ("CMAKE_LIBRARY_OUTPUT_DIRECTORY_${TAIL_OF_OUTPUT_VARNAME}" "${OUTPUT_LIBRARY_DIR}")
-
-if (WIN32)
-  set ("CMAKE_LIBRARY_OUTPUT_DIRECTORY_${TAIL_OF_OUTPUT_VARNAME}" "${OUTPUT_BINARY_DIR}")
+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 "")
-  message (FATAL_ERROR "INSTALL_DIR variable is empty. It's required to define installation directory")
-else()
+  get_filename_component (CMAKE_BINARY_DIR_PARENT ${CMAKE_BINARY_DIR} DIRECTORY)
 
-  # inc,data,tests DIRECTORY
-  file (GLOB DIRS RELATIVE ${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/src/*)
-  foreach(CDIR ${DIRS})
-    file(GLOB HFiles "${CMAKE_SOURCE_DIR}/src/${CDIR}/*.[hgl]xx" "${CMAKE_SOURCE_DIR}/src/${CDIR}/*.h")
-    set (GROUP_CDIR "")
-    if (INSTALL_GROUP_INC)
-      set (GROUP_CDIR ${CDIR})
-    endif()
-    install(FILES ${HFiles} DESTINATION "${INSTALL_DIR}/inc/${GROUP_CDIR}")
-  endforeach(CDIR)
-
-  install (DIRECTORY "${CMAKE_SOURCE_DIR}/data"         DESTINATION  "${INSTALL_DIR}")
-  install (DIRECTORY "${CMAKE_SOURCE_DIR}/samples/tcl"  DESTINATION  "${INSTALL_DIR}/samples")
-  if (TESTS_INSTALL)
-    install (DIRECTORY "${CMAKE_SOURCE_DIR}/tests" DESTINATION  "${INSTALL_DIR}" )
-  endif()
+  set (INSTALL_DIR "${CMAKE_BINARY_DIR_PARENT}/install" CACHE PATH "${INSTALL_DIR_DESCR}" FORCE)
+  set (CMAKE_INSTALL_PREFIX "${INSTALL_DIR}" CACHE INTERNAL "" FORCE )
 
-  # install patch inc, data, tests folder
-  if (NOT "${BUILD_PATCH_DIR}" STREQUAL "")
-    if (EXISTS "${BUILD_PATCH_DIR}/inc")
-      install (DIRECTORY "${BUILD_PATCH_DIR}/inc" DESTINATION  "${INSTALL_DIR}" )
-    else()
-      file (GLOB DIRS RELATIVE ${BUILD_PATCH_DIR}/src ${BUILD_PATCH_DIR}/src/*)
-      foreach(CDIR ${DIRS})
-        file(GLOB HFiles "${BUILD_PATCH_DIR}/src/${CDIR}/*.[hgl]xx" "${BUILD_PATCH_DIR}/src/${CDIR}/*.h")
-        if (INSTALL_GROUP_INC)
-          install(FILES ${HFiles} DESTINATION "${INSTALL_DIR}/inc/${CDIR}")
-        else()
-          install(FILES ${HFiles} DESTINATION "${INSTALL_DIR}/inc")
-        endif()
-      endforeach(CDIR)
-    endif()
+  message (STATUS "Info: INSTALL_DIR has been set as ${INSTALL_DIR}")
+endif()
 
-    if (EXISTS "${BUILD_PATCH_DIR}/data")
-      install (DIRECTORY "${BUILD_PATCH_DIR}/data"  DESTINATION  "${INSTALL_DIR}" )
-    endif()
+message (STATUS "\nInfo: Collecting all OCCT header files into ${CMAKE_BINARY_DIR}/inc ...")
 
-    if (TESTS_INSTALL)
-      if (EXISTS "${BUILD_PATCH_DIR}/tests")
-        install (DIRECTORY "${BUILD_PATCH_DIR}/tests" DESTINATION "${INSTALL_DIR}" )
-      endif()
-    endif()
-  endif()
+# collect all the headers to <binary dir>/inc folder
+COLLECT_AND_INSTALL_OCCT_HEADER_FILES ("${CMAKE_BINARY_DIR}" "${BUILD_TOOLKITS}")
 
-  if (WIN32)
-    set (SCRIPT_EXT bat)
-  else()
-    set (SCRIPT_EXT sh)
-  endif()
+OCCT_INSTALL_FILE_OR_DIR ("data" "${INSTALL_DIR}")
+OCCT_INSTALL_FILE_OR_DIR ("samples/tcl" "${INSTALL_DIR}/samples")
 
-  # Creation of "START_TESTS" project
-  if (TESTS_RUN AND TESTS_INSTALL)
-    #set(BUILD_TESTING ON)
-    #enable_testing ()
-    #add_test(NAME RUN_TESTS COMMAND ${INSTALL_DIR}/draw.${SCRIPT_EXT} -c testgrid -overwrite -outdir ${INSTALL_DIR}/TestResults)
-    add_custom_target(START_TESTS ${INSTALL_DIR}/draw.${SCRIPT_EXT} -c testgrid -overwrite -outdir ${INSTALL_DIR}/TestResults DEPENDS INSTALL)
-  endif()
+if (INSTALL_OCCT_SAMPLES)
+  OCCT_INSTALL_FILE_OR_DIR ("samples" "${INSTALL_DIR}")
+endif()
 
-  # Creation of "GenerateDocumentation" project
-  if (DOC_GENERATE_OVERVIEW OR DOC_GENERATE_REFMAN)
-    OCCT_INCLUDE_CMAKE_FILE("adm/cmake/occt_gendoc")
-    if(DOC_GENERATE_OVERVIEW)
-      gendoc(-overview -${DOC_OVERVIEW_OUTPUT_FORMAT})
-    endif()
-    if(DOC_GENERATE_REFMAN)
-      gendoc(-refman -html)
-    endif()
-  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 (NOT "${BUILD_PATCH_DIR}" STREQUAL "" AND EXISTS "${BUILD_PATCH_DIR}/adm/templates/draw.${SCRIPT_EXT}")
-    install(FILES "${BUILD_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}")
+# 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 "custom_${COMPILER}_${COMPILER_BITNESS}.${SCRIPT_EXT}")
-  if ("${BUILD_CONFIGURATION}" STREQUAL "Debug")
-    set (SUB_CUSTOM "custom_${COMPILER}_${COMPILER_BITNESS}_${BUILD_POSTFIX}.${SCRIPT_EXT}")
-  endif()
+set (SUB_CUSTOM_NAME "custom_${COMPILER}_${COMPILER_BITNESS}.${SCRIPT_EXT}")
 
-  if (WIN32)
-    set (ADDITIONAL_CUSTOM_CONTENT "\nif exist \"%~dp0${SUB_CUSTOM}\" (\n  call \"%~dp0${SUB_CUSTOM}\" %1 %2 %3 \n)")
-  else()
-    set (ADDITIONAL_CUSTOM_CONTENT "\nif [ -e \"\${aScriptPath}/${SUB_CUSTOM}\" ]; then\n  source \"\${aScriptPath}/${SUB_CUSTOM}\" \"\${COMPILER}\" \"\${WOKSTATION}\${ARCH}\" \"\${CASDEB}\" \nfi")
-  endif()
+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)
+ # 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}")
+  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}" "${INSTALL_DIR}")
-  endif()
+  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
-  OCCT_CONFIGURE_AND_INSTALL ("adm/templates/custom.${SCRIPT_EXT}.in" "${SUB_CUSTOM}" "${INSTALL_DIR}")
+# write current custom.bat/sh (for build directory)
+OCCT_CONFIGURE ("adm/templates/custom.build.${SCRIPT_EXT}.in" "${SUB_CUSTOM_NAME}")
 
-  if (BUILD_MFC_SAMPLES)
-    OCCT_INSTALL_FILE_OR_DIR ("adm/templates/sample.bat" "${INSTALL_DIR}")
-    OCCT_COPY_FILE_OR_DIR ("adm/templates/sample.bat" "${CMAKE_BINARY_DIR}")
-  endif()
+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()
 
-  OCCT_CONFIGURE ("adm/templates/env.build.${SCRIPT_EXT}.in" "env.${SCRIPT_EXT}")
-  OCCT_CONFIGURE ("adm/templates/env.${SCRIPT_EXT}.in" "env.install.${SCRIPT_EXT}")
-  install(FILES "${CMAKE_BINARY_DIR}/env.install.${SCRIPT_EXT}" DESTINATION  "${INSTALL_DIR}" RENAME "env.${SCRIPT_EXT}")
+# 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
@@ -419,18 +458,37 @@ foreach(RESOURCE ${RESOURCES})
 endforeach()
 
 # include patched toolkit projects or original ones
-foreach (USED_TOOLKIT ${USED_TOOLKITS})
-  if (NOT "${BUILD_PATCH_DIR}" STREQUAL "" AND EXISTS "${BUILD_PATCH_DIR}/src/${USED_TOOLKIT}")
-    add_subdirectory(${BUILD_PATCH_DIR}/src/${USED_TOOLKIT})
-  elseif (EXISTS "${CMAKE_SOURCE_DIR}/src/${USED_TOOLKIT}")
-    add_subdirectory (${CMAKE_SOURCE_DIR}/src/${USED_TOOLKIT})
-  else()
-    message (STATUS "${USED_TOOLKIT} is not included")
-  endif()
+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_MFC_SAMPLES)
+if (BUILD_MODULE_OcctMfcSamples)
   set (OCCT_ROOT ${CMAKE_SOURCE_DIR})
 
   set (MFC_STANDARD_SAMPLES_DIR ${OCCT_ROOT}/samples/mfc/standard)
@@ -448,7 +506,3 @@ if (BUILD_MFC_SAMPLES)
   add_subdirectory(samples/mfc/standard/09_Animation)
   add_subdirectory(samples/mfc/standard/10_Convert)
 endif()
-
-if (INSTALL_SAMPLES)
-  OCCT_INSTALL_FILE_OR_DIR ("samples" "${INSTALL_DIR}")
-endif()