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