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