occt_toolkit.cmake 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. # script for each OCCT toolkit
  2. # filling some variables by default values(src) or using custom(tools, samples)
  3. set (RELATIVE_SOURCES_DIR "${RELATIVE_DIR}")
  4. if ("${RELATIVE_SOURCES_DIR}" STREQUAL "")
  5. #if it is not defined, use default directory
  6. set (RELATIVE_SOURCES_DIR "src")
  7. endif()
  8. set (OCC_MODULES_LIST "${MODULES_LIST}")
  9. if ("${OCC_MODULES_LIST}" STREQUAL "")
  10. set (OCC_MODULES_LIST ${OCCT_MODULES})
  11. endif()
  12. set (OCC_TARGET_FOLDER "${TARGET_FOLDER}")
  13. if ("${OCC_TARGET_FOLDER}" STREQUAL "")
  14. set (OCC_TARGET_FOLDER "Modules")
  15. endif()
  16. set (OCCT_TOOLKITS_NAME_SUFFIX "${TOOLKITS_NAME_SUFFIX}")
  17. if ("${OCCT_TOOLKITS_NAME_SUFFIX}" STREQUAL "")
  18. set (OCCT_TOOLKITS_NAME_SUFFIX "TOOLKITS")
  19. endif()
  20. # parse PACKAGES file
  21. FILE_TO_LIST ("${RELATIVE_SOURCES_DIR}/${PROJECT_NAME}/PACKAGES" USED_PACKAGES)
  22. if ("${USED_PACKAGES}" STREQUAL "")
  23. set (USED_PACKAGES ${PROJECT_NAME})
  24. endif()
  25. if (USE_QT)
  26. # Qt dependencies
  27. OCCT_INCLUDE_CMAKE_FILE (adm/cmake/qt_macro)
  28. FIND_QT_PACKAGE(PROJECT_LIBRARIES_DEBUG PROJECT_LIBRARIES_RELEASE PROJECT_INCLUDES)
  29. include_directories("${PROJECT_INCLUDES}")
  30. endif(USE_QT)
  31. set (PRECOMPILED_DEFS)
  32. if (NOT BUILD_SHARED_LIBS)
  33. list (APPEND PRECOMPILED_DEFS "-DOCCT_NO_PLUGINS")
  34. if (WIN32 AND NOT EXECUTABLE_PROJECT)
  35. list (APPEND PRECOMPILED_DEFS "-DOCCT_STATIC_BUILD")
  36. endif()
  37. endif()
  38. # Get all used packages from toolkit
  39. UNSET(RESOURCE_FILES)
  40. foreach (OCCT_PACKAGE ${USED_PACKAGES})
  41. #remove part after "/" in the OCCT_PACKAGE variable if exists
  42. string (FIND "${OCCT_PACKAGE}" "/" _index)
  43. if (_index GREATER -1)
  44. math (EXPR _index "${_index}")
  45. string (SUBSTRING "${OCCT_PACKAGE}" 0 ${_index} OCCT_PACKAGE_NAME)
  46. else()
  47. set (OCCT_PACKAGE_NAME "${OCCT_PACKAGE}")
  48. endif()
  49. if (WIN32)
  50. list (APPEND PRECOMPILED_DEFS "-D__${OCCT_PACKAGE_NAME}_DLL")
  51. endif()
  52. set (SOURCE_FILES)
  53. set (HEADER_FILES)
  54. # Generate Flex and Bison files
  55. if (${BUILD_YACCLEX})
  56. # flex files
  57. OCCT_ORIGIN_AND_PATCHED_FILES ("${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}" "*[.]lex" SOURCE_FILES_FLEX)
  58. list (LENGTH SOURCE_FILES_FLEX SOURCE_FILES_FLEX_LEN)
  59. # bison files
  60. OCCT_ORIGIN_AND_PATCHED_FILES ("${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}" "*[.]yacc" SOURCE_FILES_BISON)
  61. list (LENGTH SOURCE_FILES_BISON SOURCE_FILES_BISON_LEN)
  62. if (${SOURCE_FILES_FLEX_LEN} EQUAL ${SOURCE_FILES_BISON_LEN} AND NOT ${SOURCE_FILES_FLEX_LEN} EQUAL 0)
  63. list (SORT SOURCE_FILES_FLEX)
  64. list (SORT SOURCE_FILES_BISON)
  65. math (EXPR SOURCE_FILES_FLEX_LEN "${SOURCE_FILES_FLEX_LEN} - 1")
  66. foreach (FLEX_FILE_INDEX RANGE ${SOURCE_FILES_FLEX_LEN})
  67. list (GET SOURCE_FILES_FLEX ${FLEX_FILE_INDEX} CURRENT_FLEX_FILE)
  68. get_filename_component (CURRENT_FLEX_FILE_NAME ${CURRENT_FLEX_FILE} NAME_WE)
  69. list (GET SOURCE_FILES_BISON ${FLEX_FILE_INDEX} CURRENT_BISON_FILE)
  70. get_filename_component (CURRENT_BISON_FILE_NAME ${CURRENT_BISON_FILE} NAME_WE)
  71. string (COMPARE EQUAL ${CURRENT_FLEX_FILE_NAME} ${CURRENT_BISON_FILE_NAME} ARE_FILES_EQUAL)
  72. if (EXISTS "${CURRENT_FLEX_FILE}" AND EXISTS "${CURRENT_BISON_FILE}" AND ${ARE_FILES_EQUAL})
  73. # Note: files are generated in original source directory (not in patch!)
  74. set (FLEX_BISON_TARGET_DIR "${CMAKE_SOURCE_DIR}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}")
  75. # choose appropriate extension for generated files: "cxx" if source file contains
  76. # instruction to generate C++ code, "c" otherwise
  77. set (BISON_OUTPUT_FILE_EXT "c")
  78. set (FLEX_OUTPUT_FILE_EXT "c")
  79. file (STRINGS "${CURRENT_BISON_FILE}" FILE_BISON_CONTENT)
  80. foreach (FILE_BISON_CONTENT_LINE ${FILE_BISON_CONTENT})
  81. string (REGEX MATCH "%language \"C\\+\\+\"" CXX_BISON_LANGUAGE_FOUND ${FILE_BISON_CONTENT_LINE})
  82. if (CXX_BISON_LANGUAGE_FOUND)
  83. set (BISON_OUTPUT_FILE_EXT "cxx")
  84. endif()
  85. endforeach()
  86. file (STRINGS "${CURRENT_FLEX_FILE}" FILE_FLEX_CONTENT)
  87. foreach (FILE_FLEX_CONTENT_LINE ${FILE_FLEX_CONTENT})
  88. string (REGEX MATCH "%option c\\+\\+" CXX_FLEX_LANGUAGE_FOUND ${FILE_FLEX_CONTENT_LINE})
  89. if (CXX_FLEX_LANGUAGE_FOUND)
  90. set (FLEX_OUTPUT_FILE_EXT "cxx")
  91. # install copy of FlexLexer.h locally to allow further building without flex
  92. if (FLEX_INCLUDE_DIR AND EXISTS "${FLEX_INCLUDE_DIR}/FlexLexer.h")
  93. configure_file("${FLEX_INCLUDE_DIR}/FlexLexer.h" "${FLEX_BISON_TARGET_DIR}/FlexLexer.h" @ONLY NEWLINE_STYLE LF)
  94. endif()
  95. endif()
  96. endforeach()
  97. set (BISON_OUTPUT_FILE ${CURRENT_BISON_FILE_NAME}.tab.${BISON_OUTPUT_FILE_EXT})
  98. set (FLEX_OUTPUT_FILE lex.${CURRENT_FLEX_FILE_NAME}.${FLEX_OUTPUT_FILE_EXT})
  99. BISON_TARGET (Parser_${CURRENT_BISON_FILE_NAME} ${CURRENT_BISON_FILE} "${FLEX_BISON_TARGET_DIR}/${BISON_OUTPUT_FILE}"
  100. COMPILE_FLAGS "-p ${CURRENT_BISON_FILE_NAME} -l -M ${CMAKE_SOURCE_DIR}/${RELATIVE_SOURCES_DIR}/=")
  101. FLEX_TARGET (Scanner_${CURRENT_FLEX_FILE_NAME} ${CURRENT_FLEX_FILE} "${FLEX_BISON_TARGET_DIR}/${FLEX_OUTPUT_FILE}"
  102. COMPILE_FLAGS "-P${CURRENT_FLEX_FILE_NAME} -L")
  103. ADD_FLEX_BISON_DEPENDENCY (Scanner_${CURRENT_FLEX_FILE_NAME} Parser_${CURRENT_BISON_FILE_NAME})
  104. list (APPEND SOURCE_FILES ${BISON_OUTPUT_FILE} ${FLEX_OUTPUT_FILE})
  105. endif()
  106. endforeach()
  107. endif()
  108. endif()
  109. # header files
  110. if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/FILES")
  111. file (STRINGS "${BUILD_PATCH}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/FILES" HEADER_FILES_M REGEX ".+[.]h")
  112. file (STRINGS "${BUILD_PATCH}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/FILES" HEADER_FILES_LXX REGEX ".+[.]lxx")
  113. file (STRINGS "${BUILD_PATCH}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/FILES" HEADER_FILES_GXX REGEX ".+[.]gxx")
  114. file (STRINGS "${BUILD_PATCH}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/FILES" SOURCE_FILES_C REGEX ".+[.]c")
  115. if(APPLE)
  116. file (STRINGS "${BUILD_PATCH}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/FILES" SOURCE_FILES_M REGEX ".+[.]mm")
  117. endif()
  118. else()
  119. file (STRINGS "${CMAKE_SOURCE_DIR}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/FILES" HEADER_FILES_M REGEX ".+[.]h")
  120. file (STRINGS "${CMAKE_SOURCE_DIR}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/FILES" HEADER_FILES_LXX REGEX ".+[.]lxx")
  121. file (STRINGS "${CMAKE_SOURCE_DIR}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/FILES" HEADER_FILES_GXX REGEX ".+[.]gxx")
  122. file (STRINGS "${CMAKE_SOURCE_DIR}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/FILES" SOURCE_FILES_C REGEX ".+[.]c")
  123. if(APPLE)
  124. file (STRINGS "${CMAKE_SOURCE_DIR}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/FILES" SOURCE_FILES_M REGEX ".+[.]mm")
  125. endif()
  126. endif()
  127. list (APPEND HEADER_FILES ${HEADER_FILES_M} ${HEADER_FILES_LXX} ${SOURCE_FILES_GXX})
  128. list (APPEND SOURCE_FILES ${SOURCE_FILES_C})
  129. if(APPLE)
  130. list (APPEND SOURCE_FILES ${SOURCE_FILES_M})
  131. endif()
  132. foreach(HEADER_FILE ${HEADER_FILES})
  133. if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/${HEADER_FILE}")
  134. message (STATUS "Info: consider patched file: ${BUILD_PATCH}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/${HEADER_FILE}")
  135. list (APPEND USED_INCFILES "${BUILD_PATCH}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/${HEADER_FILE}")
  136. SOURCE_GROUP ("Header Files\\${OCCT_PACKAGE_NAME}" FILES "${BUILD_PATCH}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/${HEADER_FILE}")
  137. else()
  138. list (APPEND USED_INCFILES "${CMAKE_SOURCE_DIR}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/${HEADER_FILE}")
  139. SOURCE_GROUP ("Header Files\\${OCCT_PACKAGE_NAME}" FILES "${CMAKE_SOURCE_DIR}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/${HEADER_FILE}")
  140. endif()
  141. endforeach()
  142. foreach(SOURCE_FILE ${SOURCE_FILES})
  143. if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/${SOURCE_FILE}")
  144. message (STATUS "Info: consider patched file: ${BUILD_PATCH}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/${SOURCE_FILE}")
  145. list (APPEND USED_SRCFILES "${BUILD_PATCH}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/${SOURCE_FILE}")
  146. SOURCE_GROUP ("Source Files\\${OCCT_PACKAGE_NAME}" FILES "${BUILD_PATCH}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/${SOURCE_FILE}")
  147. else()
  148. list (APPEND USED_SRCFILES "${CMAKE_SOURCE_DIR}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/${SOURCE_FILE}")
  149. SOURCE_GROUP ("Source Files\\${OCCT_PACKAGE_NAME}" FILES "${CMAKE_SOURCE_DIR}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/${SOURCE_FILE}")
  150. endif()
  151. endforeach()
  152. if (USE_QT)
  153. FIND_AND_INSTALL_QT_RESOURCES (${OCCT_PACKAGE} RESOURCE_FILES)
  154. #message("Qt Resource files are: ${QT_RESOURCE_FILES} in ${OCCT_PACKAGE}")
  155. endif(USE_QT)
  156. #message("Resource files are: ${RESOURCE_FILES} in ${OCCT_PACKAGE}")
  157. foreach(RESOURCE_FILE ${RESOURCE_FILES})
  158. SOURCE_GROUP ("Resource Files\\${OCCT_PACKAGE_NAME}" FILES "${RESOURCE_FILE}")
  159. endforeach()
  160. endforeach()
  161. string (REGEX REPLACE ";" " " PRECOMPILED_DEFS "${PRECOMPILED_DEFS}")
  162. set (USED_RCFILE "")
  163. if (MSVC)
  164. set (USED_RCFILE "${CMAKE_BINARY_DIR}/resources/${PROJECT_NAME}.rc")
  165. if (APPLY_OCCT_PATCH_DIR AND EXISTS "${APPLY_OCCT_PATCH_DIR}/adm/templates/occt_toolkit.rc.in")
  166. configure_file("${APPLY_OCCT_PATCH_DIR}/adm/templates/occt_toolkit.rc.in" "${USED_RCFILE}" @ONLY)
  167. else()
  168. configure_file("${CMAKE_SOURCE_DIR}/adm/templates/occt_toolkit.rc.in" "${USED_RCFILE}" @ONLY)
  169. endif()
  170. endif()
  171. set (CURRENT_MODULE)
  172. foreach (OCCT_MODULE ${OCC_MODULES_LIST})
  173. list (FIND ${OCCT_MODULE}_${OCCT_TOOLKITS_NAME_SUFFIX} ${PROJECT_NAME} CURRENT_PROJECT_IS_BUILT)
  174. if (NOT ${CURRENT_PROJECT_IS_BUILT} EQUAL -1)
  175. set (CURRENT_MODULE ${OCCT_MODULE})
  176. endif()
  177. endforeach()
  178. if (MSVC)
  179. OCCT_INSERT_CODE_FOR_TARGET ()
  180. endif()
  181. if (USE_QT)
  182. FIND_AND_WRAP_MOC_FILES("${USED_INCFILES}" "${PROJECT_NAME}_MOC_FILES")
  183. #message("MOC files: ${${PROJECT_NAME}_MOC_FILES}")
  184. endif (USE_QT)
  185. if (EXECUTABLE_PROJECT)
  186. add_executable (${PROJECT_NAME} ${USED_SRCFILES} ${USED_INCFILES} ${USED_RCFILE} ${RESOURCE_FILES} ${${PROJECT_NAME}_MOC_FILES})
  187. install (TARGETS ${PROJECT_NAME}
  188. DESTINATION "${INSTALL_DIR_BIN}\${OCCT_INSTALL_BIN_LETTER}")
  189. if (EMSCRIPTEN)
  190. install(FILES ${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/bin\${OCCT_INSTALL_BIN_LETTER}/${PROJECT_NAME}.wasm DESTINATION "${INSTALL_DIR_BIN}/${OCCT_INSTALL_BIN_LETTER}")
  191. endif()
  192. else()
  193. add_library (${PROJECT_NAME} ${USED_SRCFILES} ${USED_INCFILES} ${USED_RCFILE} ${RESOURCE_FILES} ${${PROJECT_NAME}_MOC_FILES})
  194. if (MSVC)
  195. if (BUILD_FORCE_RelWithDebInfo)
  196. set (aReleasePdbConf "Release")
  197. else()
  198. set (aReleasePdbConf)
  199. endif()
  200. # install (FILES ${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/bin\${OCCT_INSTALL_BIN_LETTER}/${PROJECT_NAME}.pdb
  201. # CONFIGURATIONS Debug ${aReleasePdbConf} RelWithDebInfo
  202. # DESTINATION "${INSTALL_DIR_BIN}\${OCCT_INSTALL_BIN_LETTER}")
  203. endif()
  204. if (BUILD_SHARED_LIBS AND NOT "${BUILD_SHARED_LIBRARY_NAME_POSTFIX}" STREQUAL "")
  205. set (CMAKE_SHARED_LIBRARY_SUFFIX_DEFAULT ${CMAKE_SHARED_LIBRARY_SUFFIX})
  206. set (CMAKE_SHARED_LIBRARY_SUFFIX "${BUILD_SHARED_LIBRARY_NAME_POSTFIX}${CMAKE_SHARED_LIBRARY_SUFFIX}")
  207. endif()
  208. install (TARGETS ${PROJECT_NAME}
  209. EXPORT OpenCASCADE${CURRENT_MODULE}Targets
  210. RUNTIME DESTINATION "${INSTALL_DIR_BIN}\${OCCT_INSTALL_BIN_LETTER}"
  211. ARCHIVE DESTINATION "${INSTALL_DIR_LIB}\${OCCT_INSTALL_BIN_LETTER}"
  212. LIBRARY DESTINATION "${INSTALL_DIR_LIB}\${OCCT_INSTALL_BIN_LETTER}")
  213. if (NOT WIN32)
  214. if (BUILD_SHARED_LIBS AND NOT "${BUILD_SHARED_LIBRARY_NAME_POSTFIX}" STREQUAL "")
  215. set (LINK_NAME "${INSTALL_DIR}/${INSTALL_DIR_LIB}\${OCCT_INSTALL_BIN_LETTER}/lib${PROJECT_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX_DEFAULT}")
  216. set (LIBRARY_NAME "${INSTALL_DIR}/${INSTALL_DIR_LIB}\${OCCT_INSTALL_BIN_LETTER}/lib${PROJECT_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}")
  217. OCCT_CREATE_SYMLINK_TO_FILE (${LIBRARY_NAME} ${LINK_NAME})
  218. endif()
  219. endif()
  220. endif()
  221. if (CURRENT_MODULE)
  222. set_target_properties (${PROJECT_NAME} PROPERTIES FOLDER "${OCC_TARGET_FOLDER}/${CURRENT_MODULE}")
  223. set_target_properties (${PROJECT_NAME} PROPERTIES MODULE "${CURRENT_MODULE}")
  224. if (APPLE)
  225. if (NOT "${INSTALL_NAME_DIR}" STREQUAL "")
  226. set_target_properties (${PROJECT_NAME} PROPERTIES BUILD_WITH_INSTALL_RPATH 1 INSTALL_NAME_DIR "${INSTALL_NAME_DIR}")
  227. endif()
  228. endif()
  229. endif()
  230. get_property (OCC_VERSION_MAJOR GLOBAL PROPERTY OCC_VERSION_MAJOR)
  231. get_property (OCC_VERSION_MINOR GLOBAL PROPERTY OCC_VERSION_MINOR)
  232. get_property (OCC_VERSION_MAINTENANCE GLOBAL PROPERTY OCC_VERSION_MAINTENANCE)
  233. if (ANDROID)
  234. # do not append version to the filename
  235. set_target_properties (${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "${PRECOMPILED_DEFS}")
  236. else()
  237. set_target_properties (${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "${PRECOMPILED_DEFS}"
  238. SOVERSION "${OCC_VERSION_MAJOR}"
  239. VERSION "${OCC_VERSION_MAJOR}.${OCC_VERSION_MINOR}.${OCC_VERSION_MAINTENANCE}")
  240. endif()
  241. set (USED_TOOLKITS_BY_CURRENT_PROJECT)
  242. set (USED_EXTERNAL_LIBS_BY_CURRENT_PROJECT)
  243. # parse EXTERNLIB file
  244. if (CUSTOM_EXTERNLIB)
  245. set (USED_EXTERNLIB_AND_TOOLKITS ${CUSTOM_EXTERNLIB})
  246. else()
  247. FILE_TO_LIST ("${RELATIVE_SOURCES_DIR}/${PROJECT_NAME}/EXTERNLIB" USED_EXTERNLIB_AND_TOOLKITS)
  248. endif()
  249. foreach (USED_ITEM ${USED_EXTERNLIB_AND_TOOLKITS})
  250. string (REGEX MATCH "^ *#" COMMENT_FOUND ${USED_ITEM})
  251. if (NOT COMMENT_FOUND)
  252. string (REGEX MATCH "^TK" TK_FOUND ${USED_ITEM})
  253. string (REGEX MATCH "^vtk" VTK_FOUND ${USED_ITEM})
  254. if (NOT "${TK_FOUND}" STREQUAL "" OR NOT "${VTK_FOUND}" STREQUAL "")
  255. list (APPEND USED_TOOLKITS_BY_CURRENT_PROJECT ${USED_ITEM})
  256. if (NOT "${VTK_FOUND}" STREQUAL "" AND BUILD_SHARED_LIBS AND INSTALL_VTK AND COMMAND OCCT_INSTALL_VTK)
  257. OCCT_INSTALL_VTK(${USED_ITEM})
  258. endif()
  259. else()
  260. string (REGEX MATCH "^CSF_" CSF_FOUND ${USED_ITEM})
  261. if ("${CSF_FOUND}" STREQUAL "")
  262. message (STATUS "Info: ${USED_ITEM} from ${PROJECT_NAME} skipped due to it is empty")
  263. else() # get CSF_ value
  264. set (CURRENT_CSF ${${USED_ITEM}})
  265. if (NOT "x${CURRENT_CSF}" STREQUAL "x")
  266. if ("${CURRENT_CSF}" STREQUAL "CSF_OpenGlLibs")
  267. add_definitions (-DHAVE_OPENGL)
  268. endif()
  269. if ("${CURRENT_CSF}" STREQUAL "CSF_OpenGlesLibs")
  270. add_definitions (-DHAVE_GLES2)
  271. endif()
  272. set (LIBRARY_FROM_CACHE 0)
  273. separate_arguments (CURRENT_CSF)
  274. foreach (CSF_LIBRARY ${CURRENT_CSF})
  275. string (TOLOWER "${CSF_LIBRARY}" CSF_LIBRARY)
  276. string (REPLACE "+" "[+]" CSF_LIBRARY "${CSF_LIBRARY}")
  277. string (REPLACE "." "" CSF_LIBRARY "${CSF_LIBRARY}")
  278. get_cmake_property(ALL_CACHE_VARIABLES CACHE_VARIABLES)
  279. string (REGEX MATCHALL "(^|;)3RDPARTY_[^;]+_LIBRARY[^;]*" ALL_CACHE_VARIABLES "${ALL_CACHE_VARIABLES}")
  280. foreach (CACHE_VARIABLE ${ALL_CACHE_VARIABLES})
  281. set (CURRENT_CACHE_LIBRARY ${${CACHE_VARIABLE}})
  282. string (TOLOWER "${CACHE_VARIABLE}" CACHE_VARIABLE)
  283. if (EXISTS "${CURRENT_CACHE_LIBRARY}" AND NOT IS_DIRECTORY "${CURRENT_CACHE_LIBRARY}")
  284. string (REGEX MATCH "_${CSF_LIBRARY}$" IS_ENDING "${CACHE_VARIABLE}")
  285. string (REGEX MATCH "^([a-z]+)" CSF_WO_VERSION "${CSF_LIBRARY}")
  286. string (REGEX MATCH "_${CSF_WO_VERSION}$" IS_ENDING_WO_VERSION "${CACHE_VARIABLE}")
  287. if ("3rdparty_${CSF_LIBRARY}_library" STREQUAL "${CACHE_VARIABLE}" OR
  288. "3rdparty_${CSF_WO_VERSION}_library" STREQUAL "${CACHE_VARIABLE}" OR
  289. NOT "x${IS_ENDING}" STREQUAL "x" OR
  290. NOT "x${IS_ENDING_WO_VERSION}" STREQUAL "x")
  291. list (APPEND USED_EXTERNAL_LIBS_BY_CURRENT_PROJECT "${CURRENT_CACHE_LIBRARY}")
  292. set (LIBRARY_FROM_CACHE 1)
  293. endif()
  294. endif()
  295. endforeach()
  296. endforeach()
  297. if (NOT ${LIBRARY_FROM_CACHE})
  298. # prepare a list from a string with whitespaces
  299. separate_arguments (CURRENT_CSF)
  300. list (APPEND USED_EXTERNAL_LIBS_BY_CURRENT_PROJECT ${CURRENT_CSF})
  301. endif()
  302. endif()
  303. endif()
  304. endif()
  305. endif()
  306. endforeach()
  307. if (APPLE)
  308. list (FIND USED_EXTERNAL_LIBS_BY_CURRENT_PROJECT X11 IS_X11_FOUND)
  309. if (NOT ${IS_X11_FOUND} EQUAL -1)
  310. find_package (X11 COMPONENTS X11)
  311. if (NOT X11_FOUND)
  312. message (STATUS "Warning: X11 is not found. It's required to install The XQuartz project: http://www.xquartz.org")
  313. endif()
  314. endif()
  315. endif()
  316. # Update list of used VTK libraries if OpenGL2 Rendering BackEnd is used.
  317. # Add VTK_OPENGL2_BACKEND definition.
  318. if("${VTK_RENDERING_BACKEND}" STREQUAL "OpenGL2" OR IS_VTK_9XX)
  319. add_definitions(-DVTK_OPENGL2_BACKEND)
  320. foreach (VTK_EXCLUDE_LIBRARY vtkRenderingOpenGL vtkRenderingFreeTypeOpenGL)
  321. list (FIND USED_TOOLKITS_BY_CURRENT_PROJECT "${VTK_EXCLUDE_LIBRARY}" IS_VTK_OPENGL_FOUND)
  322. if (NOT ${IS_VTK_OPENGL_FOUND} EQUAL -1)
  323. list (REMOVE_ITEM USED_TOOLKITS_BY_CURRENT_PROJECT ${VTK_EXCLUDE_LIBRARY})
  324. if (${VTK_EXCLUDE_LIBRARY} STREQUAL vtkRenderingOpenGL)
  325. list (APPEND USED_TOOLKITS_BY_CURRENT_PROJECT vtkRenderingOpenGL2)
  326. if(VTK_MAJOR_VERSION GREATER 6)
  327. list (APPEND USED_TOOLKITS_BY_CURRENT_PROJECT vtkRenderingGL2PSOpenGL2)
  328. endif()
  329. endif()
  330. endif()
  331. endforeach()
  332. else()
  333. if(VTK_MAJOR_VERSION EQUAL 6 AND VTK_MINOR_VERSION GREATER 2 OR VTK_MAJOR_VERSION GREATER 6)
  334. list (FIND USED_TOOLKITS_BY_CURRENT_PROJECT "vtkRenderingFreeTypeOpenGL" IS_VTK_RENDER_FREETYPE_FOUND)
  335. if (NOT ${IS_VTK_RENDER_FREETYPE_FOUND} EQUAL -1)
  336. list (REMOVE_ITEM USED_TOOLKITS_BY_CURRENT_PROJECT "vtkRenderingFreeTypeOpenGL")
  337. endif()
  338. endif()
  339. endif()
  340. if (BUILD_SHARED_LIBS OR EXECUTABLE_PROJECT)
  341. if(IS_VTK_9XX)
  342. string (REGEX REPLACE "vtk" "VTK::" USED_TOOLKITS_BY_CURRENT_PROJECT "${USED_TOOLKITS_BY_CURRENT_PROJECT}")
  343. endif()
  344. target_link_libraries (${PROJECT_NAME} ${USED_TOOLKITS_BY_CURRENT_PROJECT} ${USED_EXTERNAL_LIBS_BY_CURRENT_PROJECT})
  345. endif()
  346. if (USE_QT)
  347. foreach (PROJECT_LIBRARY_DEBUG ${PROJECT_LIBRARIES_DEBUG})
  348. target_link_libraries (${PROJECT_NAME} debug ${PROJECT_LIBRARY_DEBUG})
  349. endforeach()
  350. foreach (PROJECT_LIBRARY_RELEASE ${PROJECT_LIBRARIES_RELEASE})
  351. target_link_libraries (${PROJECT_NAME} optimized ${PROJECT_LIBRARY_RELEASE})
  352. endforeach()
  353. endif()
  354. # suppress deprecation warnings inside OCCT itself for old gcc versions with unavailable Standard_DISABLE_DEPRECATION_WARNINGS
  355. if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
  356. if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.6.0)
  357. add_definitions("-DOCCT_NO_DEPRECATED")
  358. message (STATUS "Warning: internal deprecation warnings by Standard_DEPRECATED have been disabled due to old gcc version being used")
  359. endif()
  360. endif()
  361. # use Cotire to accelerate build via usage of precompiled headers
  362. if (BUILD_USE_PCH)
  363. if (WIN32)
  364. # prevent definition of min and max macros through inclusion of Windows.h
  365. # (for cotire builds)
  366. add_definitions("-DNOMINMAX")
  367. # avoid warnings on deprecated names from standard C library (see strsafe.h)
  368. add_definitions("-DSTRSAFE_NO_DEPRECATE")
  369. # avoid "std::Equal1" warning in QANCollection_Stl.cxx in debug mode
  370. # suggesting using msvc "Checked Iterators"
  371. add_definitions("-D_SCL_SECURE_NO_WARNINGS")
  372. endif()
  373. # Exclude system-provided glext.h.
  374. # These macros are already defined within OpenGl_GlFunctions.hxx,
  375. # however we have to duplicate them here for building TKOpenGl with PCH.
  376. add_definitions("-DGL_GLEXT_LEGACY")
  377. add_definitions("-DGLX_GLXEXT_LEGACY")
  378. # workaround for old gcc
  379. if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
  380. add_definitions("-D__STDC_CONSTANT_MACROS")
  381. add_definitions("-D__STDC_FORMAT_MACROS")
  382. endif()
  383. # unity builds are not used since they do not add speed but cause conflicts
  384. # in TKV3d
  385. set_target_properties(${PROJECT_NAME} PROPERTIES COTIRE_ADD_UNITY_BUILD FALSE)
  386. cotire(${PROJECT_NAME})
  387. endif()