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