0025656: Specification of semantic of Closed flag of an edge
[occt.git] / CMakeLists.txt
1 cmake_minimum_required (VERSION 2.8.10 FATAL_ERROR)
2
3 set (CMAKE_SUPPRESS_REGENERATION TRUE)
4
5 # set build configurations list
6 if (NOT BUILD_CONFIGURATION)
7   set (BUILD_CONFIGURATION "Release" CACHE STRING "Build type of OCCT" FORCE)
8   SET_PROPERTY(CACHE BUILD_CONFIGURATION PROPERTY STRINGS Release Debug RelWithDebInfo)
9 endif()
10
11 set (CMAKE_CONFIGURATION_TYPES ${BUILD_CONFIGURATION} CACHE INTERNAL "" FORCE)
12
13 # the name of the project
14 project (OCCT)
15
16 # Solution folder property
17 set_property (GLOBAL PROPERTY USE_FOLDERS ON)
18
19 set (CMAKE_BUILD_TYPE ${BUILD_CONFIGURATION} CACHE INTERNAL "Build type of OCCT" FORCE )
20
21 # install dir of the built project
22 set (INSTALL_DIR "" CACHE PATH "Directory that will contain install files of OCCT" )
23 set (CMAKE_INSTALL_PREFIX "${INSTALL_DIR}" CACHE INTERNAL "" FORCE )
24
25 # whether install test bundle or not
26 set (INSTALL_TESTS OFF CACHE BOOL "Is tests copy to install directory")
27
28 set (BUILD_PATCH_DIR "" CACHE PATH "directory with OCCT patch")
29
30 # the list of being built toolkits
31 set (BUILD_TOOLKITS "" CACHE STRING "Toolkits are also included in OCCT")
32 separate_arguments (BUILD_TOOLKITS)
33
34 if (MSVC)
35   set (BUILD_MFC_SAMPLES OFF CACHE BOOL "OCCT samples building")
36 endif()
37
38 # whether use optional 3rdparty or not
39 if (APPLE)
40   set (USE_GLX OFF CACHE BOOL "Are X11 OpenGL used on OSX or not")
41 endif()
42
43 set (USE_FREEIMAGE OFF CACHE BOOL "Is freeimage used or not")
44 set (USE_VTK OFF CACHE BOOL "Is VTK used or not")
45
46 if (NOT DEFINED ANDROID)
47   set (USE_GL2PS OFF CACHE BOOL "Is gl2ps used or not")
48   set (USE_TBB OFF CACHE BOOL "Is tbb used or not")
49   set (USE_OPENCL OFF CACHE BOOL "Is OpenCL used or not")
50 endif()
51
52 # macro: include patched file if it exists
53 macro (OCCT_INCLUDE_CMAKE_FILE BEING_INCLUDED_FILE)
54   if (NOT "${BUILD_PATCH_DIR}" STREQUAL "" AND EXISTS "${BUILD_PATCH_DIR}/${BEING_INCLUDED_FILE}.cmake")
55     include(${BUILD_PATCH_DIR}/${BEING_INCLUDED_FILE}.cmake)
56   else()
57     include(${BEING_INCLUDED_FILE}.cmake)
58   endif()
59 endmacro()
60
61 # include occt macros
62 OCCT_INCLUDE_CMAKE_FILE ("adm/templates/occt_macros")
63
64 # BUILD_POSTFIX variable is used by all toolkit cmakelists.txt projects
65 OCCT_MAKE_BUILD_POSTFIX()
66
67 # include the patched or original list of modules
68 OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/occt_modules")
69
70 # include the list of being used toolkits. USED_TOOLKITS variable
71 OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/occt_toolkits")
72
73 # include the patched or original list of definitions and flags
74 OCCT_INCLUDE_CMAKE_FILE ("adm/templates/occt_defs_flags")
75
76 OCCT_INCLUDE_CMAKE_FILE ("adm/templates/3rdparty_macro")
77
78 set (3RDPARTY_DIR_LABEL "The directory containing required 3rdparty products")
79 if (NOT DEFINED 3RDPARTY_DIR)
80   set (3RDPARTY_DIR "" CACHE PATH ${3RDPARTY_DIR_LABEL})
81 endif()
82
83 # search for 3rdparty dir
84 if ("${3RDPARTY_DIR}" STREQUAL "")
85   if (DEFINED ENV{3RDPARTY_DIR})
86     set (3RDPARTY_DIR "$ENV{3RDPARTY_DIR}" CACHE PATH ${3RDPARTY_DIR_LABEL} FORCE)
87   elseif (EXISTS "${CMAKE_SOURCE_DIR}/../")
88     # in version 6.7.0 and above, occt parent directory contains 3rdparties
89     GET_FILENAME_COMPONENT(3RDPARTY_DIR "${CMAKE_SOURCE_DIR}/../" ABSOLUTE)
90     SET(3RDPARTY_DIR "${3RDPARTY_DIR}" CACHE PATH ${3RDPARTY_DIR_LABEL} FORCE)
91   endif()
92 endif()
93
94 # search for CSF_TclLibs variable in EXTERNLIB of each being used toolkit
95 OCCT_IS_PRODUCT_REQUIRED(CSF_TclLibs USE_TCL)
96
97 if ("${USE_TCL}" STREQUAL ON)
98   message (STATUS "Info: tcl is used by OCCT")
99   OCCT_INCLUDE_CMAKE_FILE ("adm/templates/tcl")
100 else()
101   OCCT_CHECK_AND_UNSET ("3RDPARTY_TCL_DIR")
102   OCCT_CHECK_AND_UNSET ("3RDPARTY_TCL_INCLUDE_DIR")
103   OCCT_CHECK_AND_UNSET ("3RDPARTY_TCL_LIBRARY")
104   OCCT_CHECK_AND_UNSET ("3RDPARTY_TCL_LIBRARY_DIR")
105   OCCT_CHECK_AND_UNSET ("3RDPARTY_TK_INCLUDE_DIR")
106   OCCT_CHECK_AND_UNSET ("3RDPARTY_TK_LIBRARY")
107   OCCT_CHECK_AND_UNSET ("3RDPARTY_TK_LIBRARY_DIR")
108 endif()
109
110 # search for CSF_FREETYPE variable in EXTERNLIB of each being used toolkit
111 OCCT_IS_PRODUCT_REQUIRED(CSF_FREETYPE USE_FREETYPE)
112
113 if ("${USE_FREETYPE}" STREQUAL ON)
114   message (STATUS "Info: freetype is used by OCCT")
115   OCCT_INCLUDE_CMAKE_FILE ("adm/templates/freetype")
116 else()
117   OCCT_CHECK_AND_UNSET ("3RDPARTY_FREETYPE_DIR")
118   OCCT_CHECK_AND_UNSET ("3RDPARTY_FREETYPE_INCLUDE_DIR_freetype2")
119   OCCT_CHECK_AND_UNSET ("3RDPARTY_FREETYPE_INCLUDE_DIR_ft2build")
120   OCCT_CHECK_AND_UNSET ("3RDPARTY_FREETYPE_LIBRARY")
121   OCCT_CHECK_AND_UNSET ("3RDPARTY_FREETYPE_LIBRARY_DIR")
122 endif()
123
124 # VTK
125 if (USE_VTK)
126   add_definitions (-DHAVE_VTK)
127   OCCT_INCLUDE_CMAKE_FILE ("adm/templates/vtk")
128 endif()
129
130 # GLX
131 if (USE_GLX)
132   add_definitions (-DMACOSX_USE_GLX)
133   OCCT_INCLUDE_CMAKE_FILE ("adm/templates/glx")
134 endif()
135
136 # FREEIMAGE
137 if (USE_FREEIMAGE)
138   add_definitions (-DHAVE_FREEIMAGE)
139   OCCT_INCLUDE_CMAKE_FILE ("adm/templates/freeimage")
140   OCCT_INCLUDE_CMAKE_FILE ("adm/templates/freeimageplus")
141 else()
142   OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_FREEIMAGE")
143   OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_FREEIMAGEPLUS")
144   OCCT_CHECK_AND_UNSET ("INSTALL_FREEIMAGE")
145   OCCT_CHECK_AND_UNSET ("INSTALL_FREEIMAGEPLUS")
146 endif()
147
148 # GL2PS
149 if (USE_GL2PS)
150   add_definitions (-DHAVE_GL2PS)
151   OCCT_INCLUDE_CMAKE_FILE ("adm/templates/gl2ps")
152 else()
153   OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_GL2PS")
154   OCCT_CHECK_AND_UNSET ("INSTALL_GL2PS")
155 endif()
156
157 # OPENCL
158 if (USE_OPENCL)
159   add_definitions (-DHAVE_OPENCL)
160   OCCT_INCLUDE_CMAKE_FILE ("adm/templates/opencl")
161 else()
162   OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_OPENCL")
163   OCCT_CHECK_AND_UNSET ("3RDPARTY_OPENCL_ADDITIONAL_PATH_FOR_HEADER")
164   OCCT_CHECK_AND_UNSET ("3RDPARTY_OPENCL_ADDITIONAL_PATH_FOR_LIB")
165   OCCT_CHECK_AND_UNSET ("INSTALL_OPENCL")
166 endif()
167
168 # TBB
169 if (USE_TBB)
170   ADD_DEFINITIONS(-DHAVE_TBB)
171   OCCT_INCLUDE_CMAKE_FILE ("adm/templates/tbb")
172 else()
173   OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_TBB")
174   OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_TBBMALLOC")
175   OCCT_CHECK_AND_UNSET ("INSTALL_TBB")
176 endif()
177
178 string (REGEX REPLACE ";" " " 3RDPARTY_NOT_INCLUDED "${3RDPARTY_NOT_INCLUDED}")
179
180 # check all 3rdparty paths
181 if (3RDPARTY_NOT_INCLUDED)
182   message (FATAL_ERROR "NOT FOUND: ${3RDPARTY_NOT_INCLUDED}" )
183 endif()
184
185 if (3RDPARTY_INCLUDE_DIRS)
186   list (REMOVE_DUPLICATES 3RDPARTY_INCLUDE_DIRS)
187   string (REGEX REPLACE ";" "\n\t" 3RDPARTY_INCLUDE_DIRS_WITH_ENDS "${3RDPARTY_INCLUDE_DIRS}")
188   message (STATUS "The directories containing 3rdparty headers: ${3RDPARTY_INCLUDE_DIRS_WITH_ENDS}")
189   include_directories (${3RDPARTY_INCLUDE_DIRS})
190 endif()
191
192 if (3RDPARTY_LIBRARY_DIRS)
193   list (REMOVE_DUPLICATES 3RDPARTY_LIBRARY_DIRS)
194   string (REGEX REPLACE ";" "\n\t" 3RDPARTY_LIBRARY_DIRS_WITH_ENDS "${3RDPARTY_LIBRARY_DIRS}")
195   message (STATUS "The directories containing 3rdparty libraries: ${3RDPARTY_LIBRARY_DIRS_WITH_ENDS}")
196   link_directories (${3RDPARTY_LIBRARY_DIRS})
197 endif()
198
199 OCCT_MAKE_BUILD_POSTFIX()
200
201 # build directories
202 set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/out/lib${BUILD_POSTFIX})
203 set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/out/lib${BUILD_POSTFIX})
204 set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/out/bin${BUILD_POSTFIX})
205
206 if ("${INSTALL_DIR}" STREQUAL "")
207   message (FATAL_ERROR "INSTALL_DIR variable is empty. It's required to define installation directory")
208 else()
209   # inc,data,tests DIRECTORY
210   install (DIRECTORY "${CMAKE_SOURCE_DIR}/inc"          DESTINATION  "${INSTALL_DIR}")
211   install (DIRECTORY "${CMAKE_SOURCE_DIR}/data"         DESTINATION  "${INSTALL_DIR}")
212   install (DIRECTORY "${CMAKE_SOURCE_DIR}/samples/tcl"  DESTINATION  "${INSTALL_DIR}/samples")
213   if (INSTALL_TESTS)
214     install (DIRECTORY "${CMAKE_SOURCE_DIR}/tests" DESTINATION  "${INSTALL_DIR}" )
215   endif()
216
217   # install patch inc, data, tests folder
218   if (NOT "${BUILD_PATCH_DIR}" STREQUAL "")
219     if (EXISTS "${BUILD_PATCH_DIR}/inc")
220       install (DIRECTORY "${BUILD_PATCH_DIR}/inc" DESTINATION  "${INSTALL_DIR}" )
221     endif()
222
223     if (EXISTS "${BUILD_PATCH_DIR}/data")
224       install (DIRECTORY "${BUILD_PATCH_DIR}/data"  DESTINATION  "${INSTALL_DIR}" )
225     endif()
226
227     if (INSTALL_TESTS)
228       if (EXISTS "${BUILD_PATCH_DIR}/tests")
229         install (DIRECTORY "${BUILD_PATCH_DIR}/tests" DESTINATION  "${INSTALL_DIR}" )
230       endif()
231     endif()
232   endif()
233
234   if (WIN32)
235     set (SCRIPT_EXT bat)
236   else()
237     set (SCRIPT_EXT sh)
238   endif()
239
240   # DRAW.BAT or DRAW.SH
241   IF(NOT "${BUILD_PATCH_DIR}" STREQUAL "" AND EXISTS "${BUILD_PATCH_DIR}/adm/templates/draw.${SCRIPT_EXT}")
242     install(FILES "${BUILD_PATCH_DIR}/adm/templates/draw.${SCRIPT_EXT}" DESTINATION  "${INSTALL_DIR}" PERMISSIONS
243             OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_WRITE GROUP_EXECUTE WORLD_READ WORLD_WRITE WORLD_EXECUTE)
244   ELSE()
245     install(FILES "${CMAKE_SOURCE_DIR}/adm/templates/draw.${SCRIPT_EXT}" DESTINATION  "${INSTALL_DIR}" PERMISSIONS
246             OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_WRITE GROUP_EXECUTE WORLD_READ WORLD_WRITE WORLD_EXECUTE)
247   ENDIF()
248
249   # set compiler short name
250   OCCT_MAKE_COMPILER_SHORT_NAME()
251
252   OCCT_MAKE_COMPILER_BITNESS()
253
254   SET(SUB_CUSTOM "custom_${COMPILER}_${COMPILER_BITNESS}_${BUILD_POSTFIX}.${SCRIPT_EXT}")
255
256   if (WIN32)
257     SET (ADDITIONAL_CUSTOM_CONTENT "\nif exist \"%~dp0${SUB_CUSTOM}\" (\n  call \"%~dp0${SUB_CUSTOM}\" %1 %2 %3 \n)")
258   else()
259     SET (ADDITIONAL_CUSTOM_CONTENT "\nif [ -e \"\${aScriptPath}/${SUB_CUSTOM}\" ]; then\n  source \"\${aScriptPath}/${SUB_CUSTOM}\" \"\${COMPILER}\" \"\${WOKSTATION}\${ARCH}\" \"\${CASDEB}\" \nfi")
260   endif()
261
262   # change custom.bat/sh
263   if (EXISTS "${INSTALL_DIR}/custom.${SCRIPT_EXT}")
264     file (READ "${INSTALL_DIR}/custom.${SCRIPT_EXT}" CUSTOM_CONTENT)
265
266     set (CUSTOM_CONTENT "${CUSTOM_CONTENT} ${ADDITIONAL_CUSTOM_CONTENT}")
267
268     file (WRITE "${INSTALL_DIR}/custom.${SCRIPT_EXT}" "${CUSTOM_CONTENT}")
269   else()
270     OCCT_CONFIGURE_AND_INSTALL ("adm/templates/custom.${SCRIPT_EXT}.main" "custom.${SCRIPT_EXT}" "${INSTALL_DIR}")
271   endif()
272
273   # write current custom.bat/sh
274   OCCT_CONFIGURE_AND_INSTALL ("adm/templates/custom.${SCRIPT_EXT}.in" "${SUB_CUSTOM}" "${INSTALL_DIR}")
275
276   if (BUILD_MFC_SAMPLES)
277     OCCT_INSTALL_FILE_OR_DIR ("adm/templates/sample.bat" "${INSTALL_DIR}")
278   endif()
279
280   OCCT_CONFIGURE_AND_INSTALL ("adm/templates/env.${SCRIPT_EXT}.in" "env.${SCRIPT_EXT}" "${INSTALL_DIR}")
281 endif()
282
283 # RESOURCES
284 OCCT_INSTALL_FILE_OR_DIR ("src/DrawResources"          "${INSTALL_DIR}/src")
285 OCCT_INSTALL_FILE_OR_DIR ("src/StdResource"            "${INSTALL_DIR}/src")
286 OCCT_INSTALL_FILE_OR_DIR ("src/SHMessage"              "${INSTALL_DIR}/src")
287 OCCT_INSTALL_FILE_OR_DIR ("src/Textures"               "${INSTALL_DIR}/src")
288 OCCT_INSTALL_FILE_OR_DIR ("src/Shaders"                "${INSTALL_DIR}/src")
289 OCCT_INSTALL_FILE_OR_DIR ("src/XSMessage"              "${INSTALL_DIR}/src")
290 OCCT_INSTALL_FILE_OR_DIR ("src/XSTEPResource"          "${INSTALL_DIR}/src")
291 OCCT_INSTALL_FILE_OR_DIR ("src/XmlOcafResource"        "${INSTALL_DIR}/src")
292
293 OCCT_INSTALL_FILE_OR_DIR ("src/UnitsAPI/Lexi_Expr.dat" "${INSTALL_DIR}/src/UnitsAPI")
294 OCCT_INSTALL_FILE_OR_DIR ("src/UnitsAPI/Units.dat"     "${INSTALL_DIR}/src/UnitsAPI")
295 OCCT_INSTALL_FILE_OR_DIR ("src/TObj/TObj.msg"          "${INSTALL_DIR}/src/TObj")
296
297
298 #Toolkits uses variables: INSTALL_DIR, OS_WITH_BIT, COMPILER, BUILD_POSTFIX
299 OCCT_MAKE_OS_WITH_BITNESS()
300
301 # consider for patch existence
302 set (IS_PATCH_CURRENT "NO")
303 set (TK_ROOT_DIR ${CMAKE_SOURCE_DIR})
304 if (NOT "${BUILD_PATCH_DIR}" STREQUAL "")
305   set (IS_PATCH_CURRENT "YES")
306   set (TK_ROOT_DIR ${BUILD_PATCH_DIR})
307 endif()
308
309 # include patched toolkit projects or original ones
310 set (UNSUBDIRS "")
311 if (NOT "${BUILD_PATCH_DIR}" STREQUAL "" AND EXISTS "${BUILD_PATCH_DIR}/adm/cmake/occt_inc_toolkits.cmake")
312   set (TK_ROOT_DIR ${BUILD_PATCH_DIR})
313   include (${BUILD_PATCH_DIR}/adm/cmake/occt_inc_toolkits.cmake)
314 else()
315   set (IS_PATCH_CURRENT "NO")
316   set (TK_ROOT_DIR ${CMAKE_SOURCE_DIR})
317   include (adm/cmake/occt_inc_toolkits.cmake)
318 endif()
319
320 # include some required original occt_inc_toolkits
321 if (NOT "${UNSUBDIRS}" STREQUAL "")
322   set (IS_PATCH_CURRENT "NO")
323   # add required subdirs
324   foreach (UNSUBDIR ${UNSUBDIRS})
325     add_subdirectory (${CMAKE_SOURCE_DIR}/${UNSUBDIR})
326   endforeach()
327 endif()
328
329 # samples do not support patch usage
330 IF (BUILD_MFC_SAMPLES)
331   SET (OCCT_ROOT ${CMAKE_SOURCE_DIR})
332
333   SET (MFC_STANDARD_SAMPLES_DIR ${OCCT_ROOT}/samples/mfc/standard)
334   SET (COMMON_WINMAIN_FILE      ${MFC_STANDARD_SAMPLES_DIR}/Common/Winmain.cpp)
335
336   add_subdirectory(samples/mfc/standard/mfcsample)
337   add_subdirectory(samples/mfc/standard/01_Geometry)
338   add_subdirectory(samples/mfc/standard/02_Modeling)
339   add_subdirectory(samples/mfc/standard/03_Viewer2d)
340   add_subdirectory(samples/mfc/standard/04_Viewer3d)
341   add_subdirectory(samples/mfc/standard/05_ImportExport)
342   add_subdirectory(samples/mfc/standard/06_Ocaf)
343   add_subdirectory(samples/mfc/standard/07_Triangulation)
344   add_subdirectory(samples/mfc/standard/08_HLR)
345   add_subdirectory(samples/mfc/standard/09_Animation)
346   add_subdirectory(samples/mfc/standard/10_Convert)
347 ENDIF()