0025812: Replace dynamic loading mechanism of OCAF persistence with dynamic-link one
[occt.git] / adm / cmake / occt_toolkit.cmake
CommitLineData
316d77d9 1# script for each OCCT toolkit
2
fb3267c7 3# parce PACKAGES file
4if ("${PROJECT_NAME}" STREQUAL DRAWEXE)
5 set (USED_PACKAGES DRAWEXE)
6else()
7 FILE_TO_LIST ("src/${PROJECT_NAME}/PACKAGES" USED_PACKAGES)
8endif()
9
10set (PRECOMPILED_DEFS)
11
316d77d9 12# Get all used packages from toolkit
fb3267c7 13foreach (OCCT_PACKAGE ${USED_PACKAGES})
14
15 # TKService contains platform-dependent packages: Xw and WNT
16 if ((WIN32 AND "${OCCT_PACKAGE}" STREQUAL "Xw") OR (NOT WIN32 AND "${OCCT_PACKAGE}" STREQUAL "WNT"))
e713baee 17 # do nothing
18 else()
316d77d9 19
e713baee 20 if (WIN32)
21 list (APPEND PRECOMPILED_DEFS "-D__${OCCT_PACKAGE}_DLL")
22 endif()
316d77d9 23
e713baee 24 set (SOURCE_FILES)
25 set (HEADER_FILES)
26
27 # Generate Flex and Bison files
109aa56e 28 if (${BUILD_YACCLEX})
e713baee 29
30 # flex files
31 OCCT_ORIGIN_AND_PATCHED_FILES ("src/${OCCT_PACKAGE}" "*[.]lex" SOURCE_FILES_FLEX)
32 list (LENGTH SOURCE_FILES_FLEX SOURCE_FILES_FLEX_LEN)
33
34 # bison files
35 OCCT_ORIGIN_AND_PATCHED_FILES ("src/${OCCT_PACKAGE}" "*[.]yacc" SOURCE_FILES_BISON)
36 list (LENGTH SOURCE_FILES_BISON SOURCE_FILES_BISON_LEN)
37
38 if (${SOURCE_FILES_FLEX_LEN} EQUAL ${SOURCE_FILES_BISON_LEN} AND NOT ${SOURCE_FILES_FLEX_LEN} EQUAL 0)
39
40 list (SORT SOURCE_FILES_FLEX)
41 list (SORT SOURCE_FILES_BISON)
42
43 math (EXPR SOURCE_FILES_FLEX_LEN "${SOURCE_FILES_FLEX_LEN} - 1")
44 foreach (FLEX_FILE_INDEX RANGE ${SOURCE_FILES_FLEX_LEN})
45
46 list (GET SOURCE_FILES_FLEX ${FLEX_FILE_INDEX} CURRENT_FLEX_FILE)
47 get_filename_component (CURRENT_FLEX_FILE_NAME ${CURRENT_FLEX_FILE} NAME_WE)
48
49 list (GET SOURCE_FILES_BISON ${FLEX_FILE_INDEX} CURRENT_BISON_FILE)
50 get_filename_component (CURRENT_BISON_FILE_NAME ${CURRENT_BISON_FILE} NAME_WE)
51
52 string (COMPARE EQUAL ${CURRENT_FLEX_FILE_NAME} ${CURRENT_BISON_FILE_NAME} ARE_FILES_EQUAL)
53
54 if (EXISTS "${CURRENT_FLEX_FILE}" AND EXISTS "${CURRENT_BISON_FILE}" AND ${ARE_FILES_EQUAL})
55 set (BISON_OUTPUT_FILE ${CURRENT_BISON_FILE_NAME}.tab.c)
56 set (FLEX_OUTPUT_FILE lex.${CURRENT_FLEX_FILE_NAME}.c)
57 BISON_TARGET (Parser_${CURRENT_BISON_FILE_NAME} ${CURRENT_BISON_FILE} ${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}/${BISON_OUTPUT_FILE} COMPILE_FLAGS "-p ${CURRENT_BISON_FILE_NAME}")
58 FLEX_TARGET (Scanner_${CURRENT_FLEX_FILE_NAME} ${CURRENT_FLEX_FILE} ${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}/${FLEX_OUTPUT_FILE} COMPILE_FLAGS "-P${CURRENT_FLEX_FILE_NAME}")
59 ADD_FLEX_BISON_DEPENDENCY (Scanner_${CURRENT_FLEX_FILE_NAME} Parser_${CURRENT_BISON_FILE_NAME})
60
61 list (APPEND SOURCE_FILES ${BISON_OUTPUT_FILE} ${FLEX_OUTPUT_FILE})
62 endif()
63 endforeach()
64 endif()
65 endif()
316d77d9 66
e713baee 67 # header files
109aa56e 68 if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/src/${OCCT_PACKAGE}/FILES")
69 file (STRINGS "${BUILD_PATCH}/src/${OCCT_PACKAGE}/FILES" HEADER_FILES_M REGEX ".+[.]h")
70 file (STRINGS "${BUILD_PATCH}/src/${OCCT_PACKAGE}/FILES" HEADER_FILES_LXX REGEX ".+[.]lxx")
71 file (STRINGS "${BUILD_PATCH}/src/${OCCT_PACKAGE}/FILES" HEADER_FILES_GXX REGEX ".+[.]gxx")
316d77d9 72
109aa56e 73 file (STRINGS "${BUILD_PATCH}/src/${OCCT_PACKAGE}/FILES" SOURCE_FILES_C REGEX ".+[.]c")
e713baee 74 if(APPLE)
109aa56e 75 file (STRINGS "${BUILD_PATCH}/src/${OCCT_PACKAGE}/FILES" SOURCE_FILES_M REGEX ".+[.]mm")
e713baee 76 endif()
77 else()
78 file (STRINGS "${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}/FILES" HEADER_FILES_M REGEX ".+[.]h")
79 file (STRINGS "${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}/FILES" HEADER_FILES_LXX REGEX ".+[.]lxx")
80 file (STRINGS "${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}/FILES" HEADER_FILES_GXX REGEX ".+[.]gxx")
316d77d9 81
e713baee 82 file (STRINGS "${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}/FILES" SOURCE_FILES_C REGEX ".+[.]c")
83 if(APPLE)
84 file (STRINGS "${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}/FILES" SOURCE_FILES_M REGEX ".+[.]mm")
85 endif()
316d77d9 86 endif()
e713baee 87
88 list (APPEND HEADER_FILES ${HEADER_FILES_M} ${HEADER_FILES_LXX} ${SOURCE_FILES_GXX})
89 list (APPEND SOURCE_FILES ${SOURCE_FILES_C})
f2e9c853 90 if(APPLE)
e713baee 91 list (APPEND SOURCE_FILES ${SOURCE_FILES_M})
f2e9c853 92 endif()
f2e9c853 93
e713baee 94 foreach(HEADER_FILE ${HEADER_FILES})
109aa56e 95 if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/src/${OCCT_PACKAGE}/${HEADER_FILE}")
96 message (STATUS "Info: consider patched file: ${BUILD_PATCH}/src/${OCCT_PACKAGE}/${HEADER_FILE}")
97 list (APPEND USED_INCFILES "${BUILD_PATCH}/src/${OCCT_PACKAGE}/${HEADER_FILE}")
98 SOURCE_GROUP ("Header Files\\${OCCT_PACKAGE}" FILES "${BUILD_PATCH}/src/${OCCT_PACKAGE}/${HEADER_FILE}")
e713baee 99 else()
100 list (APPEND USED_INCFILES "${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}/${HEADER_FILE}")
101 SOURCE_GROUP ("Header Files\\${OCCT_PACKAGE}" FILES "${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}/${HEADER_FILE}")
102 endif()
103 endforeach()
104
105 foreach(SOURCE_FILE ${SOURCE_FILES})
109aa56e 106 if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/src/${OCCT_PACKAGE}/${SOURCE_FILE}")
107 message (STATUS "Info: consider patched file: ${BUILD_PATCH}/src/${OCCT_PACKAGE}/${SOURCE_FILE}")
108 list (APPEND USED_SRCFILES "${BUILD_PATCH}/src/${OCCT_PACKAGE}/${SOURCE_FILE}")
109 SOURCE_GROUP ("Source Files\\${OCCT_PACKAGE}" FILES "${BUILD_PATCH}/src/${OCCT_PACKAGE}/${SOURCE_FILE}")
e713baee 110 else()
111 list (APPEND USED_SRCFILES "${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}/${SOURCE_FILE}")
112 SOURCE_GROUP ("Source Files\\${OCCT_PACKAGE}" FILES "${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}/${SOURCE_FILE}")
113 endif()
114 endforeach()
316d77d9 115 endif()
316d77d9 116endforeach()
f2e9c853 117string (REGEX REPLACE ";" " " PRECOMPILED_DEFS "${PRECOMPILED_DEFS}")
118
dfadf641 119set (USED_RCFILE "")
120if (MSVC)
121 set (USED_RCFILE "${CMAKE_BINARY_DIR}/resources/${PROJECT_NAME}.rc")
122
123 if (APPLY_OCCT_PATCH_DIR AND EXISTS "${APPLY_OCCT_PATCH_DIR}/adm/templates/occt_toolkit.rc.in")
124 configure_file("${APPLY_OCCT_PATCH_DIR}/adm/templates/occt_toolkit.rc.in" "${USED_RCFILE}" @ONLY)
125 else()
126 configure_file("${CMAKE_SOURCE_DIR}/adm/templates/occt_toolkit.rc.in" "${USED_RCFILE}" @ONLY)
127 endif()
128endif()
129
ada9ef40 130set (CURRENT_MODULE)
131foreach (OCCT_MODULE ${OCCT_MODULES})
132 list (FIND ${OCCT_MODULE}_TOOLKITS ${PROJECT_NAME} CURRENT_PROJECT_IS_BUILT)
133 if (NOT ${CURRENT_PROJECT_IS_BUILT} EQUAL -1)
134 set (CURRENT_MODULE ${OCCT_MODULE})
135 endif()
136endforeach()
137
138if (NOT SINGLE_GENERATOR)
139 OCCT_INSERT_CODE_FOR_TARGET ()
140endif()
141
fb3267c7 142if ("${PROJECT_NAME}" STREQUAL "DRAWEXE")
dfadf641 143 add_executable (${PROJECT_NAME} ${USED_SRCFILES} ${USED_INCFILES} ${USED_RCFILE})
fb3267c7 144
ada9ef40 145 install (TARGETS ${PROJECT_NAME}
146 DESTINATION "${INSTALL_DIR}/${INSTALL_DIR_BIN}\${OCCT_INSTALL_BIN_LETTER}")
fb3267c7 147else()
dfadf641 148 add_library (${PROJECT_NAME} ${USED_SRCFILES} ${USED_INCFILES} ${USED_RCFILE})
fb3267c7 149
ada9ef40 150 if (MSVC)
151 install (FILES ${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/bind/${PROJECT_NAME}.pdb
fb3267c7 152 CONFIGURATIONS Debug
ada9ef40 153 DESTINATION "${INSTALL_DIR}/${INSTALL_DIR_BIN}\${OCCT_INSTALL_BIN_LETTER}")
fb3267c7 154 endif()
46bd680a 155
156 if (BUILD_SHARED_LIBS AND NOT "${BUILD_SHARED_LIBRARY_NAME_POSTFIX}" STREQUAL "")
157 set (CMAKE_SHARED_LIBRARY_SUFFIX_DEFAULT ${CMAKE_SHARED_LIBRARY_SUFFIX})
158 set (CMAKE_SHARED_LIBRARY_SUFFIX "${BUILD_SHARED_LIBRARY_NAME_POSTFIX}${CMAKE_SHARED_LIBRARY_SUFFIX}")
159 endif()
160
ada9ef40 161 install (TARGETS ${PROJECT_NAME}
162 EXPORT OpenCASCADE${CURRENT_MODULE}Targets
163 RUNTIME DESTINATION "${INSTALL_DIR_BIN}\${OCCT_INSTALL_BIN_LETTER}"
164 ARCHIVE DESTINATION "${INSTALL_DIR_LIB}\${OCCT_INSTALL_BIN_LETTER}"
165 LIBRARY DESTINATION "${INSTALL_DIR_LIB}\${OCCT_INSTALL_BIN_LETTER}")
46bd680a 166
167 if (NOT WIN32)
168 if (BUILD_SHARED_LIBS AND NOT "${BUILD_SHARED_LIBRARY_NAME_POSTFIX}" STREQUAL "")
169 set (LINK_NAME "${INSTALL_DIR}/${INSTALL_DIR_LIB}\${OCCT_INSTALL_BIN_LETTER}/lib${PROJECT_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX_DEFAULT}")
170 set (LIBRARY_NAME "${INSTALL_DIR}/${INSTALL_DIR_LIB}\${OCCT_INSTALL_BIN_LETTER}/lib${PROJECT_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}")
171 OCCT_CREATE_SYMLINK_TO_FILE (${LIBRARY_NAME} ${LINK_NAME})
172 endif()
173 endif()
fb3267c7 174endif()
175
fb3267c7 176if (CURRENT_MODULE)
096ef695 177 set_target_properties (${PROJECT_NAME} PROPERTIES FOLDER "Modules/${CURRENT_MODULE}")
ada9ef40 178 set_target_properties (${PROJECT_NAME} PROPERTIES MODULE "${CURRENT_MODULE}")
09eca2b5 179 if (APPLE)
180 if (NOT "${INSTALL_NAME_DIR}" STREQUAL "")
181 set_target_properties (${PROJECT_NAME} PROPERTIES BUILD_WITH_INSTALL_RPATH 1 INSTALL_NAME_DIR "${INSTALL_NAME_DIR}")
182 endif()
183 endif()
fb3267c7 184endif()
316d77d9 185
096ef695 186get_property (OCC_VERSION_MAJOR GLOBAL PROPERTY OCC_VERSION_MAJOR)
187get_property (OCC_VERSION_MINOR GLOBAL PROPERTY OCC_VERSION_MINOR)
188get_property (OCC_VERSION_MAINTENANCE GLOBAL PROPERTY OCC_VERSION_MAINTENANCE)
189
41c012f0 190if (ANDROID)
191 # do not append version to the filename
192 set_target_properties (${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "${PRECOMPILED_DEFS}")
193else()
194 set_target_properties (${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "${PRECOMPILED_DEFS}"
195 SOVERSION "${OCC_VERSION_MAJOR}"
196 VERSION "${OCC_VERSION_MAJOR}.${OCC_VERSION_MINOR}.${OCC_VERSION_MAINTENANCE}")
197endif()
fb3267c7 198
199set (USED_TOOLKITS_BY_CURRENT_PROJECT)
200set (USED_EXTERNAL_LIBS_BY_CURRENT_PROJECT)
201
202# parce EXTERNLIB file
203FILE_TO_LIST ("src/${PROJECT_NAME}/EXTERNLIB" USED_EXTERNLIB_AND_TOOLKITS)
204foreach (USED_ITEM ${USED_EXTERNLIB_AND_TOOLKITS})
a6874708 205 string (REGEX MATCH "^ *#" COMMENT_FOUND ${USED_ITEM})
206 if (NOT COMMENT_FOUND)
207 string (REGEX MATCH "^TK" TK_FOUND ${USED_ITEM})
208 string (REGEX MATCH "^vtk" VTK_FOUND ${USED_ITEM})
209
210 if (NOT "${TK_FOUND}" STREQUAL "" OR NOT "${VTK_FOUND}" STREQUAL "")
211 list (APPEND USED_TOOLKITS_BY_CURRENT_PROJECT ${USED_ITEM})
212 else()
213 string (REGEX MATCH "^CSF_" CSF_FOUND ${USED_ITEM})
214 if ("${CSF_FOUND}" STREQUAL "")
215 message (STATUS "Info: ${USED_ITEM} from ${PROJECT_NAME} skipped due to it is empty")
216 else() # get CSF_ value
217 set (CURRENT_CSF ${${USED_ITEM}})
218 if (NOT "${CURRENT_CSF}" STREQUAL "")
219 # prepare a list from a string with whitespaces
220 separate_arguments (CURRENT_CSF)
221 list (APPEND USED_EXTERNAL_LIBS_BY_CURRENT_PROJECT ${CURRENT_CSF})
222 endif()
fb3267c7 223 endif()
316d77d9 224 endif()
225 endif()
fb3267c7 226endforeach()
316d77d9 227
e713baee 228if (APPLE)
229 list (FIND USED_EXTERNAL_LIBS_BY_CURRENT_PROJECT X11 IS_X11_FOUND)
230 if (NOT ${IS_X11_FOUND} EQUAL -1)
231 find_package (X11 COMPONENTS X11 Xext Xmu Xi)
232 if (NOT X11_FOUND)
a6874708 233 message (STATUS "Warning: X11 is not found. It's required to install The XQuartz project: http://www.xquartz.org")
e713baee 234 endif()
235 endif()
236endif()
237
88d533be 238# Update list of used VTK libraries if OpenGL2 Rendering BackEnd is used.
239# Add VTK_OPENGL2_BACKEND definition.
240if("${VTK_RENDERING_BACKEND}" STREQUAL "OpenGL2")
241 add_definitions(-DVTK_OPENGL2_BACKEND)
242 foreach (VTK_EXCLUDE_LIBRARY vtkRenderingOpenGL vtkRenderingFreeTypeOpenGL)
243 list (FIND USED_TOOLKITS_BY_CURRENT_PROJECT "${VTK_EXCLUDE_LIBRARY}" IS_VTK_OPENGL_FOUND)
244 if (NOT ${IS_VTK_OPENGL_FOUND} EQUAL -1)
245 list (REMOVE_ITEM USED_TOOLKITS_BY_CURRENT_PROJECT ${VTK_EXCLUDE_LIBRARY})
246 if (${VTK_EXCLUDE_LIBRARY} STREQUAL vtkRenderingOpenGL)
247 list (APPEND USED_TOOLKITS_BY_CURRENT_PROJECT vtkRenderingOpenGL2)
248 endif()
249 endif()
250 endforeach()
251endif()
252
3321f684 253if (BUILD_SHARED_LIBS)
254 target_link_libraries (${PROJECT_NAME} ${USED_TOOLKITS_BY_CURRENT_PROJECT} ${USED_EXTERNAL_LIBS_BY_CURRENT_PROJECT})
255endif()