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