0024924: ShapeFix_SplitTool doesn't verify the new range after cutting an edge
[occt.git] / CMakeLists.txt
1 cmake_minimum_required ( VERSION 2.6)
2
3 if (NOT BUILD_CONFIGURATION)
4   set(BUILD_CONFIGURATION "Release" CACHE STRING "Build type of OCCT" FORCE)
5   SET_PROPERTY(CACHE BUILD_CONFIGURATION PROPERTY STRINGS Release Debug RelWithDebInfo)
6 endif()
7
8 set(CMAKE_CONFIGURATION_TYPES ${BUILD_CONFIGURATION} CACHE INTERNAL "" FORCE)
9
10 project(OCCT)
11
12 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
13
14 set(BUILD_SHARED_LIBS ON)
15
16 IF("${BUILD_CONFIGURATION}" STREQUAL "${CMAKE_BUILD_TYPE}")
17   SET(CHANGES_ARE_NEEDED OFF)
18 ELSE()
19   SET(CHANGES_ARE_NEEDED ON)
20 ENDIF()
21
22 MATH(EXPR COMPILER_BITNESS "32 + 32*(${CMAKE_SIZEOF_VOID_P}/8)")
23
24 SET(CMAKE_BUILD_TYPE ${BUILD_CONFIGURATION} CACHE INTERNAL "Build type of OCCT" FORCE )
25
26 SET(INSTALL_DIR "" CACHE PATH "Directory that will contain install files of OCCT" )
27 SET(CMAKE_INSTALL_PREFIX "${INSTALL_DIR}" CACHE INTERNAL "" FORCE )
28
29 set(BUILD_PATCH_DIR "" CACHE PATH "directory with occt patch")
30
31 set (BUILD_TOOLKITS "" CACHE STRING "Toolkits are also included in OCCT")
32 separate_arguments(BUILD_TOOLKITS)
33
34 IF(MSVC)
35   SET(BUILD_Samples OFF CACHE BOOL "OCCT samples building")
36 ENDIF()
37
38 # consider for patch existence
39 SET (IS_PATCH_CURRENT "NO")
40 SET (TK_ROOT_DIR ${CMAKE_SOURCE_DIR})
41 IF(NOT "${BUILD_PATCH_DIR}" STREQUAL "")
42   SET (IS_PATCH_CURRENT "YES")
43   SET (TK_ROOT_DIR ${BUILD_PATCH_DIR})
44 ENDIF()
45
46 # include the list of patch modules if the one exists
47 # or include the list of original modules
48 IF(NOT "${BUILD_PATCH_DIR}" STREQUAL "" AND EXISTS "${BUILD_PATCH_DIR}/adm/cmake/CMakeModules.txt")
49   MESSAGE(STATUS "Info: the list of patched modules is included")
50   include(${BUILD_PATCH_DIR}/adm/cmake/CMakeModules.txt)
51 ELSE()
52   include(adm/cmake/CMakeModules.txt)
53 ENDIF()
54
55 if (WIN32)
56   set(SCRIPT_EXT bat)
57 else()
58   set(SCRIPT_EXT sh)
59 endif()
60
61 if (MSVC)
62   add_definitions(/fp:precise)
63 endif()
64
65 # choose SSE2 option for appropriate MSVC compilers
66 if (MSVC80 OR MSVC90 OR MSVC10)
67   if (${COMPILER_BITNESS} STREQUAL 32)
68     add_definitions(/arch:SSE2)
69   endif()
70 endif()
71
72 # set compiler short name
73 if (MSVC)
74   if (MSVC70)
75     set (COMPILER vc7)
76   elseif (MSVC80)
77     set (COMPILER vc8)
78   elseif (MSVC90)
79     set (COMPILER vc9)
80   elseif (MSVC10)
81     set (COMPILER vc10)
82   elseif (MSVC11)
83     set (COMPILER vc11)
84   endif()
85 elseif (DEFINED CMAKE_COMPILER_IS_GNUCC)
86   set (COMPILER gcc)
87 elseif (DEFINED CMAKE_COMPILER_IS_GNUCXX)
88   set (COMPILER gxx)
89 elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
90   set (COMPILER clang)
91 elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
92   set (COMPILER icc)
93 else()
94   set (COMPILER ${CMAKE_GENERATOR})
95   string (REGEX REPLACE " " "" COMPILER ${COMPILER})
96 endif()
97
98 if (WIN32)
99   SET(OS_WITH_BIT "win${COMPILER_BITNESS}")
100 elseif(APPLE)
101   SET(OS_WITH_BIT "mac${COMPILER_BITNESS}")
102 else()
103   SET(OS_WITH_BIT "lin${COMPILER_BITNESS}")
104 endif()
105
106 add_definitions(-DCSFDB)
107 if(WIN32)
108   add_definitions(/DWNT -wd4996)
109 elseif(APPLE)
110   add_definitions(-fexceptions -fPIC -DOCC_CONVERT_SIGNALS -DHAVE_WOK_CONFIG_H -DHAVE_CONFIG_H)
111 else()
112   add_definitions(-fexceptions -fPIC -DOCC_CONVERT_SIGNALS -DHAVE_WOK_CONFIG_H -DHAVE_CONFIG_H -DLIN)
113 endif()
114
115 # enable structured exceptions for MSVC
116 string(REGEX MATCH "EHsc" ISFLAG "${CMAKE_CXX_FLAGS}")
117 IF(ISFLAG)
118   STRING(REGEX REPLACE "EHsc" "EHa" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
119 ELSEIF(WIN32)
120   SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -EHa")
121 ENDIF()
122
123 # enable parallel compilation on MSVC 9 and above
124 IF(WIN32)
125   IF(NOT DEFINED MSVC70 AND NOT DEFINED MSVC80)
126     SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -MP")
127   ENDIF()
128 ENDIF()
129
130 # increase compiler warnings level (-W4 for MSVC, -Wall for GCC)
131 IF(MSVC)
132   if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
133     string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
134   else()
135     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
136   endif()
137 elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
138   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
139 endif()
140
141 SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNo_Exception")
142 SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DNo_Exception")
143
144 SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEB")
145 SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DDEB")
146
147 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/out/lib)
148 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/out/lib)
149 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/out/bin)
150
151 # RESOURCES
152 install(DIRECTORY "${CMAKE_SOURCE_DIR}/src/DrawResources" DESTINATION  "${INSTALL_DIR}/src" )
153 install(DIRECTORY "${CMAKE_SOURCE_DIR}/src/StdResource" DESTINATION  "${INSTALL_DIR}/src" )
154 install(DIRECTORY "${CMAKE_SOURCE_DIR}/src/SHMessage" DESTINATION  "${INSTALL_DIR}/src" )
155 install(DIRECTORY "${CMAKE_SOURCE_DIR}/src/Textures" DESTINATION  "${INSTALL_DIR}/src" )
156 install(DIRECTORY "${CMAKE_SOURCE_DIR}/src/Shaders" DESTINATION  "${INSTALL_DIR}/src" )
157 install(DIRECTORY "${CMAKE_SOURCE_DIR}/src/XSMessage" DESTINATION  "${INSTALL_DIR}/src" )
158 install(DIRECTORY "${CMAKE_SOURCE_DIR}/src/XSTEPResource" DESTINATION  "${INSTALL_DIR}/src" )
159 install(DIRECTORY "${CMAKE_SOURCE_DIR}/src/XmlOcafResource" DESTINATION  "${INSTALL_DIR}/src" )
160
161 install(FILES "${CMAKE_SOURCE_DIR}/src/UnitsAPI/Lexi_Expr.dat" DESTINATION  "${INSTALL_DIR}/src/UnitsAPI" )
162 install(FILES "${CMAKE_SOURCE_DIR}/src/UnitsAPI/Units.dat"     DESTINATION  "${INSTALL_DIR}/src/UnitsAPI" )
163 install(FILES "${CMAKE_SOURCE_DIR}/src/TObj/TObj.msg" DESTINATION  "${INSTALL_DIR}/src/TObj" )
164
165 IF("${BUILD_CONFIGURATION}" STREQUAL "Debug") 
166   SET(3RDPARTY_BUILD_SUFFIX "") # debug == release
167   SET(BUILD_SUFFIX "d")
168 ELSE()
169   SET(3RDPARTY_BUILD_SUFFIX "") 
170   SET(BUILD_SUFFIX "")
171 ENDIF()
172
173 FUNCTION(SUBDIRECTORY_NAMES MAIN_DIRECTORY RESULT)
174   file(GLOB SUB_ITEMS "${MAIN_DIRECTORY}/*")
175
176   foreach(ITEM ${SUB_ITEMS})
177     if(IS_DIRECTORY "${ITEM}")
178       GET_FILENAME_COMPONENT(ITEM_NAME "${ITEM}" NAME)
179       LIST(APPEND LOCAL_RESULT "${ITEM_NAME}")
180     endif()
181   endforeach()
182   set (${RESULT} ${LOCAL_RESULT} PARENT_SCOPE)
183 ENDFUNCTION()
184
185 FUNCTION(FIND_PRODUCT_DIR ROOT_DIR PRODUCT_NAME RESULT)
186   string( TOLOWER "${PRODUCT_NAME}" lower_PRODUCT_NAME )
187
188   LIST(APPEND SEARCH_TEMPLATES "${lower_PRODUCT_NAME}.*${COMPILER}.*${COMPILER_BITNESS}")
189   LIST(APPEND SEARCH_TEMPLATES "${lower_PRODUCT_NAME}.*[0-9.]+.*${COMPILER}.*${COMPILER_BITNESS}")
190   LIST(APPEND SEARCH_TEMPLATES "${lower_PRODUCT_NAME}.*[0-9.]+.*${COMPILER_BITNESS}")
191   LIST(APPEND SEARCH_TEMPLATES "${lower_PRODUCT_NAME}.*[0-9.]+")
192   LIST(APPEND SEARCH_TEMPLATES "${lower_PRODUCT_NAME}")
193
194   SUBDIRECTORY_NAMES( "${ROOT_DIR}" SUBDIR_NAME_LIST)
195
196   FOREACH( SEARCH_TEMPLATE ${SEARCH_TEMPLATES})
197     IF(LOCAL_RESULT)
198       BREAK()
199     ENDIF()
200
201     FOREACH(SUBDIR_NAME ${SUBDIR_NAME_LIST})
202       string( TOLOWER "${SUBDIR_NAME}" lower_SUBDIR_NAME )
203
204       STRING(REGEX MATCH "${SEARCH_TEMPLATE}" DUMMY_VAR "${lower_SUBDIR_NAME}")
205       IF(DUMMY_VAR)
206         LIST(APPEND LOCAL_RESULT ${SUBDIR_NAME})
207       ENDIF()
208     ENDFOREACH()
209   ENDFOREACH()
210
211   IF(LOCAL_RESULT)
212     LIST(LENGTH "${LOCAL_RESULT}" LOC_LEN)
213     MATH(EXPR LAST_ELEMENT_INDEX "${LOC_LEN}-1")
214     LIST(GET LOCAL_RESULT ${LAST_ELEMENT_INDEX} DUMMY)
215     SET(${RESULT} ${DUMMY} PARENT_SCOPE)
216   ENDIF()
217 ENDFUNCTION()
218
219 IF(WIN32)
220   SET(DLL_SO "dll")
221   SET(DLL_SO_FOLDER "bin")
222   SET(DLL_SO_PREFIX "")
223 ELSEIF(APPLE)
224   SET(DLL_SO "dylib")
225   SET(DLL_SO_FOLDER "lib")
226   SET(DLL_SO_PREFIX "lib")
227 ELSE()
228   SET(DLL_SO "so")
229   SET(DLL_SO_FOLDER "lib")
230   SET(DLL_SO_PREFIX "lib")
231 ENDIF()
232
233 SET(3RDPARTY_DIR ${CMAKE_SOURCE_DIR} CACHE PATH "Directory contains required 3rdparty products")
234 SET(3RDPARTY_INCLUDE_DIRS "")
235 SET(3RDPARTY_NOT_INCLUDED)
236
237 IF(APPLE)
238   SET(USE_GLX OFF CACHE BOOL "whether use X11 OpenGL on OSX or not")
239 ENDIF()
240
241 SET(USE_GL2PS OFF CACHE BOOL "whether use gl2ps product or not")
242 SET(USE_FREEIMAGE OFF CACHE BOOL "whether use freeimage product or not")
243 SET(USE_TBB OFF CACHE BOOL "whether use tbb product or not")
244 SET(USE_OPENCL OFF CACHE BOOL "whether use OpenCL or not")
245
246 SET(INSTALL_TESTS OFF CACHE BOOL "Is tests copy to install directory")
247
248 MACRO (CHECK_AND_UNSET VARNAME)
249   IF(DEFINED ${VARNAME})
250     UNSET(${VARNAME} CACHE)
251   ENDIF()
252 ENDMACRO()
253
254 MACRO (CHECK_AND_UNSET_GROUP VARNAME)
255   CHECK_AND_UNSET ("${VARNAME}_DIR")
256   CHECK_AND_UNSET ("${VARNAME}_INCLUDE_DIR")
257   CHECK_AND_UNSET ("${VARNAME}_DLL")
258   CHECK_AND_UNSET ("${VARNAME}_LIBRARY")
259 ENDMACRO()
260
261 MACRO(THIRDPARTY_PRODUCT PRODUCT_NAME HEADER_NAME LIBRARY_NAME)
262   IF(NOT DEFINED 3RDPARTY_${PRODUCT_NAME}_DIR)
263     SET(3RDPARTY_${PRODUCT_NAME}_DIR "" CACHE PATH "Directory contains ${PRODUCT_NAME} product")
264   ENDIF()
265
266   IF(3RDPARTY_DIR AND ("${3RDPARTY_${PRODUCT_NAME}_DIR}" STREQUAL "" OR CHANGES_ARE_NEEDED))
267     FIND_PRODUCT_DIR("${3RDPARTY_DIR}" ${PRODUCT_NAME} ${PRODUCT_NAME}_DIR_NAME)
268     IF("${${PRODUCT_NAME}_DIR_NAME}" STREQUAL "")
269       MESSAGE(STATUS "${PRODUCT_NAME} DON'T FIND")
270     ELSE()
271       SET(3RDPARTY_${PRODUCT_NAME}_DIR "${3RDPARTY_DIR}/${${PRODUCT_NAME}_DIR_NAME}" CACHE PATH "Directory contains ${PRODUCT_NAME} product" FORCE)
272     ENDIF()
273   ENDIF()
274
275   SET(INSTALL_${PRODUCT_NAME} OFF CACHE BOOL "Is ${PRODUCT_NAME} lib copy to install directory")
276
277   IF(3RDPARTY_${PRODUCT_NAME}_DIR)
278     IF("${3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR}" STREQUAL "" OR CHANGES_ARE_NEEDED OR "${3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR}" STREQUAL "3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR-NOTFOUND")
279       SET(3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR "3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR-NOTFOUND" CACHE FILEPATH "Directory contains headers of the ${PRODUCT_NAME} product" FORCE)
280       if ("${PRODUCT_NAME}" STREQUAL "FREETYPE")
281         FIND_PATH(3RDPARTY_FREETYPE_INCLUDE_DIR ${HEADER_NAME} PATHS "${3RDPARTY_FREETYPE_DIR}/include" "${3RDPARTY_FREETYPE_DIR}/include/freetype2" NO_DEFAULT_PATH)
282       else()
283         FIND_PATH(3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR ${HEADER_NAME} PATHS "${3RDPARTY_${PRODUCT_NAME}_DIR}/include" NO_DEFAULT_PATH)
284       endif()
285     ENDIF()
286
287     IF("${3RDPARTY_${PRODUCT_NAME}_LIBRARY}" STREQUAL "" OR CHANGES_ARE_NEEDED OR "${3RDPARTY_${PRODUCT_NAME}_LIBRARY}" STREQUAL "3RDPARTY_${PRODUCT_NAME}_LIBRARY-NOTFOUND")
288       SET(3RDPARTY_${PRODUCT_NAME}_LIBRARY "3RDPARTY_${PRODUCT_NAME}_LIBRARY-NOTFOUND" CACHE FILEPATH "Path to library of the ${PRODUCT_NAME} product" FORCE)
289       FIND_LIBRARY(3RDPARTY_${PRODUCT_NAME}_LIBRARY ${LIBRARY_NAME}  PATHS "${3RDPARTY_${PRODUCT_NAME}_DIR}/lib" NO_DEFAULT_PATH)
290     ENDIF()
291
292     IF("${3RDPARTY_${PRODUCT_NAME}_DLL}" STREQUAL "" OR CHANGES_ARE_NEEDED OR "${3RDPARTY_${PRODUCT_NAME}_DLL}" STREQUAL "3RDPARTY_${PRODUCT_NAME}_DLL-NOTFOUND")
293       SET(3RDPARTY_${PRODUCT_NAME}_DLL "3RDPARTY_${PRODUCT_NAME}_DLL-NOTFOUND" CACHE FILEPATH "Path to shared library of the ${PRODUCT_NAME} product" FORCE)
294       FIND_FILE(3RDPARTY_${PRODUCT_NAME}_DLL "${DLL_SO_PREFIX}${LIBRARY_NAME}.${DLL_SO}"  PATHS "${3RDPARTY_${PRODUCT_NAME}_DIR}/${DLL_SO_FOLDER}" NO_DEFAULT_PATH)
295     ENDIF()
296
297     MARK_AS_ADVANCED(3RDPARTY_${PRODUCT_NAME}_DIR)
298   ELSE()
299
300   ENDIF()
301
302   # check default path (with additions) for header search
303   IF("${3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR}" STREQUAL "" OR "${3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR}" STREQUAL "3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR-NOTFOUND")
304     SET(3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR "3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR-NOTFOUND" CACHE FILEPATH "Directory contains headers of the ${PRODUCT_NAME} product" FORCE)
305     FIND_PATH(3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR ${HEADER_NAME} ${3RDPARTY_${PRODUCT_NAME}_ADDITIONAL_PATH_FOR_HEADER})
306   ENDIF()
307
308   # check default path (with additions) for library search
309   IF("${3RDPARTY_${PRODUCT_NAME}_LIBRARY}" STREQUAL "" OR "${3RDPARTY_${PRODUCT_NAME}_LIBRARY}" STREQUAL "3RDPARTY_${PRODUCT_NAME}_LIBRARY-NOTFOUND")
310     SET(3RDPARTY_${PRODUCT_NAME}_LIBRARY "3RDPARTY_${PRODUCT_NAME}_LIBRARY-NOTFOUND" CACHE FILEPATH "Directory contains library of the ${PRODUCT_NAME} product" FORCE)
311     FIND_LIBRARY(3RDPARTY_${PRODUCT_NAME}_LIBRARY ${LIBRARY_NAME} ${3RDPARTY_${PRODUCT_NAME}_ADDITIONAL_PATH_FOR_LIB})
312   ENDIF()
313
314   # check default path (with additions) for DLL search
315   IF("${3RDPARTY_${PRODUCT_NAME}_DLL}" STREQUAL "" OR "${3RDPARTY_${PRODUCT_NAME}_DLL}" STREQUAL "3RDPARTY_${PRODUCT_NAME}_DLL-NOTFOUND")
316     SET(3RDPARTY_${PRODUCT_NAME}_DLL "3RDPARTY_${PRODUCT_NAME}_DLL-NOTFOUND" CACHE FILEPATH "Directory contains shared library of the ${PRODUCT_NAME} product" FORCE)
317     FIND_FILE(3RDPARTY_${PRODUCT_NAME}_DLL "${DLL_SO_PREFIX}${LIBRARY_NAME}.${DLL_SO}" ${3RDPARTY_${PRODUCT_NAME}_ADDITIONAL_PATH_FOR_DLL})
318   ENDIF()
319
320   IF(3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR)
321     SET(3RDPARTY_INCLUDE_DIRS "${3RDPARTY_INCLUDE_DIRS};${3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR}")
322   ELSE()
323     LIST(APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR)
324   ENDIF()
325
326   IF(3RDPARTY_${PRODUCT_NAME}_LIBRARY)
327     GET_FILENAME_COMPONENT(3RDPARTY_${PRODUCT_NAME}_LIBRARY_DIR "${3RDPARTY_${PRODUCT_NAME}_LIBRARY}" PATH)
328     SET(3RDPARTY_LIBRARY_DIRS "${3RDPARTY_LIBRARY_DIRS};${3RDPARTY_${PRODUCT_NAME}_LIBRARY_DIR}")
329   ELSE()
330     LIST(APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_${PRODUCT_NAME}_LIBRARY)
331   ENDIF()
332
333   IF(3RDPARTY_${PRODUCT_NAME}_DLL)
334     #
335   ELSE()
336     LIST(APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_${PRODUCT_NAME}_DLL)
337   ENDIF()
338
339   IF(INSTALL_${PRODUCT_NAME})
340     INSTALL(FILES "${3RDPARTY_${PRODUCT_NAME}_DLL}" DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/${DLL_SO_FOLDER}${BUILD_SUFFIX}")
341     SET(3RDPARTY_${PRODUCT_NAME}_DLL_DIR "")
342   ELSE()
343     GET_FILENAME_COMPONENT(3RDPARTY_${PRODUCT_NAME}_DLL_DIR "${3RDPARTY_${PRODUCT_NAME}_DLL}" PATH)
344   ENDIF()
345 ENDMACRO()
346
347 # TCL
348 INCLUDE(adm/templates/tcl.cmake)
349
350 #install tcltk
351 IF(INSTALL_TCL)
352   SET(3RDPARTY_TCL_DLL_DIR "")
353   SET(3RDPARTY_TCL_LIB_DIR "")
354   
355   GET_FILENAME_COMPONENT(3RDPARTY_TCL_LIB_DIR_INSIDE "${3RDPARTY_TCL_LIBRARY}" PATH)
356   GET_FILENAME_COMPONENT(3RDPARTY_TCL_DLL_DIR_INSIDE "${3RDPARTY_TCL_DLL}" PATH)
357
358   IF (IS_TCL_VERSION_FOUND)
359     SET (TCL_VERSION ${TCL_MAJOR_VERSION}${TCL_SEP}${TCL_MINOR_VERSION})
360     SET (TCL_FOLDER_VERSION ${TCL_MAJOR_VERSION}.${TCL_MINOR_VERSION})
361   ELSE()
362     SET (TCL_VERSION "")
363
364     #TODO SEARCH tclX.X & tkX.X subdirs
365     SET (TCL_FOLDER_VERSION "")
366   ENDIF()
367   
368   INSTALL(FILES "${3RDPARTY_TCL_DLL_DIR_INSIDE}/${DLL_SO_PREFIX}tcl${TCL_VERSION}.${DLL_SO}" DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/${DLL_SO_FOLDER}${BUILD_SUFFIX}")
369   INSTALL(FILES "${3RDPARTY_TCL_DLL_DIR_INSIDE}/${DLL_SO_PREFIX}tk${TCL_VERSION}.${DLL_SO}" DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/${DLL_SO_FOLDER}${BUILD_SUFFIX}")
370   
371   IF (IS_TCL_VERSION_FOUND)
372     # tcl is required to install in lib folder (without ${BUILD_SUFFIX})
373     INSTALL(DIRECTORY "${3RDPARTY_TCL_LIB_DIR_INSIDE}/tcl8" DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/lib")
374     INSTALL(DIRECTORY "${3RDPARTY_TCL_LIB_DIR_INSIDE}/tcl${TCL_FOLDER_VERSION}" DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/lib")
375     INSTALL(DIRECTORY "${3RDPARTY_TCL_LIB_DIR_INSIDE}/tk${TCL_FOLDER_VERSION}" DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/lib")
376   ELSE()
377     MESSAGE(STATUS "\nWarning: tclX.X and tkX.X subdirs won't be copyied during the installation process.")
378     MESSAGE(STATUS "Try seeking tcl within another folder by changing 3RDPARTY_TCL_DIR variable.")
379   ENDIF()
380 ELSE()
381   GET_FILENAME_COMPONENT(3RDPARTY_TCL_DLL_DIR "${3RDPARTY_TCL_DLL}" PATH)
382   GET_FILENAME_COMPONENT(3RDPARTY_TCL_LIB_DIR "${3RDPARTY_TCL_LIBRARY}" PATH)
383 ENDIF()
384
385 # GLX
386 IF(USE_GLX)
387   ADD_DEFINITIONS(-DMACOSX_USE_GLX)
388
389   IF(NOT DEFINED 3RDPARTY_GLX_DIR)
390     SET(3RDPARTY_GLX_DIR "" CACHE PATH "Directory contains GLX product")
391   ENDIF()
392
393   IF(3RDPARTY_DIR AND ("${3RDPARTY_GLX_DIR}" STREQUAL "" OR CHANGES_ARE_NEEDED))
394     FIND_PRODUCT_DIR("${3RDPARTY_DIR}" GLX GLX_DIR_NAME)
395     IF("${GLX_DIR_NAME}" STREQUAL "")
396       MESSAGE(STATUS "GLX DON'T FIND")
397     ELSE()
398       SET(3RDPARTY_GLX_DIR "${3RDPARTY_DIR}/${GLX_DIR_NAME}" CACHE PATH "Directory contains GLX product" FORCE)
399     ENDIF()
400   ENDIF()
401
402   IF(3RDPARTY_GLX_DIR)
403     SET(3RDPARTY_GLX_INCLUDE_DIR "${3RDPARTY_GLX_DIR}/include" CACHE FILEPATH "Directory contains headers of the GLX product" FORCE)
404     SET(3RDPARTY_GLX_LIBRARY_DIR "${3RDPARTY_GLX_DIR}/lib"     CACHE FILEPATH "Directory contains library of the GLX product" FORCE)
405
406     SET(3RDPARTY_INCLUDE_DIRS "${3RDPARTY_INCLUDE_DIRS};${3RDPARTY_GLX_INCLUDE_DIR}")
407     SET(3RDPARTY_LIBRARY_DIRS "${3RDPARTY_LIBRARY_DIRS};${3RDPARTY_GLX_LIBRARY_DIR}")
408
409     MARK_AS_ADVANCED(3RDPARTY_GLX_DIR)
410   ELSE()
411     LIST(APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_GLX_INCLUDE_DIR)
412     LIST(APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_GLX_LIBRARY_DIR)
413   ENDIF()
414 ENDIF()
415
416 # FREETYPE
417 THIRDPARTY_PRODUCT("FREETYPE" "ft2build.h" "freetype${3RDPARTY_BUILD_SUFFIX}")
418
419 # FREEIMAGE
420 IF(USE_FREEIMAGE)
421   ADD_DEFINITIONS(-DHAVE_FREEIMAGE)
422
423   THIRDPARTY_PRODUCT("FREEIMAGE" "FreeImage.h" "freeimage${3RDPARTY_BUILD_SUFFIX}")
424   IF(WIN32)
425     IF("${3RDPARTY_FREEIMAGE_DIR}" STREQUAL "")
426     ELSE()
427       SET (3RDPARTY_FREEIMAGEPLUS_DIR "${3RDPARTY_FREEIMAGE_DIR}")
428     ENDIF()
429
430     THIRDPARTY_PRODUCT("FREEIMAGEPLUS" "FreeImagePlus.h" "freeimageplus${3RDPARTY_BUILD_SUFFIX}")
431
432   ENDIF()
433 ELSE()
434   CHECK_AND_UNSET_GROUP ("3RDPARTY_FREEIMAGE")
435   CHECK_AND_UNSET_GROUP ("3RDPARTY_FREEIMAGEPLUS")
436   CHECK_AND_UNSET ("INSTALL_FREEIMAGE")
437   CHECK_AND_UNSET ("INSTALL_FREEIMAGEPLUS")
438 ENDIF()
439
440 # GL2PS
441 IF(USE_GL2PS)
442   ADD_DEFINITIONS(-DHAVE_GL2PS)
443   THIRDPARTY_PRODUCT("GL2PS" "gl2ps.h" "gl2ps${3RDPARTY_BUILD_SUFFIX}")
444 ELSE()
445   CHECK_AND_UNSET_GROUP ("3RDPARTY_GL2PS")
446   CHECK_AND_UNSET ("INSTALL_GL2PS")
447 ENDIF()
448
449 # OPENCL
450 IF(USE_OPENCL)
451   ADD_DEFINITIONS(-DHAVE_OPENCL)
452
453   SET (3RDPARTY_OPENCL_ADDITIONAL_PATH_FOR_HEADER $ENV{AMDAPPSDKROOT}/include
454                                                   $ENV{INTELOCLSDKROOT}/include
455                                                   $ENV{NVSDKCOMPUTE_ROOT}/OpenCL/common/inc
456                                                   $ENV{ATISTREAMSDKROOT}/include)
457
458
459   IF(${COMPILER_BITNESS} STREQUAL 32)
460     SET (3RDPARTY_OPENCL_ADDITIONAL_PATH_FOR_LIB $ENV{AMDAPPSDKROOT}/lib/x86
461                                                  $ENV{INTELOCLSDKROOT}/lib/x86
462                                                  $ENV{NVSDKCOMPUTE_ROOT}/OpenCL/common/lib/Win32
463                                                  $ENV{ATISTREAMSDKROOT}/lib/x86)
464   ELSEIF(${COMPILER_BITNESS} STREQUAL 64)
465     SET (3RDPARTY_OPENCL_ADDITIONAL_PATH_FOR_LIB $ENV{AMDAPPSDKROOT}/lib/x86_64
466                                                  $ENV{INTELOCLSDKROOT}/lib/x64
467                                                  $ENV{NVSDKCOMPUTE_ROOT}/OpenCL/common/lib/x64
468                                                  $ENV{ATISTREAMSDKROOT}/lib/x86_64)
469   ENDIF()
470
471
472   THIRDPARTY_PRODUCT("OPENCL" "CL/cl.h" "OpenCL${3RDPARTY_BUILD_SUFFIX}")
473
474   # if CL/cl.h isn't found (and 3RDPARTY_OPENCL_INCLUDE_DIR isn't defined)
475   # then try to find OpenCL/cl.h (all other variable won't be changed)
476   IF("${3RDPARTY_OPENCL_INCLUDE_DIR}" STREQUAL "" OR "${3RDPARTY_OPENCL_INCLUDE_DIR}" STREQUAL "3RDPARTY_OPENCL_INCLUDE_DIR-NOTFOUND")
477     THIRDPARTY_PRODUCT("OPENCL" "OpenCL/cl.h" "OpenCL${3RDPARTY_BUILD_SUFFIX}")
478   ENDIF()
479   
480 ELSE()
481   CHECK_AND_UNSET_GROUP ("3RDPARTY_OPENCL")
482   CHECK_AND_UNSET ("3RDPARTY_OPENCL_ADDITIONAL_PATH_FOR_HEADER")
483   CHECK_AND_UNSET ("3RDPARTY_OPENCL_ADDITIONAL_PATH_FOR_LIB")
484   CHECK_AND_UNSET ("INSTALL_OPENCL")
485 ENDIF()
486
487 # TBB
488 IF (USE_TBB)
489   ADD_DEFINITIONS(-DHAVE_TBB)
490
491   INCLUDE(adm/templates/tbb.cmake)
492
493   IF(INSTALL_TBB)
494     INSTALL(FILES "${3RDPARTY_TBB_DLL}" "${3RDPARTY_TBB_MALLOC_DLL}" DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/${DLL_SO_FOLDER}${BUILD_SUFFIX}")
495
496     SET(3RDPARTY_TBB_DLL_DIR "")
497     SET(3RDPARTY_TBB_MALLOC_DLL_DIR "")
498   ELSE()
499     GET_FILENAME_COMPONENT(3RDPARTY_TBB_DLL_DIR "${3RDPARTY_TBB_DLL}" PATH)
500     GET_FILENAME_COMPONENT(3RDPARTY_TBB_MALLOC_DLL_DIR "${3RDPARTY_TBB_MALLOC_DLL}" PATH)
501   ENDIF()
502 ELSE()
503   CHECK_AND_UNSET_GROUP ("3RDPARTY_TBB")
504   CHECK_AND_UNSET_GROUP ("3RDPARTY_TBB_MALLOC")
505   CHECK_AND_UNSET ("3RDPARTY_TBB_DIR_NAME")
506   CHECK_AND_UNSET ("INSTALL_TBB")
507 ENDIF()
508
509 string( REGEX REPLACE ";" " " 3RDPARTY_NOT_INCLUDED "${3RDPARTY_NOT_INCLUDED}")
510
511 #CHECK ALL 3RDPARTY PATHS
512 IF(3RDPARTY_NOT_INCLUDED)
513   MESSAGE(FATAL_ERROR "NOT FOUND: ${3RDPARTY_NOT_INCLUDED}" )
514 ENDIF()
515
516 list(REMOVE_DUPLICATES 3RDPARTY_INCLUDE_DIRS)
517 string( REGEX REPLACE ";" "\n\t" 3RDPARTY_INCLUDE_DIRS_WITH_ENDS "${3RDPARTY_INCLUDE_DIRS}")
518 MESSAGE(STATUS "3RDPARTY_INCLUDE_DIRS: ${3RDPARTY_INCLUDE_DIRS_WITH_ENDS}")
519 include_directories( ${3RDPARTY_INCLUDE_DIRS} )
520
521 list(REMOVE_DUPLICATES 3RDPARTY_LIBRARY_DIRS)
522 string( REGEX REPLACE ";" "\n\t" 3RDPARTY_LIBRARY_DIRS_WITH_ENDS "${3RDPARTY_LIBRARY_DIRS}")
523 MESSAGE(STATUS "3RDPARTY_LIBRARY_DIRS: ${3RDPARTY_LIBRARY_DIRS_WITH_ENDS}")
524 link_directories( ${3RDPARTY_LIBRARY_DIRS} )
525
526 IF("${INSTALL_DIR}" STREQUAL "")
527   MESSAGE(FATAL_ERROR "INSTALL_DIR is empty")
528 ELSE()
529   # inc,data,tests DIRECTORY
530   install(DIRECTORY "${CMAKE_SOURCE_DIR}/inc"          DESTINATION  "${INSTALL_DIR}")
531   install(DIRECTORY "${CMAKE_SOURCE_DIR}/data"         DESTINATION  "${INSTALL_DIR}")
532   install(DIRECTORY "${CMAKE_SOURCE_DIR}/samples/tcl"  DESTINATION  "${INSTALL_DIR}/samples")
533   IF(INSTALL_TESTS)
534     install(DIRECTORY "${CMAKE_SOURCE_DIR}/tests" DESTINATION  "${INSTALL_DIR}" )
535   ENDIF()
536
537     # install patch inc, data, tests folder
538   IF(NOT "${BUILD_PATCH_DIR}" STREQUAL "")
539     IF(EXISTS "${BUILD_PATCH_DIR}/inc")
540       install(DIRECTORY "${BUILD_PATCH_DIR}/inc" DESTINATION  "${INSTALL_DIR}" )
541     ENDIF()
542     
543     IF(EXISTS "${BUILD_PATCH_DIR}/data")
544       install(DIRECTORY "${BUILD_PATCH_DIR}/data"  DESTINATION  "${INSTALL_DIR}" )
545     ENDIF()
546     
547     IF(INSTALL_TESTS)
548       IF(EXISTS "${BUILD_PATCH_DIR}/tests")
549         install(DIRECTORY "${BUILD_PATCH_DIR}/tests" DESTINATION  "${INSTALL_DIR}" )
550       ENDIF()
551     ENDIF()
552   ENDIF()
553   
554   # DRAW.BAT or DRAW.SH
555   IF(NOT "${BUILD_PATCH_DIR}" STREQUAL "" AND EXISTS "${BUILD_PATCH_DIR}/adm/templates/draw.${SCRIPT_EXT}")
556     install(FILES "${BUILD_PATCH_DIR}/adm/templates/draw.${SCRIPT_EXT}" DESTINATION  "${INSTALL_DIR}" PERMISSIONS  
557             OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_WRITE GROUP_EXECUTE WORLD_READ WORLD_WRITE WORLD_EXECUTE)
558   ELSE()
559     install(FILES "${CMAKE_SOURCE_DIR}/adm/templates/draw.${SCRIPT_EXT}" DESTINATION  "${INSTALL_DIR}" PERMISSIONS  
560             OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_WRITE GROUP_EXECUTE WORLD_READ WORLD_WRITE WORLD_EXECUTE)
561   ENDIF()
562   
563   
564   SET(CUSTOM_CUR "custom_${COMPILER}_${COMPILER_BITNESS}_${BUILD_SUFFIX}.${SCRIPT_EXT}")
565   
566   if (WIN32)
567     SET (CUSTOM_ADD_CONTENT "\nif exist \"%~dp0${CUSTOM_CUR}\" (\n  call \"%~dp0${CUSTOM_CUR}\" %1 %2 %3 \n)")
568   else()
569     SET (CUSTOM_ADD_CONTENT "\nif [ -e \"\${aScriptPath}/${CUSTOM_CUR}\" ]; then\n  source \"\${aScriptPath}/${CUSTOM_CUR}\" \"\${COMPILER}\" \"\${WOKSTATION}\${ARCH}\" \"\${CASDEB}\" \nfi")
570   endif()
571   
572   # change custom.bat/sh
573   if (EXISTS "${INSTALL_DIR}/custom.${SCRIPT_EXT}")
574     FILE(READ "${INSTALL_DIR}/custom.${SCRIPT_EXT}" CUSTOM_CONTENT)
575
576     SET (CUSTOM_CONTENT "${CUSTOM_CONTENT} ${CUSTOM_ADD_CONTENT}")
577
578     FILE(WRITE "${INSTALL_DIR}/custom.${SCRIPT_EXT}" "${CUSTOM_CONTENT}")
579   else()
580     IF(NOT "${BUILD_PATCH_DIR}" STREQUAL "" AND EXISTS "${BUILD_PATCH_DIR}/adm/templates/custom.${SCRIPT_EXT}.main")
581       configure_file("${BUILD_PATCH_DIR}/adm/templates/custom.${SCRIPT_EXT}.main" "custom.${SCRIPT_EXT}" @ONLY)
582     ELSE()
583       configure_file("${CMAKE_SOURCE_DIR}/adm/templates/custom.${SCRIPT_EXT}.main" "custom.${SCRIPT_EXT}" @ONLY)
584     ENDIF()
585
586     install(FILES "${OCCT_BINARY_DIR}/custom.${SCRIPT_EXT}" DESTINATION  "${INSTALL_DIR}")
587   endif()
588
589   # write current custom.bat/sh
590   IF(NOT "${BUILD_PATCH_DIR}" STREQUAL "" AND EXISTS "${BUILD_PATCH_DIR}/adm/templates/custom.${SCRIPT_EXT}.in")
591     configure_file("${BUILD_PATCH_DIR}/adm/templates/custom.${SCRIPT_EXT}.in" ${CUSTOM_CUR} @ONLY)
592   ELSE()
593     configure_file("${CMAKE_SOURCE_DIR}/adm/templates/custom.${SCRIPT_EXT}.in" ${CUSTOM_CUR} @ONLY)
594   ENDIF()
595
596   install(FILES "${OCCT_BINARY_DIR}/${CUSTOM_CUR}" DESTINATION  "${INSTALL_DIR}" )
597   
598   IF (BUILD_Samples)
599     IF(NOT "${BUILD_PATCH_DIR}" STREQUAL "" AND EXISTS "${BUILD_PATCH_DIR}/adm/templates/sample.bat")
600       install(FILES "${BUILD_PATCH_DIR}/adm/templates/sample.bat" DESTINATION  "${INSTALL_DIR}")
601     ELSE()
602       install(FILES "${CMAKE_SOURCE_DIR}/adm/templates/sample.bat" DESTINATION  "${INSTALL_DIR}")
603     ENDIF()
604   ENDIF()
605
606   IF(NOT "${BUILD_PATCH_DIR}" STREQUAL "" AND EXISTS "${BUILD_PATCH_DIR}/adm/templates/env.${SCRIPT_EXT}.in")
607     configure_file("${BUILD_PATCH_DIR}/adm/templates/env.${SCRIPT_EXT}.in" env.${SCRIPT_EXT} @ONLY)
608   ELSE()
609     configure_file("${CMAKE_SOURCE_DIR}/adm/templates/env.${SCRIPT_EXT}.in" env.${SCRIPT_EXT} @ONLY)
610   ENDIF()
611   install(FILES "${OCCT_BINARY_DIR}/env.${SCRIPT_EXT}" DESTINATION  "${INSTALL_DIR}" )
612 ENDIF()
613
614 # include patched toolkit projects or original ones
615 SET (UNSUBDIRS "")
616 IF(NOT "${BUILD_PATCH_DIR}" STREQUAL "" AND EXISTS "${BUILD_PATCH_DIR}/adm/cmake/CMakeToolKitsDeps.txt")
617   include(${BUILD_PATCH_DIR}/adm/cmake/CMakeToolKitsDeps.txt)
618 ELSE()
619   SET (IS_PATCH_CURRENT "NO")
620   SET (TK_ROOT_DIR ${CMAKE_SOURCE_DIR})
621   include(adm/cmake/CMakeToolKitsDeps.txt)
622 ENDIF()
623
624 # include some required original toolkit
625 IF(NOT "${UNSUBDIRS}" STREQUAL "")
626   SET (IS_PATCH_CURRENT "NO")
627   SET (TK_ROOT_DIR ${CMAKE_SOURCE_DIR})
628   # add required subdirs
629   FOREACH(UNSUBDIR ${UNSUBDIRS})
630     MESSAGE(STATUS "${UNSUBDIR}")
631     subdirs(${TK_ROOT_DIR}/${UNSUBDIR})
632   ENDFOREACH()
633 ENDIF()
634
635 # samples do not support patch usage
636 IF (BUILD_Samples)
637   SET (CMAKE_MFC_FLAG 2)
638   SET (OCCT_ROOT ${CMAKE_SOURCE_DIR})
639
640   SET (MFC_STANDARD_SAMPLES_DIR ${OCCT_ROOT}/samples/mfc/standard)
641   SET (COMMON_WINMAIN_FILE      ${MFC_STANDARD_SAMPLES_DIR}/Common/Winmain.cpp)
642
643   subdirs(samples/mfc/standard/mfcsample)
644   subdirs(samples/mfc/standard/01_Geometry)
645   subdirs(samples/mfc/standard/02_Modeling)
646   subdirs(samples/mfc/standard/03_Viewer2d)
647   subdirs(samples/mfc/standard/04_Viewer3d)
648   subdirs(samples/mfc/standard/05_ImportExport)
649   subdirs(samples/mfc/standard/06_Ocaf)
650   subdirs(samples/mfc/standard/07_Triangulation)
651   subdirs(samples/mfc/standard/08_HLR)
652   subdirs(samples/mfc/standard/09_Animation)
653   subdirs(samples/mfc/standard/10_Convert)
654 ENDIF()