0026529: CMake offers rebuilding of platform dependent code unclear for an user
[occt.git] / adm / cmake / occt_toolkit.cmake
1 # script for each OCCT toolkit
2
3 # Get all used packages from toolkit
4 foreach (TOOLKIT_MODULE ${TOOLKIT_MODULES})
5   if (WIN32)
6     list (APPEND PRECOMPILED_DEFS "-D__${TOOLKIT_MODULE}_DLL")
7   endif()
8   list (APPEND COMPILER_DIRECTORIES "${OCCT_SOURCE_DIR}/src/${TOOLKIT_MODULE}")
9 endforeach()
10 string (REGEX REPLACE ";" " " PRECOMPILED_DEFS "${PRECOMPILED_DEFS}")
11
12 # Get from toolkits EXTERNLIB all used libs
13 OCCT_TOOLKIT_DEP (${PROJECT_NAME} ${PROJECT_NAME}_DEPS)
14 foreach (PROJECT_DEP ${${PROJECT_NAME}_DEPS})
15   IS_OCCT_TOOLKIT (${PROJECT_DEP} OCCT_MODULES FOUND_TOOLKIT)
16   if ("${FOUND_TOOLKIT}" STREQUAL "ON")
17     list (APPEND USED_LIBS "${PROJECT_DEP}")
18   endif()
19 endforeach()
20
21 # Get all source files from used packages
22 foreach (CMP_DIR ${COMPILER_DIRECTORIES})
23   get_filename_component (CMP_DIR_NAME ${CMP_DIR} NAME)
24
25   set (SOURCE_FILES)
26   set (HEADER_FILES)
27
28   # Generate Flex and Bison files
29   if (${REBUILD_PLATFORM_DEPENDENT_CODE})
30
31     # flex files
32     file (GLOB SOURCE_FILES_FLEX "${CMP_DIR}/*[.]lex") 
33     list (LENGTH SOURCE_FILES_FLEX SOURCE_FILES_FLEX_LEN)
34     list (SORT SOURCE_FILES_FLEX)
35
36     # bison files
37     file (GLOB SOURCE_FILES_BISON "${CMP_DIR}/*[.]yacc") 
38     list (LENGTH SOURCE_FILES_BISON SOURCE_FILES_BISON_LEN)
39     list (SORT SOURCE_FILES_BISON)
40
41     if (${SOURCE_FILES_FLEX_LEN} EQUAL ${SOURCE_FILES_BISON_LEN} AND NOT ${SOURCE_FILES_FLEX_LEN} EQUAL 0)
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} ${CMP_DIR}/${BISON_OUTPUT_FILE} COMPILE_FLAGS "-p ${CURRENT_BISON_FILE_NAME}")
58           FLEX_TARGET  (Scanner_${CURRENT_FLEX_FILE_NAME} ${CURRENT_FLEX_FILE} ${CMP_DIR}/${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()
66
67   # header files 
68   file (STRINGS "${CMP_DIR}/FILES" HEADER_FILES_M   REGEX ".+[.]h")
69   file (STRINGS "${CMP_DIR}/FILES" HEADER_FILES_LXX REGEX ".+[.]lxx")
70   file (STRINGS "${CMP_DIR}/FILES" HEADER_FILES_GXX REGEX ".+[.]gxx")
71   list (APPEND HEADER_FILES ${HEADER_FILES_M} ${HEADER_FILES_LXX} ${SOURCE_FILES_GXX})
72
73   foreach(HEADER_FILE ${HEADER_FILES})
74     list (APPEND USED_INCFILES ${CMP_DIR}/${HEADER_FILE})
75     SOURCE_GROUP ("Header Files\\${CMP_DIR_NAME}" FILES ${CMP_DIR}/${HEADER_FILE})
76   endforeach()
77
78   # source files
79   file (STRINGS "${CMP_DIR}/FILES" SOURCE_FILES_C REGEX ".+[.]c")
80   list (APPEND SOURCE_FILES ${SOURCE_FILES_C})
81
82   if(APPLE)
83     file (STRINGS "${CMP_DIR}/FILES" SOURCE_FILES_M REGEX ".+[.]mm")
84     list (APPEND SOURCE_FILES ${SOURCE_FILES_M})
85   endif()
86
87   foreach(SOURCE_FILE ${SOURCE_FILES})
88     list (APPEND USED_SRCFILES ${CMP_DIR}/${SOURCE_FILE})
89     SOURCE_GROUP ("Source Files\\${CMP_DIR_NAME}" FILES ${CMP_DIR}/${SOURCE_FILE})
90   endforeach()
91 endforeach()
92
93 # Create project for toolkit
94 list (FIND BUILD_TOOLKITS ${PROJECT_NAME} CURRENT_PROJECT_IS_BUILT)
95 if ("${BUILD_TOOLKITS}" STREQUAL "" OR NOT ${CURRENT_PROJECT_IS_BUILT} EQUAL -1)
96
97   foreach (OCCT_MODULE ${OCCT_MODULES})
98     list (FIND ${OCCT_MODULE}_TOOLKITS ${PROJECT_NAME} CURRENT_PROJECT_IS_BUILT)
99     if (NOT ${CURRENT_PROJECT_IS_BUILT} EQUAL -1)
100       set (CURRENT_MODULE ${OCCT_MODULE})
101     endif()
102   endforeach()
103   
104   if ("${PROJECT_NAME}" STREQUAL "DRAWEXE")
105     add_executable (${PROJECT_NAME} ${USED_SRCFILES} ${USED_INCFILES})
106
107     install (TARGETS ${PROJECT_NAME}
108              CONFIGURATIONS Release
109              DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bin")
110     install (TARGETS ${PROJECT_NAME}
111              CONFIGURATIONS RelWithDebInfo
112              DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bini")
113     install (TARGETS ${PROJECT_NAME}
114              CONFIGURATIONS Debug
115              DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bind")
116   else()
117     add_library (${PROJECT_NAME} ${USED_SRCFILES} ${USED_INCFILES})
118
119     install (TARGETS ${PROJECT_NAME}
120              CONFIGURATIONS Release
121              RUNTIME DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bin"
122              ARCHIVE DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/lib"
123              LIBRARY DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/lib")
124     install (TARGETS ${PROJECT_NAME}
125              CONFIGURATIONS RelWithDebInfo
126              RUNTIME DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bini"
127              ARCHIVE DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/libi"
128              LIBRARY DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/libi")
129     install (TARGETS ${PROJECT_NAME}
130              CONFIGURATIONS Debug
131              RUNTIME DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bind"
132              ARCHIVE DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/libd"
133              LIBRARY DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/libd")
134     if (MSVC)
135       install (FILES  ${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/bind/${PROJECT_NAME}.pdb
136                CONFIGURATIONS Debug
137                DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bind")
138     endif()
139   endif()
140
141   set_property (TARGET ${PROJECT_NAME} PROPERTY FOLDER "Modules/${CURRENT_MODULE}")
142   set_target_properties (${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "${PRECOMPILED_DEFS}")
143   target_link_libraries (${PROJECT_NAME} ${USED_LIBS})
144 endif()