0026865: Configuration, CMake - ensure consistency between FILES and actual content...
[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"))
17 continue()
18 endif()
19
316d77d9 20 if (WIN32)
f2e9c853 21 list (APPEND PRECOMPILED_DEFS "-D__${OCCT_PACKAGE}_DLL")
316d77d9 22 endif()
316d77d9 23
24 set (SOURCE_FILES)
25 set (HEADER_FILES)
26
27 # Generate Flex and Bison files
28 if (${REBUILD_PLATFORM_DEPENDENT_CODE})
29
30 # flex files
f2e9c853 31 OCCT_ORIGIN_AND_PATCHED_FILES ("src/${OCCT_PACKAGE}" "*[.]lex" SOURCE_FILES_FLEX)
316d77d9 32 list (LENGTH SOURCE_FILES_FLEX SOURCE_FILES_FLEX_LEN)
316d77d9 33
34 # bison files
f2e9c853 35 OCCT_ORIGIN_AND_PATCHED_FILES ("src/${OCCT_PACKAGE}" "*[.]yacc" SOURCE_FILES_BISON)
316d77d9 36 list (LENGTH SOURCE_FILES_BISON SOURCE_FILES_BISON_LEN)
316d77d9 37
38 if (${SOURCE_FILES_FLEX_LEN} EQUAL ${SOURCE_FILES_BISON_LEN} AND NOT ${SOURCE_FILES_FLEX_LEN} EQUAL 0)
fb3267c7 39
40 list (SORT SOURCE_FILES_FLEX)
41 list (SORT SOURCE_FILES_BISON)
316d77d9 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)
fb3267c7 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}")
316d77d9 59 ADD_FLEX_BISON_DEPENDENCY (Scanner_${CURRENT_FLEX_FILE_NAME} Parser_${CURRENT_BISON_FILE_NAME})
fb3267c7 60
316d77d9 61 list (APPEND SOURCE_FILES ${BISON_OUTPUT_FILE} ${FLEX_OUTPUT_FILE})
62 endif()
63 endforeach()
64 endif()
65 endif()
66
f2e9c853 67 # header files
68 if (APPLY_OCCT_PATCH_DIR AND EXISTS "${APPLY_OCCT_PATCH_DIR}/src/${OCCT_PACKAGE}/FILES")
69 file (STRINGS "${APPLY_OCCT_PATCH_DIR}/src/${OCCT_PACKAGE}/FILES" HEADER_FILES_M REGEX ".+[.]h")
70 file (STRINGS "${APPLY_OCCT_PATCH_DIR}/src/${OCCT_PACKAGE}/FILES" HEADER_FILES_LXX REGEX ".+[.]lxx")
71 file (STRINGS "${APPLY_OCCT_PATCH_DIR}/src/${OCCT_PACKAGE}/FILES" HEADER_FILES_GXX REGEX ".+[.]gxx")
316d77d9 72
f2e9c853 73 file (STRINGS "${APPLY_OCCT_PATCH_DIR}/src/${OCCT_PACKAGE}/FILES" SOURCE_FILES_C REGEX ".+[.]c")
74 if(APPLE)
75 file (STRINGS "${APPLY_OCCT_PATCH_DIR}/src/${OCCT_PACKAGE}/FILES" SOURCE_FILES_M REGEX ".+[.]mm")
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")
81
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()
86 endif()
87
88 list (APPEND HEADER_FILES ${HEADER_FILES_M} ${HEADER_FILES_LXX} ${SOURCE_FILES_GXX})
316d77d9 89 list (APPEND SOURCE_FILES ${SOURCE_FILES_C})
316d77d9 90 if(APPLE)
316d77d9 91 list (APPEND SOURCE_FILES ${SOURCE_FILES_M})
92 endif()
93
f2e9c853 94 foreach(HEADER_FILE ${HEADER_FILES})
95 if (APPLY_OCCT_PATCH_DIR AND EXISTS "${APPLY_OCCT_PATCH_DIR}/src/${OCCT_PACKAGE}/${HEADER_FILE}")
96 message (STATUS "Info. consider patched file: ${APPLY_OCCT_PATCH_DIR}/src/${OCCT_PACKAGE}/${HEADER_FILE}")
97 list (APPEND USED_INCFILES "${APPLY_OCCT_PATCH_DIR}/src/${OCCT_PACKAGE}/${HEADER_FILE}")
98 SOURCE_GROUP ("Header Files\\${OCCT_PACKAGE}" FILES "${APPLY_OCCT_PATCH_DIR}/src/${OCCT_PACKAGE}/${HEADER_FILE}")
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
316d77d9 105 foreach(SOURCE_FILE ${SOURCE_FILES})
f2e9c853 106 if (APPLY_OCCT_PATCH_DIR AND EXISTS "${APPLY_OCCT_PATCH_DIR}/src/${OCCT_PACKAGE}/${SOURCE_FILE}")
107 message (STATUS "Info. consider patched file: ${APPLY_OCCT_PATCH_DIR}/src/${OCCT_PACKAGE}/${SOURCE_FILE}")
108 list (APPEND USED_SRCFILES "${APPLY_OCCT_PATCH_DIR}/src/${OCCT_PACKAGE}/${SOURCE_FILE}")
109 SOURCE_GROUP ("Source Files\\${OCCT_PACKAGE}" FILES "${APPLY_OCCT_PATCH_DIR}/src/${OCCT_PACKAGE}/${SOURCE_FILE}")
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()
316d77d9 114 endforeach()
115endforeach()
f2e9c853 116string (REGEX REPLACE ";" " " PRECOMPILED_DEFS "${PRECOMPILED_DEFS}")
117
fb3267c7 118if ("${PROJECT_NAME}" STREQUAL "DRAWEXE")
119 add_executable (${PROJECT_NAME} ${USED_SRCFILES} ${USED_INCFILES})
120
121 install (TARGETS ${PROJECT_NAME}
122 CONFIGURATIONS Release
123 DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bin")
124 install (TARGETS ${PROJECT_NAME}
125 CONFIGURATIONS RelWithDebInfo
126 DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bini")
127 install (TARGETS ${PROJECT_NAME}
128 CONFIGURATIONS Debug
129 DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bind")
130else()
131 add_library (${PROJECT_NAME} ${USED_SRCFILES} ${USED_INCFILES})
132
133 install (TARGETS ${PROJECT_NAME}
134 CONFIGURATIONS Release
135 RUNTIME DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bin"
136 ARCHIVE DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/lib"
137 LIBRARY DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/lib")
138 install (TARGETS ${PROJECT_NAME}
139 CONFIGURATIONS RelWithDebInfo
140 RUNTIME DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bini"
141 ARCHIVE DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/libi"
142 LIBRARY DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/libi")
143 install (TARGETS ${PROJECT_NAME}
144 CONFIGURATIONS Debug
145 RUNTIME DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bind"
146 ARCHIVE DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/libd"
147 LIBRARY DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/libd")
148 if (MSVC)
149 install (FILES ${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/bind/${PROJECT_NAME}.pdb
150 CONFIGURATIONS Debug
151 DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bind")
152 endif()
153endif()
154
155set (CURRENT_MODULE)
156foreach (OCCT_MODULE ${OCCT_MODULES})
157 list (FIND ${OCCT_MODULE}_TOOLKITS ${PROJECT_NAME} CURRENT_PROJECT_IS_BUILT)
158 if (NOT ${CURRENT_PROJECT_IS_BUILT} EQUAL -1)
159 set (CURRENT_MODULE ${OCCT_MODULE})
f2e9c853 160 endif()
161endforeach()
316d77d9 162
fb3267c7 163if (CURRENT_MODULE)
164 set_property (TARGET ${PROJECT_NAME} PROPERTY FOLDER "Modules/${CURRENT_MODULE}")
165endif()
316d77d9 166
fb3267c7 167set_target_properties (${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "${PRECOMPILED_DEFS}")
168
169set (USED_TOOLKITS_BY_CURRENT_PROJECT)
170set (USED_EXTERNAL_LIBS_BY_CURRENT_PROJECT)
171
172# parce EXTERNLIB file
173FILE_TO_LIST ("src/${PROJECT_NAME}/EXTERNLIB" USED_EXTERNLIB_AND_TOOLKITS)
174foreach (USED_ITEM ${USED_EXTERNLIB_AND_TOOLKITS})
175 string (REGEX MATCH "^TK" TK_FOUND ${USED_ITEM})
176 if (NOT "${TK_FOUND}" STREQUAL "")
177 list (APPEND USED_TOOLKITS_BY_CURRENT_PROJECT ${USED_ITEM})
316d77d9 178 else()
fb3267c7 179 string (REGEX MATCH "^CSF_" CSF_FOUND ${USED_ITEM})
180 if ("${CSF_FOUND}" STREQUAL "")
181 message (STATUS "Info: ${USED_ITEM} from ${PROJECT_NAME} skipped due to it is empty")
182 else() # get CSF_ value
183 set (CURRENT_CSF ${${USED_ITEM}})
184 if (NOT "${CURRENT_CSF}" STREQUAL "")
185 # prepare a list from a string with whitespaces
186 separate_arguments (CURRENT_CSF)
187 list (APPEND USED_EXTERNAL_LIBS_BY_CURRENT_PROJECT ${CURRENT_CSF})
188 endif()
316d77d9 189 endif()
190 endif()
fb3267c7 191endforeach()
316d77d9 192
fb3267c7 193target_link_libraries (${PROJECT_NAME} ${USED_TOOLKITS_BY_CURRENT_PROJECT} ${USED_EXTERNAL_LIBS_BY_CURRENT_PROJECT})