0026460: Implicit cast to TopoDS_Shape compilation error due to ambiguous conversion
[occt.git] / adm / cmake / BuildToolkit.cmake
1 # Get all used packages from toolkit
2 foreach (MODULE ${TOOLKIT_MODULES})
3   if (WIN32)
4     list (APPEND PRECOMPILED_DEFS "-D__${MODULE}_DLL")
5   endif()
6   list (APPEND COMPILER_DIRECTORIES "${OCCT_SOURCE_DIR}/src/${MODULE}")
7 endforeach()
8 string (REGEX REPLACE ";" " " PRECOMPILED_DEFS "${PRECOMPILED_DEFS}")
9
10 # Get from toolkits EXTERNLIB all used libs
11 OCCT_TOOLKIT_DEP (${PROJECT_NAME} ${PROJECT_NAME}_DEPS)
12 foreach (DEP ${${PROJECT_NAME}_DEPS})
13   IS_OCCT_TOOLKIT (${DEP} OCCT_MODULES FOUND_TOOLKIT)
14   if ("${FOUND_TOOLKIT}" STREQUAL "ON")
15     list ( APPEND USED_LIBS "${DEP}" )
16   endif()
17 endforeach()
18
19 # Get all source files from used packages
20 foreach (CDIR ${COMPILER_DIRECTORIES})
21   get_filename_component (CDirName ${CDIR} NAME)
22   set (CDIR_files)
23   set (HDIR_files)
24   file(STRINGS "${CDIR}/FILES" FLEX_Files REGEX ".+[.]lex")
25   file(STRINGS "${CDIR}/FILES" BISON_Files REGEX ".+[.]yacc")
26   file(STRINGS "${CDIR}/FILES" CFiles REGEX ".+[.]c")
27   file(STRINGS "${CDIR}/FILES" MFiles REGEX ".+[.]mm")
28   file(STRINGS "${CDIR}/FILES" HFiles REGEX ".+[.]h")
29   file(STRINGS "${CDIR}/FILES" LXXFiles REGEX ".+[.]lxx")
30   file(STRINGS "${CDIR}/FILES" GXXFiles REGEX ".+[.]gxx")
31
32   # Generate Flex and Bison files
33   if (${BUILD_BISON_FLEX_FILES})
34     list (LENGTH FLEX_Files FLength)
35     list (LENGTH BISON_Files BLength)
36     list (SORT FLEX_Files)
37     list (SORT BISON_Files)
38     if (${FLength} EQUAL ${BLength} AND NOT ${FLength} EQUAL 0)
39       math (EXPR FLength "${FLength} - 1")
40       foreach (FileIndex RANGE ${FLength})
41         list (GET FLEX_Files ${FileIndex} FLEX_File)
42         list (GET BISON_Files ${FileIndex} BISON_File)
43         get_filename_component (FLEX_Name ${FLEX_File} NAME_WE)
44         get_filename_component (BISON_Name ${BISON_File} NAME_WE)
45         string (COMPARE EQUAL ${FLEX_Name} ${BISON_Name} isEQUAL)
46         if (EXISTS "${FLEX_File}" AND EXISTS "${BISON_File}" AND ${isEQUAL})
47           BISON_TARGET (Parser_${BISON_Name} ${BISON_File} ${CDIR}/${BISON_Name}.tab.c)
48           FLEX_TARGET (Scanner_${FLEX_Name} ${FLEX_File} ${CDIR}/lex.${FLEX_Name}.c)
49           ADD_FLEX_BISON_DEPENDENCY (Scanner_${FLEX_Name} Parser_${BISON_Name})
50           list (APPEND CDIR_files ${BISON_Parser_${BISON_Name}_OUTPUTS} ${FLEX_Scanner_${FLEX_Name}_OUTPUTS})
51         endif()
52       endforeach()
53     endif()
54   endif()
55
56   list(APPEND HDIR_files ${HFiles} ${LXXFiles} ${GXXFiles})
57   list( APPEND CDIR_files ${CFiles})
58   if(APPLE)
59     list( APPEND CDIR_files ${MFiles})
60   endif()
61
62   foreach(HFile ${HDIR_files})
63     list( APPEND USED_INCFILES ${CDIR}/${HFile} )
64     SOURCE_GROUP ("Header Files\\${CDirName}" FILES ${CDIR}/${HFile})
65   endforeach(HFile)
66
67   foreach(CFile ${CDIR_files})
68     list( APPEND USED_SRCFILES ${CDIR}/${CFile} )
69     SOURCE_GROUP ("Source Files\\${CDirName}" FILES ${CDIR}/${CFile})
70   endforeach(CFile)
71 endforeach(CDIR)
72
73 list( FIND USED_TOOLKITS ${PROJECT_NAME} isFOUND)
74
75 # Create project for toolkit
76 if ("${USED_TOOLKITS}" STREQUAL "" OR NOT ${isFOUND} EQUAL -1)
77   foreach (MODULE ${OCCT_MODULES})
78     list (FIND ${MODULE}_TOOLKITS ${PROJECT_NAME} isFOUND)
79     if (NOT ${isFOUND} EQUAL -1)
80       set (CURRENT_MODULE ${MODULE})
81     endif()
82   endforeach()
83   if (isEXE)
84     add_executable (${PROJECT_NAME} ${USED_SRCFILES} ${USED_INCFILES})
85     install (TARGETS ${PROJECT_NAME}
86              CONFIGURATIONS Release
87              DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bin")
88     install (TARGETS ${PROJECT_NAME}
89              CONFIGURATIONS RelWithDebInfo
90              DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bin")
91     install (TARGETS ${PROJECT_NAME}
92              CONFIGURATIONS Debug
93              DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bind")
94   else()
95     add_library (${PROJECT_NAME} ${USED_SRCFILES} ${USED_INCFILES})
96     install (TARGETS ${PROJECT_NAME}
97              CONFIGURATIONS Release
98              RUNTIME DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bin"
99              ARCHIVE DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/lib"
100              LIBRARY DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/lib")
101     install (TARGETS ${PROJECT_NAME}
102              CONFIGURATIONS RelWithDebInfo
103              RUNTIME DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bin"
104              ARCHIVE DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/lib"
105              LIBRARY DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/lib")
106     install (TARGETS ${PROJECT_NAME}
107              CONFIGURATIONS Debug
108              RUNTIME DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bind"
109              ARCHIVE DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/libd"
110              LIBRARY DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/libd")
111     if (MSVC)
112       install (FILES  ${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/bind/${PROJECT_NAME}.pdb
113                CONFIGURATIONS Debug
114                DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bind")
115     endif()
116   endif()
117
118   set_property (TARGET ${PROJECT_NAME} PROPERTY FOLDER "Modules/${CURRENT_MODULE}")
119   set_target_properties (${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "${PRECOMPILED_DEFS}")
120   target_link_libraries (${PROJECT_NAME} ${USED_LIBS})
121 endif()