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