0026858: Configuration - cmake wrong detected TK folder
[occt.git] / adm / cmake / occt_toolkit.cmake
CommitLineData
316d77d9 1# script for each OCCT toolkit
2
3# Get all used packages from toolkit
f2e9c853 4foreach (OCCT_PACKAGE ${TOOLKIT_MODULES})
316d77d9 5 if (WIN32)
f2e9c853 6 list (APPEND PRECOMPILED_DEFS "-D__${OCCT_PACKAGE}_DLL")
316d77d9 7 endif()
f2e9c853 8 # ${OCCT_SOURCE_DIR}/src/${OCCT_PACKAGE}
316d77d9 9
10 set (SOURCE_FILES)
11 set (HEADER_FILES)
12
13 # Generate Flex and Bison files
14 if (${REBUILD_PLATFORM_DEPENDENT_CODE})
15
16 # flex files
f2e9c853 17 OCCT_ORIGIN_AND_PATCHED_FILES ("src/${OCCT_PACKAGE}" "*[.]lex" SOURCE_FILES_FLEX)
316d77d9 18 list (LENGTH SOURCE_FILES_FLEX SOURCE_FILES_FLEX_LEN)
19 list (SORT SOURCE_FILES_FLEX)
20
21 # bison files
f2e9c853 22 OCCT_ORIGIN_AND_PATCHED_FILES ("src/${OCCT_PACKAGE}" "*[.]yacc" SOURCE_FILES_BISON)
316d77d9 23 list (LENGTH SOURCE_FILES_BISON SOURCE_FILES_BISON_LEN)
24 list (SORT SOURCE_FILES_BISON)
25
26 if (${SOURCE_FILES_FLEX_LEN} EQUAL ${SOURCE_FILES_BISON_LEN} AND NOT ${SOURCE_FILES_FLEX_LEN} EQUAL 0)
27
28 math (EXPR SOURCE_FILES_FLEX_LEN "${SOURCE_FILES_FLEX_LEN} - 1")
29 foreach (FLEX_FILE_INDEX RANGE ${SOURCE_FILES_FLEX_LEN})
30
31 list (GET SOURCE_FILES_FLEX ${FLEX_FILE_INDEX} CURRENT_FLEX_FILE)
32 get_filename_component (CURRENT_FLEX_FILE_NAME ${CURRENT_FLEX_FILE} NAME_WE)
33
34 list (GET SOURCE_FILES_BISON ${FLEX_FILE_INDEX} CURRENT_BISON_FILE)
35 get_filename_component (CURRENT_BISON_FILE_NAME ${CURRENT_BISON_FILE} NAME_WE)
36
37 string (COMPARE EQUAL ${CURRENT_FLEX_FILE_NAME} ${CURRENT_BISON_FILE_NAME} ARE_FILES_EQUAL)
38
39 if (EXISTS "${CURRENT_FLEX_FILE}" AND EXISTS "${CURRENT_BISON_FILE}" AND ${ARE_FILES_EQUAL})
40 set (BISON_OUTPUT_FILE ${CURRENT_BISON_FILE_NAME}.tab.c)
41 set (FLEX_OUTPUT_FILE lex.${CURRENT_FLEX_FILE_NAME}.c)
42 BISON_TARGET (Parser_${CURRENT_BISON_FILE_NAME} ${CURRENT_BISON_FILE} ${CMP_DIR}/${BISON_OUTPUT_FILE} COMPILE_FLAGS "-p ${CURRENT_BISON_FILE_NAME}")
43 FLEX_TARGET (Scanner_${CURRENT_FLEX_FILE_NAME} ${CURRENT_FLEX_FILE} ${CMP_DIR}/${FLEX_OUTPUT_FILE} COMPILE_FLAGS "-P${CURRENT_FLEX_FILE_NAME}")
44 ADD_FLEX_BISON_DEPENDENCY (Scanner_${CURRENT_FLEX_FILE_NAME} Parser_${CURRENT_BISON_FILE_NAME})
45
46 list (APPEND SOURCE_FILES ${BISON_OUTPUT_FILE} ${FLEX_OUTPUT_FILE})
47 endif()
48 endforeach()
49 endif()
50 endif()
51
f2e9c853 52 # header files
53 if (APPLY_OCCT_PATCH_DIR AND EXISTS "${APPLY_OCCT_PATCH_DIR}/src/${OCCT_PACKAGE}/FILES")
54 file (STRINGS "${APPLY_OCCT_PATCH_DIR}/src/${OCCT_PACKAGE}/FILES" HEADER_FILES_M REGEX ".+[.]h")
55 file (STRINGS "${APPLY_OCCT_PATCH_DIR}/src/${OCCT_PACKAGE}/FILES" HEADER_FILES_LXX REGEX ".+[.]lxx")
56 file (STRINGS "${APPLY_OCCT_PATCH_DIR}/src/${OCCT_PACKAGE}/FILES" HEADER_FILES_GXX REGEX ".+[.]gxx")
316d77d9 57
f2e9c853 58 file (STRINGS "${APPLY_OCCT_PATCH_DIR}/src/${OCCT_PACKAGE}/FILES" SOURCE_FILES_C REGEX ".+[.]c")
59 if(APPLE)
60 file (STRINGS "${APPLY_OCCT_PATCH_DIR}/src/${OCCT_PACKAGE}/FILES" SOURCE_FILES_M REGEX ".+[.]mm")
61 endif()
62 else()
63 file (STRINGS "${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}/FILES" HEADER_FILES_M REGEX ".+[.]h")
64 file (STRINGS "${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}/FILES" HEADER_FILES_LXX REGEX ".+[.]lxx")
65 file (STRINGS "${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}/FILES" HEADER_FILES_GXX REGEX ".+[.]gxx")
66
67 file (STRINGS "${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}/FILES" SOURCE_FILES_C REGEX ".+[.]c")
68 if(APPLE)
69 file (STRINGS "${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}/FILES" SOURCE_FILES_M REGEX ".+[.]mm")
70 endif()
71 endif()
72
73 list (APPEND HEADER_FILES ${HEADER_FILES_M} ${HEADER_FILES_LXX} ${SOURCE_FILES_GXX})
316d77d9 74 list (APPEND SOURCE_FILES ${SOURCE_FILES_C})
316d77d9 75 if(APPLE)
316d77d9 76 list (APPEND SOURCE_FILES ${SOURCE_FILES_M})
77 endif()
78
f2e9c853 79 foreach(HEADER_FILE ${HEADER_FILES})
80 if (APPLY_OCCT_PATCH_DIR AND EXISTS "${APPLY_OCCT_PATCH_DIR}/src/${OCCT_PACKAGE}/${HEADER_FILE}")
81 message (STATUS "Info. consider patched file: ${APPLY_OCCT_PATCH_DIR}/src/${OCCT_PACKAGE}/${HEADER_FILE}")
82 list (APPEND USED_INCFILES "${APPLY_OCCT_PATCH_DIR}/src/${OCCT_PACKAGE}/${HEADER_FILE}")
83 SOURCE_GROUP ("Header Files\\${OCCT_PACKAGE}" FILES "${APPLY_OCCT_PATCH_DIR}/src/${OCCT_PACKAGE}/${HEADER_FILE}")
84 else()
85 list (APPEND USED_INCFILES "${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}/${HEADER_FILE}")
86 SOURCE_GROUP ("Header Files\\${OCCT_PACKAGE}" FILES "${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}/${HEADER_FILE}")
87 endif()
88 endforeach()
89
316d77d9 90 foreach(SOURCE_FILE ${SOURCE_FILES})
f2e9c853 91 if (APPLY_OCCT_PATCH_DIR AND EXISTS "${APPLY_OCCT_PATCH_DIR}/src/${OCCT_PACKAGE}/${SOURCE_FILE}")
92 message (STATUS "Info. consider patched file: ${APPLY_OCCT_PATCH_DIR}/src/${OCCT_PACKAGE}/${SOURCE_FILE}")
93 list (APPEND USED_SRCFILES "${APPLY_OCCT_PATCH_DIR}/src/${OCCT_PACKAGE}/${SOURCE_FILE}")
94 SOURCE_GROUP ("Source Files\\${OCCT_PACKAGE}" FILES "${APPLY_OCCT_PATCH_DIR}/src/${OCCT_PACKAGE}/${SOURCE_FILE}")
95 else()
96 list (APPEND USED_SRCFILES "${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}/${SOURCE_FILE}")
97 SOURCE_GROUP ("Source Files\\${OCCT_PACKAGE}" FILES "${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}/${SOURCE_FILE}")
98 endif()
316d77d9 99 endforeach()
100endforeach()
f2e9c853 101string (REGEX REPLACE ";" " " PRECOMPILED_DEFS "${PRECOMPILED_DEFS}")
102
103# Get from toolkits EXTERNLIB all used libs
104OCCT_TOOLKIT_DEP (${PROJECT_NAME} ${PROJECT_NAME}_DEPS)
105foreach (PROJECT_DEP ${${PROJECT_NAME}_DEPS})
106 IS_OCCT_TOOLKIT (${PROJECT_DEP} OCCT_MODULES FOUND_TOOLKIT)
107 if ("${FOUND_TOOLKIT}" STREQUAL "ON")
108 list (APPEND USED_LIBS "${PROJECT_DEP}")
109 endif()
110endforeach()
316d77d9 111
112# Create project for toolkit
113list (FIND BUILD_TOOLKITS ${PROJECT_NAME} CURRENT_PROJECT_IS_BUILT)
114if ("${BUILD_TOOLKITS}" STREQUAL "" OR NOT ${CURRENT_PROJECT_IS_BUILT} EQUAL -1)
115
116 foreach (OCCT_MODULE ${OCCT_MODULES})
117 list (FIND ${OCCT_MODULE}_TOOLKITS ${PROJECT_NAME} CURRENT_PROJECT_IS_BUILT)
118 if (NOT ${CURRENT_PROJECT_IS_BUILT} EQUAL -1)
119 set (CURRENT_MODULE ${OCCT_MODULE})
120 endif()
121 endforeach()
122
123 if ("${PROJECT_NAME}" STREQUAL "DRAWEXE")
124 add_executable (${PROJECT_NAME} ${USED_SRCFILES} ${USED_INCFILES})
125
126 install (TARGETS ${PROJECT_NAME}
127 CONFIGURATIONS Release
128 DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bin")
129 install (TARGETS ${PROJECT_NAME}
130 CONFIGURATIONS RelWithDebInfo
131 DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bini")
132 install (TARGETS ${PROJECT_NAME}
133 CONFIGURATIONS Debug
134 DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bind")
135 else()
136 add_library (${PROJECT_NAME} ${USED_SRCFILES} ${USED_INCFILES})
137
138 install (TARGETS ${PROJECT_NAME}
139 CONFIGURATIONS Release
140 RUNTIME DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bin"
141 ARCHIVE DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/lib"
142 LIBRARY DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/lib")
143 install (TARGETS ${PROJECT_NAME}
144 CONFIGURATIONS RelWithDebInfo
145 RUNTIME DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bini"
146 ARCHIVE DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/libi"
147 LIBRARY DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/libi")
148 install (TARGETS ${PROJECT_NAME}
149 CONFIGURATIONS Debug
150 RUNTIME DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bind"
151 ARCHIVE DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/libd"
152 LIBRARY DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/libd")
153 if (MSVC)
154 install (FILES ${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/bind/${PROJECT_NAME}.pdb
155 CONFIGURATIONS Debug
156 DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bind")
157 endif()
158 endif()
159
160 set_property (TARGET ${PROJECT_NAME} PROPERTY FOLDER "Modules/${CURRENT_MODULE}")
161 set_target_properties (${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "${PRECOMPILED_DEFS}")
162 target_link_libraries (${PROJECT_NAME} ${USED_LIBS})
163endif()