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