0024580: CMake doesn't unset becoming unused variables when 3rdparty's usage is switc...
[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 (CHECK_AND_UNSET VARNAME)
213   IF(DEFINED ${VARNAME})
214     UNSET(${VARNAME} CACHE)
215   ENDIF()
216 ENDMACRO()
217
218 MACRO (CHECK_AND_UNSET_GROUP VARNAME)
219   CHECK_AND_UNSET ("${VARNAME}_DIR")
220   CHECK_AND_UNSET ("${VARNAME}_INCLUDE_DIR")
221   CHECK_AND_UNSET ("${VARNAME}_DLL")
222   CHECK_AND_UNSET ("${VARNAME}_LIBRARY")
223 ENDMACRO()
224
225 MACRO(THIRDPARTY_PRODUCT PRODUCT_NAME HEADER_NAME LIBRARY_NAME)
226   IF(NOT DEFINED 3RDPARTY_${PRODUCT_NAME}_DIR)
227     SET(3RDPARTY_${PRODUCT_NAME}_DIR "" CACHE PATH "Directory contains ${PRODUCT_NAME} product")
228   ENDIF()
229
230   IF(3RDPARTY_DIR AND ("${3RDPARTY_${PRODUCT_NAME}_DIR}" STREQUAL "" OR CHANGES_ARE_NEEDED))
231     FIND_PRODUCT_DIR("${3RDPARTY_DIR}" ${PRODUCT_NAME} ${PRODUCT_NAME}_DIR_NAME)
232     IF("${${PRODUCT_NAME}_DIR_NAME}" STREQUAL "")
233       MESSAGE(STATUS "${PRODUCT_NAME} DON'T FIND")
234     ELSE()
235       SET(3RDPARTY_${PRODUCT_NAME}_DIR "${3RDPARTY_DIR}/${${PRODUCT_NAME}_DIR_NAME}" CACHE PATH "Directory contains ${PRODUCT_NAME} product" FORCE)
236     ENDIF()
237   ENDIF()
238
239   SET(INSTALL_${PRODUCT_NAME} OFF CACHE BOOL "Is ${PRODUCT_NAME} lib copy to install directory")
240
241   IF(3RDPARTY_${PRODUCT_NAME}_DIR)
242     IF("${3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR}" STREQUAL "" OR CHANGES_ARE_NEEDED OR "${3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR}" STREQUAL "3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR-NOTFOUND")
243       SET(3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR "3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR-NOTFOUND" CACHE FILEPATH "Directory contains headers of the ${PRODUCT_NAME} product" FORCE)
244       FIND_PATH(3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR ${HEADER_NAME} PATHS "${3RDPARTY_${PRODUCT_NAME}_DIR}/include" NO_DEFAULT_PATH)
245     ENDIF()
246
247     IF("${3RDPARTY_${PRODUCT_NAME}_LIBRARY}" STREQUAL "" OR CHANGES_ARE_NEEDED OR "${3RDPARTY_${PRODUCT_NAME}_LIBRARY}" STREQUAL "3RDPARTY_${PRODUCT_NAME}_LIBRARY-NOTFOUND")
248       SET(3RDPARTY_${PRODUCT_NAME}_LIBRARY "3RDPARTY_${PRODUCT_NAME}_LIBRARY-NOTFOUND" CACHE FILEPATH "Path to library of the ${PRODUCT_NAME} product" FORCE)
249       FIND_LIBRARY(3RDPARTY_${PRODUCT_NAME}_LIBRARY ${LIBRARY_NAME}  PATHS "${3RDPARTY_${PRODUCT_NAME}_DIR}/lib" NO_DEFAULT_PATH)
250     ENDIF()
251
252     IF("${3RDPARTY_${PRODUCT_NAME}_DLL}" STREQUAL "" OR CHANGES_ARE_NEEDED OR "${3RDPARTY_${PRODUCT_NAME}_DLL}" STREQUAL "3RDPARTY_${PRODUCT_NAME}_DLL-NOTFOUND")
253       SET(3RDPARTY_${PRODUCT_NAME}_DLL "3RDPARTY_${PRODUCT_NAME}_DLL-NOTFOUND" CACHE FILEPATH "Path to shared library of the ${PRODUCT_NAME} product" FORCE)
254       FIND_FILE(3RDPARTY_${PRODUCT_NAME}_DLL "${DLL_SO_PREFIX}${LIBRARY_NAME}.${DLL_SO}"  PATHS "${3RDPARTY_${PRODUCT_NAME}_DIR}/${DLL_SO_FOLDER}" NO_DEFAULT_PATH)
255     ENDIF()
256
257     MARK_AS_ADVANCED(3RDPARTY_${PRODUCT_NAME}_DIR)
258   ELSE()
259
260   ENDIF()
261
262   # check default path (with additions) for header search
263   IF("${3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR}" STREQUAL "" OR "${3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR}" STREQUAL "3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR-NOTFOUND")
264     SET(3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR "3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR-NOTFOUND" CACHE FILEPATH "Directory contains headers of the ${PRODUCT_NAME} product" FORCE)
265     FIND_PATH(3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR ${HEADER_NAME} ${3RDPARTY_${PRODUCT_NAME}_ADDITIONAL_PATH_FOR_HEADER})
266   ENDIF()
267
268   # check default path (with additions) for library search
269   IF("${3RDPARTY_${PRODUCT_NAME}_LIBRARY}" STREQUAL "" OR "${3RDPARTY_${PRODUCT_NAME}_LIBRARY}" STREQUAL "3RDPARTY_${PRODUCT_NAME}_LIBRARY-NOTFOUND")
270     SET(3RDPARTY_${PRODUCT_NAME}_LIBRARY "3RDPARTY_${PRODUCT_NAME}_LIBRARY-NOTFOUND" CACHE FILEPATH "Directory contains library of the ${PRODUCT_NAME} product" FORCE)
271     FIND_LIBRARY(3RDPARTY_${PRODUCT_NAME}_LIBRARY ${LIBRARY_NAME} ${3RDPARTY_${PRODUCT_NAME}_ADDITIONAL_PATH_FOR_LIB})
272   ENDIF()
273
274   # check default path (with additions) for DLL search
275   IF("${3RDPARTY_${PRODUCT_NAME}_DLL}" STREQUAL "" OR "${3RDPARTY_${PRODUCT_NAME}_DLL}" STREQUAL "3RDPARTY_${PRODUCT_NAME}_DLL-NOTFOUND")
276     SET(3RDPARTY_${PRODUCT_NAME}_DLL "3RDPARTY_${PRODUCT_NAME}_DLL-NOTFOUND" CACHE FILEPATH "Directory contains shared library of the ${PRODUCT_NAME} product" FORCE)
277     FIND_FILE(3RDPARTY_${PRODUCT_NAME}_DLL "${DLL_SO_PREFIX}${LIBRARY_NAME}.${DLL_SO}" ${3RDPARTY_${PRODUCT_NAME}_ADDITIONAL_PATH_FOR_DLL})
278   ENDIF()
279
280   IF(3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR)
281     SET(3RDPARTY_INCLUDE_DIRS "${3RDPARTY_INCLUDE_DIRS};${3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR}")
282   ELSE()
283     LIST(APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR)
284   ENDIF()
285
286   IF(3RDPARTY_${PRODUCT_NAME}_LIBRARY)
287     GET_FILENAME_COMPONENT(3RDPARTY_${PRODUCT_NAME}_LIBRARY_DIR "${3RDPARTY_${PRODUCT_NAME}_LIBRARY}" PATH)
288     SET(3RDPARTY_LIBRARY_DIRS "${3RDPARTY_LIBRARY_DIRS};${3RDPARTY_${PRODUCT_NAME}_LIBRARY_DIR}")
289   ELSE()
290     LIST(APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_${PRODUCT_NAME}_LIBRARY)
291   ENDIF()
292
293   IF(3RDPARTY_${PRODUCT_NAME}_DLL)
294     #
295   ELSE()
296     LIST(APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_${PRODUCT_NAME}_DLL)
297   ENDIF()
298
299   IF(INSTALL_${PRODUCT_NAME})
300     INSTALL(FILES "${3RDPARTY_${PRODUCT_NAME}_DLL}" DESTINATION "${INSTALL_DIR}/${DLL_SO_FOLDER}")
301     SET(3RDPARTY_${PRODUCT_NAME}_DLL_DIR "")
302   ELSE()
303     GET_FILENAME_COMPONENT(3RDPARTY_${PRODUCT_NAME}_DLL_DIR "${3RDPARTY_${PRODUCT_NAME}_DLL}" PATH)
304   ENDIF()
305 ENDMACRO()
306
307 # TCL
308 INCLUDE(adm/templates/tcl.cmake)
309
310 #install tcltk
311 IF(INSTALL_TCL)
312   SET(3RDPARTY_TCL_DLL_DIR "")
313   SET(3RDPARTY_TCL_LIB_DIR "")
314   
315   GET_FILENAME_COMPONENT(3RDPARTY_TCL_LIB_DIR_INSIDE "${3RDPARTY_TCL_LIBRARY}" PATH)
316   GET_FILENAME_COMPONENT(3RDPARTY_TCL_DLL_DIR_INSIDE "${3RDPARTY_TCL_DLL}" PATH)
317
318   IF (IS_TCL_VERSION_FOUND)
319     SET (TCL_VERSION ${TCL_MAJOR_VERSION}${TCL_SEP}${TCL_MINOR_VERSION})
320     SET (TCL_FOLDER_VERSION ${TCL_MAJOR_VERSION}.${TCL_MINOR_VERSION})
321   ELSE()
322     SET (TCL_VERSION "")
323
324     #TODO SEARCH tclX.X & tkX.X subdirs
325     SET (TCL_FOLDER_VERSION "")
326   ENDIF()
327   
328   INSTALL(FILES "${3RDPARTY_TCL_DLL_DIR_INSIDE}/${DLL_SO_PREFIX}tcl${TCL_VERSION}.${DLL_SO}" DESTINATION "${INSTALL_DIR}/${DLL_SO_FOLDER}")
329   INSTALL(FILES "${3RDPARTY_TCL_DLL_DIR_INSIDE}/${DLL_SO_PREFIX}tk${TCL_VERSION}.${DLL_SO}" DESTINATION "${INSTALL_DIR}/${DLL_SO_FOLDER}")
330   
331   IF (IS_TCL_VERSION_FOUND)
332     INSTALL(DIRECTORY "${3RDPARTY_TCL_LIB_DIR_INSIDE}/tcl8" DESTINATION "${INSTALL_DIR}/lib")
333     INSTALL(DIRECTORY "${3RDPARTY_TCL_LIB_DIR_INSIDE}/tcl${TCL_FOLDER_VERSION}" DESTINATION "${INSTALL_DIR}/lib")
334     INSTALL(DIRECTORY "${3RDPARTY_TCL_LIB_DIR_INSIDE}/tk${TCL_FOLDER_VERSION}" DESTINATION "${INSTALL_DIR}/lib")
335   ELSE()
336     MESSAGE(STATUS "\nWarning: tclX.X and tkX.X subdirs won't be copyied during the installation process.")
337     MESSAGE(STATUS "Try seeking tcl within another folder by changing 3RDPARTY_TCL_DIR variable.")
338   ENDIF()
339 ELSE()
340   GET_FILENAME_COMPONENT(3RDPARTY_TCL_DLL_DIR "${3RDPARTY_TCL_DLL}" PATH)
341   GET_FILENAME_COMPONENT(3RDPARTY_TCL_LIB_DIR "${3RDPARTY_TCL_LIBRARY}" PATH)
342 ENDIF()
343
344 # GLX
345 IF(USE_GLX)
346   ADD_DEFINITIONS(-DMACOSX_USE_GLX)
347
348   IF(NOT DEFINED 3RDPARTY_GLX_DIR)
349     SET(3RDPARTY_GLX_DIR "" CACHE PATH "Directory contains GLX product")
350   ENDIF()
351
352   IF(3RDPARTY_DIR AND ("${3RDPARTY_GLX_DIR}" STREQUAL "" OR CHANGES_ARE_NEEDED))
353     FIND_PRODUCT_DIR("${3RDPARTY_DIR}" GLX GLX_DIR_NAME)
354     IF("${GLX_DIR_NAME}" STREQUAL "")
355       MESSAGE(STATUS "GLX DON'T FIND")
356     ELSE()
357       SET(3RDPARTY_GLX_DIR "${3RDPARTY_DIR}/${GLX_DIR_NAME}" CACHE PATH "Directory contains GLX product" FORCE)
358     ENDIF()
359   ENDIF()
360
361   IF(3RDPARTY_GLX_DIR)
362     SET(3RDPARTY_GLX_INCLUDE_DIR "${3RDPARTY_GLX_DIR}/include" CACHE FILEPATH "Directory contains headers of the GLX product" FORCE)
363     SET(3RDPARTY_GLX_LIBRARY_DIR "${3RDPARTY_GLX_DIR}/lib"     CACHE FILEPATH "Directory contains library of the GLX product" FORCE)
364
365     SET(3RDPARTY_INCLUDE_DIRS "${3RDPARTY_INCLUDE_DIRS};${3RDPARTY_GLX_INCLUDE_DIR}")
366     SET(3RDPARTY_LIBRARY_DIRS "${3RDPARTY_LIBRARY_DIRS};${3RDPARTY_GLX_LIBRARY_DIR}")
367
368     MARK_AS_ADVANCED(3RDPARTY_GLX_DIR)
369   ELSE()
370     LIST(APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_GLX_INCLUDE_DIR)
371     LIST(APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_GLX_LIBRARY_DIR)
372   ENDIF()
373 ENDIF()
374
375 # FREETYPE
376 THIRDPARTY_PRODUCT("FREETYPE" "ft2build.h" "freetype${BUILD_SUFFIX}")
377
378 IF("${3RDPARTY_FREETYPE_INCLUDE_DIR}" STREQUAL "" OR "${3RDPARTY_FREETYPE_INCLUDE_DIR}" STREQUAL "3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR-NOTFOUND")
379
380 ELSEIF(EXISTS "${3RDPARTY_FREETYPE_INCLUDE_DIR}/freetype2/")
381   SET(3RDPARTY_INCLUDE_DIRS "${3RDPARTY_INCLUDE_DIRS};${3RDPARTY_FREETYPE_INCLUDE_DIR}/freetype2")
382 ENDIF()
383
384 # FREEIMAGE
385 IF(USE_FREEIMAGE)
386   ADD_DEFINITIONS(-DHAVE_FREEIMAGE)
387
388   THIRDPARTY_PRODUCT("FREEIMAGE" "FreeImage.h" "freeimage${BUILD_SUFFIX}")
389   IF(WIN32)
390     IF("${3RDPARTY_FREEIMAGE_DIR}" STREQUAL "")
391     ELSE()
392       SET (3RDPARTY_FREEIMAGEPLUS_DIR "${3RDPARTY_FREEIMAGE_DIR}")
393     ENDIF()
394
395     THIRDPARTY_PRODUCT("FREEIMAGEPLUS" "FreeImagePlus.h" "freeimageplus${BUILD_SUFFIX}")
396
397   ENDIF()
398 ELSE()
399   CHECK_AND_UNSET_GROUP ("3RDPARTY_FREEIMAGE")
400   CHECK_AND_UNSET_GROUP ("3RDPARTY_FREEIMAGEPLUS")
401   CHECK_AND_UNSET ("INSTALL_FREEIMAGE")
402   CHECK_AND_UNSET ("INSTALL_FREEIMAGEPLUS")
403 ENDIF()
404
405 # GL2PS
406 IF(USE_GL2PS)
407   ADD_DEFINITIONS(-DHAVE_GL2PS)
408   THIRDPARTY_PRODUCT("GL2PS" "gl2ps.h" "gl2ps${BUILD_SUFFIX}")
409 ELSE()
410   CHECK_AND_UNSET_GROUP ("3RDPARTY_GL2PS")
411   CHECK_AND_UNSET ("INSTALL_GL2PS")
412 ENDIF()
413
414 # OPENCL
415 IF(USE_OPENCL)
416   ADD_DEFINITIONS(-DHAVE_OPENCL)
417
418   SET (3RDPARTY_OPENCL_ADDITIONAL_PATH_FOR_HEADER $ENV{AMDAPPSDKROOT}/include
419                                                   $ENV{INTELOCLSDKROOT}/include
420                                                   $ENV{NVSDKCOMPUTE_ROOT}/OpenCL/common/inc
421                                                   $ENV{ATISTREAMSDKROOT}/include)
422
423
424   IF(${COMPILER_BITNESS} STREQUAL 32)
425     SET (3RDPARTY_OPENCL_ADDITIONAL_PATH_FOR_LIB $ENV{AMDAPPSDKROOT}/lib/x86
426                                                  $ENV{INTELOCLSDKROOT}/lib/x86
427                                                  $ENV{NVSDKCOMPUTE_ROOT}/OpenCL/common/lib/Win32
428                                                  $ENV{ATISTREAMSDKROOT}/lib/x86)
429   ELSEIF(${COMPILER_BITNESS} STREQUAL 64)
430     SET (3RDPARTY_OPENCL_ADDITIONAL_PATH_FOR_LIB $ENV{AMDAPPSDKROOT}/lib/x86_64
431                                                  $ENV{INTELOCLSDKROOT}/lib/x64
432                                                  $ENV{NVSDKCOMPUTE_ROOT}/OpenCL/common/lib/x64
433                                                  $ENV{ATISTREAMSDKROOT}/lib/x86_64)
434   ENDIF()
435
436
437   THIRDPARTY_PRODUCT("OPENCL" "CL/cl.h" "OpenCL${BUILD_SUFFIX}")
438
439   # if CL/cl.h isn't found (and 3RDPARTY_OPENCL_INCLUDE_DIR isn't defined)
440   # then try to find OpenCL/cl.h (all other variable won't be changed)
441   THIRDPARTY_PRODUCT("OPENCL" "OpenCL/cl.h" "OpenCL${BUILD_SUFFIX}")
442 ELSE()
443   CHECK_AND_UNSET_GROUP ("3RDPARTY_OPENCL")
444   CHECK_AND_UNSET ("3RDPARTY_OPENCL_ADDITIONAL_PATH_FOR_LIB")
445   CHECK_AND_UNSET ("3RDPARTY_OPENCL_ADDITIONAL_PATH_FOR_LIB")
446   CHECK_AND_UNSET ("INSTALL_OPENCL")
447 ENDIF()
448
449 # TBB
450 IF (USE_TBB)
451   ADD_DEFINITIONS(-DHAVE_TBB)
452
453   INCLUDE(adm/templates/tbb.cmake)
454
455   IF(INSTALL_TBB)
456     INSTALL(FILES "${3RDPARTY_TBB_DLL}" "${3RDPARTY_TBB_MALLOC_DLL}" DESTINATION "${INSTALL_DIR}/${DLL_SO_FOLDER}")
457
458     SET(3RDPARTY_TBB_DLL_DIR "")
459     SET(3RDPARTY_TBB_MALLOC_DLL_DIR "")
460   ELSE()
461     GET_FILENAME_COMPONENT(3RDPARTY_TBB_DLL_DIR "${3RDPARTY_TBB_DLL}" PATH)
462     GET_FILENAME_COMPONENT(3RDPARTY_TBB_MALLOC_DLL_DIR "${3RDPARTY_TBB_MALLOC_DLL}" PATH)
463   ENDIF()
464 ELSE()
465   CHECK_AND_UNSET_GROUP ("3RDPARTY_TBB")
466   CHECK_AND_UNSET_GROUP ("3RDPARTY_TBB_MALLOC")
467   CHECK_AND_UNSET ("3RDPARTY_TBB_DIR_NAME")
468   CHECK_AND_UNSET ("INSTALL_TBB")
469 ENDIF()
470
471 string( REGEX REPLACE ";" " " 3RDPARTY_NOT_INCLUDED "${3RDPARTY_NOT_INCLUDED}")
472
473 #CHECK ALL 3RDPARTY PATHS
474 IF(3RDPARTY_NOT_INCLUDED)
475   MESSAGE(FATAL_ERROR "NOT FOUND: ${3RDPARTY_NOT_INCLUDED}" )
476 ENDIF()
477
478 list(REMOVE_DUPLICATES 3RDPARTY_INCLUDE_DIRS)
479 string( REGEX REPLACE ";" "\n\t" 3RDPARTY_INCLUDE_DIRS_WITH_ENDS "${3RDPARTY_INCLUDE_DIRS}")
480 MESSAGE(STATUS "3RDPARTY_INCLUDE_DIRS: ${3RDPARTY_INCLUDE_DIRS_WITH_ENDS}")
481 include_directories( ${3RDPARTY_INCLUDE_DIRS} )
482
483 list(REMOVE_DUPLICATES 3RDPARTY_LIBRARY_DIRS)
484 string( REGEX REPLACE ";" "\n\t" 3RDPARTY_LIBRARY_DIRS_WITH_ENDS "${3RDPARTY_LIBRARY_DIRS}")
485 MESSAGE(STATUS "3RDPARTY_LIBRARY_DIRS: ${3RDPARTY_LIBRARY_DIRS_WITH_ENDS}")
486 link_directories( ${3RDPARTY_LIBRARY_DIRS} )
487
488 IF("${INSTALL_DIR}" STREQUAL "")
489   MESSAGE(FATAL_ERROR "INSTALL_DIR is empty")
490 ELSE()
491   # inc,data,tests DIRECTORY
492   install(DIRECTORY "${CMAKE_SOURCE_DIR}/inc"   DESTINATION  "${INSTALL_DIR}" )
493   install(DIRECTORY "${CMAKE_SOURCE_DIR}/data"  DESTINATION  "${INSTALL_DIR}" )
494   IF(INSTALL_TESTS)
495     install(DIRECTORY "${CMAKE_SOURCE_DIR}/tests" DESTINATION  "${INSTALL_DIR}" )
496   ENDIF()
497
498   # DRAW.BAT or DRAW.SH
499   install(FILES "${CMAKE_SOURCE_DIR}/adm/templates/draw.${SCRIPT_EXT}" DESTINATION  "${INSTALL_DIR}" PERMISSIONS  OWNER_READ OWNER_WRITE OWNER_EXECUTE 
500                                                                               GROUP_READ GROUP_WRITE GROUP_EXECUTE 
501                                                                               WORLD_READ WORLD_WRITE WORLD_EXECUTE)
502   IF (BUILD_Samples)
503     install(FILES "${CMAKE_SOURCE_DIR}/adm/templates/sample.bat" DESTINATION  "${INSTALL_DIR}")
504   ENDIF()
505
506   configure_file("${CMAKE_SOURCE_DIR}/adm/templates/env.${SCRIPT_EXT}.in" env.${SCRIPT_EXT} @ONLY)
507   install(FILES "${OCCT_BINARY_DIR}/env.${SCRIPT_EXT}" DESTINATION  "${INSTALL_DIR}" )
508 ENDIF()
509
510 include(adm/cmake/CMakeToolKitsDeps.txt)
511
512 IF (BUILD_Samples)
513   SET (CMAKE_MFC_FLAG 2)
514   SET (OCCT_ROOT ${CMAKE_SOURCE_DIR})
515
516   SET (MFC_STANDARD_SAMPLES_DIR ${OCCT_ROOT}/samples/mfc/standard)
517   SET (COMMON_WINMAIN_FILE      ${MFC_STANDARD_SAMPLES_DIR}/Common/Winmain.cpp)
518
519   subdirs(samples/mfc/standard/mfcsample)
520   subdirs(samples/mfc/standard/01_Geometry)
521   subdirs(samples/mfc/standard/02_Modeling)
522   subdirs(samples/mfc/standard/03_Viewer2d)
523   subdirs(samples/mfc/standard/04_Viewer3d)
524   subdirs(samples/mfc/standard/05_ImportExport)
525   subdirs(samples/mfc/standard/06_Ocaf)
526   subdirs(samples/mfc/standard/07_Triangulation)
527   subdirs(samples/mfc/standard/08_HLR)
528   subdirs(samples/mfc/standard/09_Animation)
529   subdirs(samples/mfc/standard/10_Convert)
530 ENDIF()