0024352: Add Shaders directory to OCCT resources
[occt.git] / CMakeLists.txt
1 cmake_minimum_required ( VERSION 2.6)
2
3 if (NOT BUILD_TYPE)
4   set(BUILD_TYPE "Release" CACHE STRING "Build type of the OCCT" FORCE)
5   SET_PROPERTY(CACHE BUILD_TYPE PROPERTY STRINGS Release Debug)
6 endif()
7
8 set(CMAKE_CONFIGURATION_TYPES ${BUILD_TYPE} CACHE INTERNAL "" FORCE)
9
10 project(OCCT)
11
12 set_property(GLOBAL PROPERTY 3RDPARTY_USE_FOLDERS ON)
13
14 set(BUILD_SHARED_LIBS ON)
15
16 IF("${BUILD_TYPE}" 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_TYPE} CACHE INTERNAL "Build type of the OCCT" FORCE )
25
26 SET( INSTALL_DIR "" CACHE PATH "Directory contains install files of the OCCT" )
27 SET( CMAKE_INSTALL_PREFIX "${INSTALL_DIR}" CACHE INTERNAL "" FORCE )
28
29 set (BUILD_TOOLKITS "" CACHE STRING "Toolkits are included in OCCT")
30 separate_arguments(BUILD_TOOLKITS)
31
32 include(adm/cmake/CMakeModules.txt)
33
34 if (WIN32)
35   set(SCRIPT_EXT bat)
36 else()
37   set(SCRIPT_EXT sh)
38 endif()
39
40 # set compiler short name and choose SSE2 option for appropriate MSVC compilers
41 if (DEFINED MSVC70)
42   SET(COMPILER vc7)
43 elseif (DEFINED MSVC80)
44   SET(COMPILER vc8)
45   if (${COMPILER_BITNESS} STREQUAL 32)
46     add_definitions(/arch:SSE2)
47   endif()
48 elseif (DEFINED MSVC90)
49   SET(COMPILER vc9)
50   if (${COMPILER_BITNESS} STREQUAL 32)
51     add_definitions(/arch:SSE2)
52   endif()
53 elseif (DEFINED MSVC10)
54   SET(COMPILER vc10)
55   if (${COMPILER_BITNESS} STREQUAL 32)
56     add_definitions(/arch:SSE2)
57   endif()
58 elseif (DEFINED MSVC11)
59   SET(COMPILER vc11)
60 else()
61   SET(COMPILER ${CMAKE_GENERATOR})
62 endif()
63
64 if (${COMPILER_BITNESS} STREQUAL 64)
65   add_definitions(-D_OCC64)
66 endif()
67
68 add_definitions(-DCSFDB)
69 if(WIN32)
70   add_definitions(/DWNT -wd4996)
71 elseif(APPLE)
72   add_definitions(-fexceptions -fPIC -DOCC_CONVERT_SIGNALS -DHAVE_WOK_CONFIG_H -DHAVE_CONFIG_H)
73 else()
74   add_definitions(-fexceptions -fPIC -DOCC_CONVERT_SIGNALS -DHAVE_WOK_CONFIG_H -DHAVE_CONFIG_H -DLIN)
75 endif()
76
77 # enable structured exceptions for MSVC
78 string(REGEX MATCH "EHsc" ISFLAG "${CMAKE_CXX_FLAGS}")
79 IF(ISFLAG)
80   STRING(REGEX REPLACE "EHsc" "EHa" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
81 ELSEIF(WIN32)
82   SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -EHa")
83 ENDIF()
84
85 # enable parallel compilation on MSVC 9 and above
86 IF(WIN32)
87   IF(NOT DEFINED MSVC70 AND NOT DEFINED MSVC80)
88     SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -MP")
89   ENDIF()
90 ENDIF()
91
92 # increase compiler warnings level (-W4 for MSVC, -Wall for GCC)
93 IF(MSVC)
94   if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
95     string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
96   else()
97     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
98   endif()
99 elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
100   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
101 endif()
102
103 SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNo_Exception")
104 SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DNo_Exception")
105
106 SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEB")
107 SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DDEB")
108
109 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/out/lib)
110 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/out/lib)
111 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/out/bin)
112
113 # RESOURCES
114 install(DIRECTORY "${CMAKE_SOURCE_DIR}/src/DrawResources" DESTINATION  "${INSTALL_DIR}/src" )
115 install(DIRECTORY "${CMAKE_SOURCE_DIR}/src/StdResource" DESTINATION  "${INSTALL_DIR}/src" )
116 install(DIRECTORY "${CMAKE_SOURCE_DIR}/src/SHMessage" DESTINATION  "${INSTALL_DIR}/src" )
117 install(DIRECTORY "${CMAKE_SOURCE_DIR}/src/Textures" DESTINATION  "${INSTALL_DIR}/src" )
118 install(DIRECTORY "${CMAKE_SOURCE_DIR}/src/Shaders" DESTINATION  "${INSTALL_DIR}/src" )
119 install(DIRECTORY "${CMAKE_SOURCE_DIR}/src/XSMessage" DESTINATION  "${INSTALL_DIR}/src" )
120 install(DIRECTORY "${CMAKE_SOURCE_DIR}/src/TObj" DESTINATION  "${INSTALL_DIR}/src" )
121 install(DIRECTORY "${CMAKE_SOURCE_DIR}/src/XSTEPResource" DESTINATION  "${INSTALL_DIR}/src" )
122 install(DIRECTORY "${CMAKE_SOURCE_DIR}/src/XmlOcafResource" DESTINATION  "${INSTALL_DIR}/src" )
123
124 install(FILES "${CMAKE_SOURCE_DIR}/src/UnitsAPI/Lexi_Expr.dat" DESTINATION  "${INSTALL_DIR}/src/UnitsAPI" )
125 install(FILES "${CMAKE_SOURCE_DIR}/src/UnitsAPI/Units.dat"     DESTINATION  "${INSTALL_DIR}/src/UnitsAPI" )
126
127 IF("${BUILD_TYPE}" STREQUAL "Release") 
128   SET(BUILD_SUFFIX "")
129 ELSE()
130   SET(BUILD_SUFFIX "") # debug == release
131 ENDIF()
132
133 FUNCTION(SUBDIRECTORY_NAMES MAIN_DIRECTORY RESULT)
134   file(GLOB SUB_ITEMS "${MAIN_DIRECTORY}/*")
135   
136   foreach(ITEM ${SUB_ITEMS})
137     if(IS_DIRECTORY "${ITEM}")
138       GET_FILENAME_COMPONENT(ITEM_NAME "${ITEM}" NAME)
139       LIST(APPEND LOCAL_RESULT "${ITEM_NAME}")
140     endif()
141   endforeach()
142   set (${RESULT} ${LOCAL_RESULT} PARENT_SCOPE)
143 ENDFUNCTION()
144
145 FUNCTION(FIND_PRODUCT_DIR ROOT_DIR PRODUCT_NAME RESULT)
146   string( TOLOWER "${PRODUCT_NAME}" lower_PRODUCT_NAME )
147   
148   LIST(APPEND SEARCH_TEMPLATES "${lower_PRODUCT_NAME}.*${COMPILER}.*${COMPILER_BITNESS}")
149   LIST(APPEND SEARCH_TEMPLATES "${lower_PRODUCT_NAME}.*[0-9.]+.*${COMPILER}.*${COMPILER_BITNESS}")
150   LIST(APPEND SEARCH_TEMPLATES "${lower_PRODUCT_NAME}.*[0-9.]+.*${COMPILER_BITNESS}")
151   LIST(APPEND SEARCH_TEMPLATES "${lower_PRODUCT_NAME}.*[0-9.]+")
152   LIST(APPEND SEARCH_TEMPLATES "${lower_PRODUCT_NAME}")
153   
154   SUBDIRECTORY_NAMES( "${ROOT_DIR}" SUBDIR_NAME_LIST)
155   
156   FOREACH( SEARCH_TEMPLATE ${SEARCH_TEMPLATES})
157     IF(LOCAL_RESULT)
158       BREAK()
159     ENDIF()
160     
161     FOREACH(SUBDIR_NAME ${SUBDIR_NAME_LIST})
162       string( TOLOWER "${SUBDIR_NAME}" lower_SUBDIR_NAME )
163       
164       STRING(REGEX MATCH "${SEARCH_TEMPLATE}" DUMMY_VAR "${lower_SUBDIR_NAME}")
165       IF(DUMMY_VAR)
166         LIST(APPEND LOCAL_RESULT ${SUBDIR_NAME})
167       ENDIF()
168     ENDFOREACH()
169   ENDFOREACH()
170   
171   IF(LOCAL_RESULT)
172     LIST(LENGTH "${LOCAL_RESULT}" LOC_LEN)
173     MATH(EXPR LAST_ELEMENT_INDEX "${LOC_LEN}-1")
174     LIST(GET LOCAL_RESULT ${LAST_ELEMENT_INDEX} DUMMY)
175     SET(${RESULT} ${DUMMY} PARENT_SCOPE)
176   ENDIF()  
177 ENDFUNCTION()
178
179 IF(WIN32)
180   SET(DLL_SO "dll")
181   SET(DLL_SO_FOLDER "bin")
182   SET(DLL_SO_PREFIX "")
183 ELSEIF(APPLE)
184   SET(DLL_SO "dylib")
185   SET(DLL_SO_FOLDER "lib")
186   SET(DLL_SO_PREFIX "lib")
187 ELSE()
188   SET(DLL_SO "so")
189   SET(DLL_SO_FOLDER "lib")
190   SET(DLL_SO_PREFIX "lib")
191 ENDIF()
192
193 SET(3RDPARTY_DIR ${CMAKE_SOURCE_DIR} CACHE PATH "Directory contains required 3rdparty products")
194 SET(3RDPARTY_INCLUDE_DIRS "")
195 SET(3RDPARTY_NOT_INCLUDED)
196
197 IF(APPLE)
198   SET(3RDPARTY_USE_GLX OFF CACHE BOOL "whether use X11 OpenGL on OSX or not")
199 ENDIF()
200
201 SET(3RDPARTY_USE_GL2PS OFF CACHE BOOL "whether use gl2ps product or not")
202 SET(3RDPARTY_USE_FREEIMAGE OFF CACHE BOOL "whether use freeimage product or not")
203 SET(3RDPARTY_USE_TBB OFF CACHE BOOL "whether use tbb product or not")
204 SET(3RDPARTY_USE_OPENCL OFF CACHE BOOL "whether use OpenCL or not")
205
206 SET(INSTALL_TESTS OFF CACHE BOOL "Is tests copy to install directory")
207
208 MACRO(THIRDPARTY_PRODUCT PRODUCT_NAME HEADER_NAME LIBRARY_NAME)
209   IF(NOT DEFINED 3RDPARTY_${PRODUCT_NAME}_DIR)
210     SET(3RDPARTY_${PRODUCT_NAME}_DIR "" CACHE PATH "Directory contains ${PRODUCT_NAME} product")
211   ENDIF()
212   
213   IF(3RDPARTY_DIR AND ("${3RDPARTY_${PRODUCT_NAME}_DIR}" STREQUAL "" OR CHANGES_ARE_NEEDED))
214     FIND_PRODUCT_DIR("${3RDPARTY_DIR}" ${PRODUCT_NAME} ${PRODUCT_NAME}_DIR_NAME)
215     IF("${${PRODUCT_NAME}_DIR_NAME}" STREQUAL "")
216       MESSAGE(STATUS "${PRODUCT_NAME} DON'T FIND")
217     ELSE()
218       SET(3RDPARTY_${PRODUCT_NAME}_DIR "${3RDPARTY_DIR}/${${PRODUCT_NAME}_DIR_NAME}" CACHE PATH "Directory contains ${PRODUCT_NAME} product" FORCE)
219     ENDIF()
220   ENDIF()
221   
222   SET(INSTALL_${PRODUCT_NAME} OFF CACHE BOOL "Is ${PRODUCT_NAME} lib copy to install directory")
223
224   IF(3RDPARTY_${PRODUCT_NAME}_DIR)
225     IF("${3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR}" STREQUAL "" OR CHANGES_ARE_NEEDED OR "${3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR}" STREQUAL "3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR-NOTFOUND")
226       SET(3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR "3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR-NOTFOUND" CACHE FILEPATH "Directory contains headers of the ${PRODUCT_NAME} product" FORCE)
227       FIND_PATH(3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR ${HEADER_NAME} PATHS "${3RDPARTY_${PRODUCT_NAME}_DIR}/include" NO_DEFAULT_PATH)
228     ENDIF()
229     
230     IF("${3RDPARTY_${PRODUCT_NAME}_LIBRARY}" STREQUAL "" OR CHANGES_ARE_NEEDED OR "${3RDPARTY_${PRODUCT_NAME}_LIBRARY}" STREQUAL "3RDPARTY_${PRODUCT_NAME}_LIBRARY-NOTFOUND")
231       SET(3RDPARTY_${PRODUCT_NAME}_LIBRARY "3RDPARTY_${PRODUCT_NAME}_LIBRARY-NOTFOUND" CACHE FILEPATH "Directory contains library of the ${PRODUCT_NAME} product" FORCE)
232       FIND_LIBRARY(3RDPARTY_${PRODUCT_NAME}_LIBRARY ${LIBRARY_NAME}  PATHS "${3RDPARTY_${PRODUCT_NAME}_DIR}/lib" NO_DEFAULT_PATH)
233     ENDIF()
234     
235     IF("${3RDPARTY_${PRODUCT_NAME}_DLL}" STREQUAL "" OR CHANGES_ARE_NEEDED OR "${3RDPARTY_${PRODUCT_NAME}_DLL}" STREQUAL "3RDPARTY_${PRODUCT_NAME}_DLL-NOTFOUND")
236       SET(3RDPARTY_${PRODUCT_NAME}_DLL "3RDPARTY_${PRODUCT_NAME}_DLL-NOTFOUND" CACHE FILEPATH "Directory contains shared library of the ${PRODUCT_NAME} product" FORCE)
237       FIND_FILE(3RDPARTY_${PRODUCT_NAME}_DLL "${DLL_SO_PREFIX}${LIBRARY_NAME}.${DLL_SO}"  PATHS "${3RDPARTY_${PRODUCT_NAME}_DIR}/${DLL_SO_FOLDER}" NO_DEFAULT_PATH)
238     ENDIF()
239     
240     MARK_AS_ADVANCED(3RDPARTY_${PRODUCT_NAME}_DIR)
241   ELSE()
242   
243   ENDIF()
244   
245   # check default path (with additions) for header search
246   IF("${3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR}" STREQUAL "" OR "${3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR}" STREQUAL "3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR-NOTFOUND")
247     SET(3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR "3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR-NOTFOUND" CACHE FILEPATH "Directory contains headers of the ${PRODUCT_NAME} product" FORCE)
248     FIND_PATH(3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR ${HEADER_NAME} ${3RDPARTY_${PRODUCT_NAME}_ADDITIONAL_PATH_FOR_HEADER})
249   ENDIF()
250
251   # check default path (with additions) for library search
252   IF("${3RDPARTY_${PRODUCT_NAME}_LIBRARY}" STREQUAL "" OR "${3RDPARTY_${PRODUCT_NAME}_LIBRARY}" STREQUAL "3RDPARTY_${PRODUCT_NAME}_LIBRARY-NOTFOUND")
253     SET(3RDPARTY_${PRODUCT_NAME}_LIBRARY "3RDPARTY_${PRODUCT_NAME}_LIBRARY-NOTFOUND" CACHE FILEPATH "Directory contains library of the ${PRODUCT_NAME} product" FORCE)
254     FIND_LIBRARY(3RDPARTY_${PRODUCT_NAME}_LIBRARY ${LIBRARY_NAME} ${3RDPARTY_${PRODUCT_NAME}_ADDITIONAL_PATH_FOR_LIB})
255   ENDIF()
256
257   # check default path (with additions) for DLL search
258   IF("${3RDPARTY_${PRODUCT_NAME}_DLL}" STREQUAL "" OR "${3RDPARTY_${PRODUCT_NAME}_DLL}" STREQUAL "3RDPARTY_${PRODUCT_NAME}_DLL-NOTFOUND")
259     SET(3RDPARTY_${PRODUCT_NAME}_DLL "3RDPARTY_${PRODUCT_NAME}_DLL-NOTFOUND" CACHE FILEPATH "Directory contains shared library of the ${PRODUCT_NAME} product" FORCE)
260     FIND_FILE(3RDPARTY_${PRODUCT_NAME}_DLL "${DLL_SO_PREFIX}${LIBRARY_NAME}.${DLL_SO}" ${3RDPARTY_${PRODUCT_NAME}_ADDITIONAL_PATH_FOR_DLL})
261   ENDIF()
262
263   IF(3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR)
264     SET(3RDPARTY_INCLUDE_DIRS "${3RDPARTY_INCLUDE_DIRS};${3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR}")
265   ELSE()
266     LIST(APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR)
267   ENDIF()
268
269   IF(3RDPARTY_${PRODUCT_NAME}_LIBRARY)
270     GET_FILENAME_COMPONENT(3RDPARTY_${PRODUCT_NAME}_LIBRARY_DIR "${3RDPARTY_${PRODUCT_NAME}_LIBRARY}" PATH)
271     SET(3RDPARTY_LIBRARY_DIRS "${3RDPARTY_LIBRARY_DIRS};${3RDPARTY_${PRODUCT_NAME}_LIBRARY_DIR}")
272   ELSE()
273     LIST(APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_${PRODUCT_NAME}_LIBRARY)
274   ENDIF()
275   
276   IF(3RDPARTY_${PRODUCT_NAME}_DLL)
277     #
278   ELSE()
279     LIST(APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_${PRODUCT_NAME}_DLL)
280   ENDIF()
281
282   IF(INSTALL_${PRODUCT_NAME})
283     INSTALL(FILES "${3RDPARTY_${PRODUCT_NAME}_DLL}" DESTINATION "${INSTALL_DIR}/${DLL_SO_FOLDER}")
284     SET(3RDPARTY_${PRODUCT_NAME}_DLL_DIR "")
285   ELSE()
286     GET_FILENAME_COMPONENT(3RDPARTY_${PRODUCT_NAME}_DLL_DIR "${3RDPARTY_${PRODUCT_NAME}_DLL}" PATH)
287   ENDIF()
288 ENDMACRO()
289
290 # TCL
291
292 #tcl85 - win; tcl8.5 - lin
293 IF(WIN32)
294   SET(TCL_SEP "")
295 ELSE()
296   SET(TCL_SEP ".")
297 ENDIF()
298   
299 THIRDPARTY_PRODUCT("TCL" "tcl.h" "tcl8${TCL_SEP}5")
300
301 #install tk and libs
302 IF(INSTALL_TCL)
303   GET_FILENAME_COMPONENT(3RDPARTY_TK_LIB_DIR "${3RDPARTY_TCL_LIBRARY}" PATH)
304   GET_FILENAME_COMPONENT(3RDPARTY_TK_DLL_DIR "${3RDPARTY_TCL_DLL}" PATH)
305   
306   INSTALL(FILES "${3RDPARTY_TK_DLL_DIR}/${DLL_SO_PREFIX}tk8${TCL_SEP}5.${DLL_SO}" DESTINATION "${INSTALL_DIR}/${DLL_SO_FOLDER}")
307   INSTALL(DIRECTORY "${3RDPARTY_TK_LIB_DIR}/tcl8.5" DESTINATION "${INSTALL_DIR}/lib")
308   INSTALL(DIRECTORY "${3RDPARTY_TK_LIB_DIR}/tk8.5" DESTINATION "${INSTALL_DIR}/lib")
309 ENDIF()
310
311 # GLX
312 IF(3RDPARTY_USE_GLX)
313   ADD_DEFINITIONS(-DMACOSX_USE_GLX)
314   
315   IF(NOT DEFINED 3RDPARTY_GLX_DIR)
316     SET(3RDPARTY_GLX_DIR "" CACHE PATH "Directory contains GLX product")
317   ENDIF()
318   
319   IF(3RDPARTY_DIR AND ("${3RDPARTY_GLX_DIR}" STREQUAL "" OR CHANGES_ARE_NEEDED))
320     FIND_PRODUCT_DIR("${3RDPARTY_DIR}" GLX GLX_DIR_NAME)
321     IF("${GLX_DIR_NAME}" STREQUAL "")
322       MESSAGE(STATUS "GLX DON'T FIND")
323     ELSE()
324       SET(3RDPARTY_GLX_DIR "${3RDPARTY_DIR}/${GLX_DIR_NAME}" CACHE PATH "Directory contains GLX product" FORCE)
325     ENDIF()
326   ENDIF()
327   
328   IF(3RDPARTY_GLX_DIR)
329     SET(3RDPARTY_GLX_INCLUDE_DIR "${3RDPARTY_GLX_DIR}/include" CACHE FILEPATH "Directory contains headers of the GLX product" FORCE)
330     SET(3RDPARTY_GLX_LIBRARY_DIR "${3RDPARTY_GLX_DIR}/lib"     CACHE FILEPATH "Directory contains library of the GLX product" FORCE)
331     
332     SET(3RDPARTY_INCLUDE_DIRS "${3RDPARTY_INCLUDE_DIRS};${3RDPARTY_GLX_INCLUDE_DIR}")
333     SET(3RDPARTY_LIBRARY_DIRS "${3RDPARTY_LIBRARY_DIRS};${3RDPARTY_GLX_LIBRARY_DIR}")
334     
335     MARK_AS_ADVANCED(3RDPARTY_GLX_DIR)
336   ELSE()
337     LIST(APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_GLX_INCLUDE_DIR)
338     LIST(APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_GLX_LIBRARY_DIR)
339   ENDIF()
340 ENDIF()
341
342 # FREETYPE
343 THIRDPARTY_PRODUCT("FREETYPE" "ft2build.h" "freetype${BUILD_SUFFIX}")
344
345 IF("${3RDPARTY_FREETYPE_INCLUDE_DIR}" STREQUAL "" OR "${3RDPARTY_FREETYPE_INCLUDE_DIR}" STREQUAL "3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR-NOTFOUND")
346   
347 ELSEIF(EXISTS "${3RDPARTY_FREETYPE_INCLUDE_DIR}/freetype2/")
348   SET(3RDPARTY_INCLUDE_DIRS "${3RDPARTY_INCLUDE_DIRS};${3RDPARTY_FREETYPE_INCLUDE_DIR}/freetype2")
349 ENDIF()
350
351 # FREEIMAGE
352 IF(3RDPARTY_USE_FREEIMAGE)
353   ADD_DEFINITIONS(-DHAVE_FREEIMAGE) 
354
355   THIRDPARTY_PRODUCT("FREEIMAGE" "FreeImage.h" "freeimage${BUILD_SUFFIX}")
356   IF(WIN32)
357     IF("${3RDPARTY_FREEIMAGE_DIR}" STREQUAL "")
358     ELSE()
359       SET (3RDPARTY_FREEIMAGEPLUS_DIR "${3RDPARTY_FREEIMAGE_DIR}")
360     ENDIF()
361     
362     THIRDPARTY_PRODUCT("FREEIMAGEPLUS" "FreeImagePlus.h" "freeimageplus${BUILD_SUFFIX}")
363     
364   ENDIF()
365 ENDIF()
366
367 # GL2PS
368 IF(3RDPARTY_USE_GL2PS)
369   ADD_DEFINITIONS(-DHAVE_GL2PS)
370   THIRDPARTY_PRODUCT("GL2PS" "gl2ps.h" "gl2ps${BUILD_SUFFIX}")
371 ENDIF()
372
373 # OPENCL
374 IF(3RDPARTY_USE_OPENCL)
375   ADD_DEFINITIONS(-DHAVE_OPENCL) 
376   
377   SET (3RDPARTY_OPENCL_ADDITIONAL_PATH_FOR_HEADER $ENV{AMDAPPSDKROOT}/include
378                                                   $ENV{INTELOCLSDKROOT}/include
379                                                   $ENV{NVSDKCOMPUTE_ROOT}/OpenCL/common/inc
380                                                   $ENV{ATISTREAMSDKROOT}/include)
381                                                   
382                                                   
383   IF(${COMPILER_BITNESS} STREQUAL 32)
384     SET (3RDPARTY_OPENCL_ADDITIONAL_PATH_FOR_LIB $ENV{AMDAPPSDKROOT}/lib/x86
385                                                  $ENV{INTELOCLSDKROOT}/lib/x86
386                                                  $ENV{NVSDKCOMPUTE_ROOT}/OpenCL/common/lib/Win32
387                                                  $ENV{ATISTREAMSDKROOT}/lib/x86)
388   ELSEIF(${COMPILER_BITNESS} STREQUAL 64)
389     SET (3RDPARTY_OPENCL_ADDITIONAL_PATH_FOR_LIB $ENV{AMDAPPSDKROOT}/lib/x86_64
390                                                  $ENV{INTELOCLSDKROOT}/lib/x64
391                                                  $ENV{NVSDKCOMPUTE_ROOT}/OpenCL/common/lib/x64
392                                                  $ENV{ATISTREAMSDKROOT}/lib/x86_64)
393   ENDIF()
394   
395  
396   THIRDPARTY_PRODUCT("OPENCL" "CL/cl.h" "OpenCL${BUILD_SUFFIX}")
397   
398   # if CL/cl.h isn't found (and 3RDPARTY_OPENCL_INCLUDE_DIR isn't defined) 
399   # then try to find OpenCL/cl.h (all other variable won't be changed)
400   THIRDPARTY_PRODUCT("OPENCL" "OpenCL/cl.h" "OpenCL${BUILD_SUFFIX}")
401 ENDIF()
402
403 # TBB
404 IF (3RDPARTY_USE_TBB)
405   ADD_DEFINITIONS(-DHAVE_TBB)
406
407   IF(${COMPILER_BITNESS} STREQUAL 32)
408     SET (TBB_ARCH_NAME ia32)
409   ELSE()
410     SET (TBB_ARCH_NAME intel64)
411   ENDIF()
412   
413   IF(NOT DEFINED 3RDPARTY_TBB_DIR)
414     SET(3RDPARTY_TBB_DIR "" CACHE PATH "Directory contains tbb product")
415   ENDIF()
416   
417   SET(3RDPARTY_TBB_DIR_NAME "")
418   IF(3RDPARTY_DIR AND ("${3RDPARTY_TBB_DIR}" STREQUAL "" OR CHANGES_ARE_NEEDED))
419     FIND_PRODUCT_DIR("${3RDPARTY_DIR}" "TBB" 3RDPARTY_TBB_DIR_NAME)
420     IF("${3RDPARTY_TBB_DIR_NAME}" STREQUAL "")
421       MESSAGE(STATUS "TBB DON'T FIND")
422     ELSE()
423       SET(3RDPARTY_TBB_DIR "${3RDPARTY_DIR}/${3RDPARTY_TBB_DIR_NAME}" CACHE PATH "Directory contains tbb product" FORCE)
424     ENDIF()
425   ENDIF()
426   
427   SET(INSTALL_TBB OFF CACHE BOOL "Is tbb lib copy to install directory")
428
429   IF(3RDPARTY_TBB_DIR)
430     IF("${3RDPARTY_TBB_INCLUDE_DIR}" STREQUAL "" OR CHANGES_ARE_NEEDED)
431       SET(3RDPARTY_TBB_INCLUDE_DIR "3RDPARTY_TBB_INCLUDE_DIR-NOTFOUND" CACHE PATH "Directory contains headers of the tbb product" FORCE)
432       FIND_PATH(3RDPARTY_TBB_INCLUDE_DIR tbb/tbb.h PATHS "${3RDPARTY_TBB_DIR}/include")
433     ENDIF()
434
435     SET(TBB_DEBUG_POSTFIX "")
436     if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
437       SET(TBB_DEBUG_POSTFIX "") # _debug postfix removed
438     ENDIF()
439     
440     IF("${3RDPARTY_TBB_LIBRARY}" STREQUAL "" OR CHANGES_ARE_NEEDED OR "${3RDPARTY_TBB_LIBRARY}" STREQUAL "3RDPARTY_TBB_LIBRARY-NOTFOUND")
441       SET(3RDPARTY_TBB_LIBRARY "3RDPARTY_TBB_LIBRARY-NOTFOUND" CACHE PATH "Directory contains library of the tbb product" FORCE)
442       FIND_LIBRARY(3RDPARTY_TBB_LIBRARY tbb${TBB_DEBUG_POSTFIX} PATHS "${3RDPARTY_TBB_DIR}/lib/${TBB_ARCH_NAME}/${COMPILER}" NO_DEFAULT_PATH)
443       
444       IF("${3RDPARTY_TBB_LIBRARY}" STREQUAL "3RDPARTY_TBB_LIBRARY-NOTFOUND")
445         FIND_LIBRARY(3RDPARTY_TBB_LIBRARY tbb${TBB_DEBUG_POSTFIX})
446       ENDIF()
447     ENDIF()
448
449     IF("${3RDPARTY_TBB_MALLOC_LIBRARY}" STREQUAL "" OR CHANGES_ARE_NEEDED OR "${3RDPARTY_TBB_MALLOC_LIBRARY}" STREQUAL "3RDPARTY_TBB_MALLOC_LIBRARY-NOTFOUND")
450       SET(3RDPARTY_TBB_MALLOC_LIBRARY "3RDPARTY_TBB_MALLOC_LIBRARY-NOTFOUND" CACHE PATH "Directory contains library of the tbb malloc product" FORCE)
451       FIND_LIBRARY(3RDPARTY_TBB_MALLOC_LIBRARY tbbmalloc${TBB_DEBUG_POSTFIX} PATHS "${3RDPARTY_TBB_DIR}/lib/${TBB_ARCH_NAME}/${COMPILER}" NO_DEFAULT_PATH)
452       
453       IF("${3RDPARTY_TBB_MALLOC_LIBRARY}" STREQUAL "3RDPARTY_TBB_MALLOC_LIBRARY-NOTFOUND")
454         FIND_LIBRARY(3RDPARTY_TBB_MALLOC_LIBRARY tbbmalloc${TBB_DEBUG_POSTFIX})
455       ENDIF()
456     ENDIF()
457     
458     
459     
460     IF("${3RDPARTY_TBB_DLL}" STREQUAL "" OR CHANGES_ARE_NEEDED)
461       SET(3RDPARTY_TBB_DLL "3RDPARTY_TBB_DLL-NOTFOUND" CACHE PATH "Directory contains shared library of the tbb product" FORCE)
462       FIND_FILE(3RDPARTY_TBB_DLL "${DLL_SO_PREFIX}tbb${TBB_DEBUG_POSTFIX}.${DLL_SO}" PATHS "${3RDPARTY_TBB_DIR}/${DLL_SO_FOLDER}/${TBB_ARCH_NAME}/${COMPILER}" NO_DEFAULT_PATH)
463       
464       IF("${3RDPARTY_TBB_DLL}" STREQUAL "3RDPARTY_TBB_DLL-NOTFOUND")
465         FIND_FILE(3RDPARTY_TBB_DLL "${DLL_SO_PREFIX}tbb${TBB_DEBUG_POSTFIX}.${DLL_SO}")
466       ENDIF()
467     ENDIF()
468     
469     IF("${3RDPARTY_TBB_MALLOC_DLL}" STREQUAL "" OR CHANGES_ARE_NEEDED)
470       SET(3RDPARTY_TBB_MALLOC_DLL "3RDPARTY_TBB_MALLOC_DLL-NOTFOUND" CACHE PATH "Directory contains shared library of the tbb malloc product" FORCE)
471       FIND_FILE(3RDPARTY_TBB_MALLOC_DLL "${DLL_SO_PREFIX}tbbmalloc${TBB_DEBUG_POSTFIX}.${DLL_SO}" PATHS "${3RDPARTY_TBB_DIR}/${DLL_SO_FOLDER}/${TBB_ARCH_NAME}/${COMPILER}" NO_DEFAULT_PATH)
472       
473       IF("${3RDPARTY_TBB_MALLOC_DLL}" STREQUAL "3RDPARTY_TBB_MALLOC_DLL-NOTFOUND")
474         FIND_FILE(3RDPARTY_TBB_MALLOC_DLL "${DLL_SO_PREFIX}tbbmalloc${TBB_DEBUG_POSTFIX}.${DLL_SO}")
475       ENDIF()
476     ENDIF()
477
478     MARK_AS_ADVANCED(3RDPARTY_TBB_DIR_NAME)
479   ELSE()
480     LIST(APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_TBB_DIR)
481   ENDIF()
482
483   IF(3RDPARTY_TBB_INCLUDE_DIR)
484     SET(3RDPARTY_INCLUDE_DIRS "${3RDPARTY_INCLUDE_DIRS};${3RDPARTY_TBB_INCLUDE_DIR}")
485   ELSE()
486     LIST(APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_TBB_INCLUDE_DIR)
487   ENDIF()
488
489   IF(3RDPARTY_TBB_LIBRARY)
490     GET_FILENAME_COMPONENT(3RDPARTY_TBB_LIBRARY_DIR "${3RDPARTY_TBB_LIBRARY}" PATH)
491     SET(3RDPARTY_LIBRARY_DIRS "${3RDPARTY_LIBRARY_DIRS};${3RDPARTY_TBB_LIBRARY_DIR}")
492   ELSE()
493     LIST(APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_TBB_LIBRARY)
494   ENDIF()
495   
496   IF(3RDPARTY_TBB_MALLOC_LIBRARY)
497     GET_FILENAME_COMPONENT(3RDPARTY_TBB_LIBRARY_DIR "${3RDPARTY_TBB_MALLOC_LIBRARY}" PATH)
498     SET(3RDPARTY_LIBRARY_DIRS "${3RDPARTY_LIBRARY_DIRS};${3RDPARTY_TBB_LIBRARY_DIR}")
499   ELSE()
500     LIST(APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_TBB_MALLOC_LIBRARY)
501   ENDIF()
502   
503   IF(3RDPARTY_TBB_DLL)
504     #
505   ELSE()
506     LIST(APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_TBB_DLL)
507   ENDIF()
508   
509   IF(3RDPARTY_TBB_MALLOC_DLL)
510     #
511   ELSE()
512     LIST(APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_TBB_MALLOC_DLL)
513   ENDIF()
514
515   IF(INSTALL_TBB)
516     INSTALL(FILES "${3RDPARTY_TBB_DLL}" "${3RDPARTY_TBB_MALLOC_DLL}" DESTINATION "${INSTALL_DIR}/${DLL_SO_FOLDER}")
517
518     SET(3RDPARTY_TBB_DLL_DIR "")
519     SET(3RDPARTY_TBB_MALLOC_DLL_DIR "")
520   ELSE()
521     GET_FILENAME_COMPONENT(3RDPARTY_TBB_DLL_DIR "${3RDPARTY_TBB_DLL}" PATH)
522     GET_FILENAME_COMPONENT(3RDPARTY_TBB_MALLOC_DLL_DIR "${3RDPARTY_TBB_MALLOC_DLL}" PATH)
523   ENDIF()
524 ENDIF()
525
526 string( REGEX REPLACE ";" " " 3RDPARTY_NOT_INCLUDED "${3RDPARTY_NOT_INCLUDED}")
527
528 #CHECK ALL 3RDPARTY PATHS
529 IF(3RDPARTY_NOT_INCLUDED)
530   MESSAGE(FATAL_ERROR "NOT FOUND: ${3RDPARTY_NOT_INCLUDED}" )
531 ENDIF()
532
533 list(REMOVE_DUPLICATES 3RDPARTY_INCLUDE_DIRS)
534 string( REGEX REPLACE ";" "\n\t" 3RDPARTY_INCLUDE_DIRS_WITH_ENDS "${3RDPARTY_INCLUDE_DIRS}")
535 MESSAGE(STATUS "3RDPARTY_INCLUDE_DIRS: ${3RDPARTY_INCLUDE_DIRS_WITH_ENDS}")
536 include_directories( ${3RDPARTY_INCLUDE_DIRS} )
537
538 list(REMOVE_DUPLICATES 3RDPARTY_LIBRARY_DIRS)
539 string( REGEX REPLACE ";" "\n\t" 3RDPARTY_LIBRARY_DIRS_WITH_ENDS "${3RDPARTY_LIBRARY_DIRS}")
540 MESSAGE(STATUS "3RDPARTY_LIBRARY_DIRS: ${3RDPARTY_LIBRARY_DIRS_WITH_ENDS}")
541 link_directories( ${3RDPARTY_LIBRARY_DIRS} )
542
543 #
544 SET(RUN_PROJECT "")
545 SET(CASROOT_DEFINITION "set \"CASROOT=${CMAKE_SOURCE_DIR}\"")
546 SET(BIN_DIR_POSTFIX "bin")
547 SET(RESOURCE_DIR_PREFIX "%SCRIPTROOT%\\src")
548
549 IF("${INSTALL_DIR}" STREQUAL "")
550   MESSAGE(FATAL_ERROR "INSTALL_DIR is empty")
551 ELSE()
552   # inc,data,tests DIRECTORY
553   install(DIRECTORY "${CMAKE_SOURCE_DIR}/inc"   DESTINATION  "${INSTALL_DIR}" )
554   install(DIRECTORY "${CMAKE_SOURCE_DIR}/data"  DESTINATION  "${INSTALL_DIR}" )
555   IF(INSTALL_TESTS)
556     install(DIRECTORY "${CMAKE_SOURCE_DIR}/tests" DESTINATION  "${INSTALL_DIR}" )
557   ENDIF()
558
559   # DRAW.BAT or DRAW.SH
560   install(FILES "${CMAKE_SOURCE_DIR}/adm/cmake/draw.${SCRIPT_EXT}" DESTINATION  "${INSTALL_DIR}" PERMISSIONS  OWNER_READ OWNER_WRITE OWNER_EXECUTE 
561                                                                               GROUP_READ GROUP_WRITE GROUP_EXECUTE 
562                                                                               WORLD_READ WORLD_WRITE WORLD_EXECUTE)
563
564   configure_file("${CMAKE_SOURCE_DIR}/adm/cmake/env.${SCRIPT_EXT}.in" env.${SCRIPT_EXT} @ONLY)
565   install(FILES "${OCCT_BINARY_DIR}/env.${SCRIPT_EXT}" DESTINATION  "${INSTALL_DIR}" )
566 ENDIF()
567
568 IF(MSVC AND "${BUILD_TYPE}" STREQUAL "Debug")
569   SET(RUN_PROJECT "start OCCT.sln")
570   SET(BIN_DIR_POSTFIX "out\\bin\\Debug")
571   SET(RESOURCE_DIR_PREFIX "%CASROOT%\\src")
572   configure_file("${CMAKE_SOURCE_DIR}/adm/cmake/env.bat.in" OCCT.bat @ONLY)
573 ENDIF()
574
575 include(adm/cmake/CMakeToolKitsDeps.txt)