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