0026460: Implicit cast to TopoDS_Shape compilation error due to ambiguous conversion
[occt.git] / adm / cmake / 3rdparty_macro.cmake
1 #
2
3 # include occt macros. compiler_bitness, os_wiht_bit, compiler
4 OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/occt_macros")
5
6 macro (THIRDPARTY_PRODUCT PRODUCT_NAME HEADER_NAME LIBRARY_NAME LIBRARY_NAME_DEBUG)
7
8   # define 3RDPARTY_${PRODUCT_NAME}_DIR variable is it isn't defined
9   if (NOT DEFINED 3RDPARTY_${PRODUCT_NAME}_DIR)
10     set (3RDPARTY_${PRODUCT_NAME}_DIR "" CACHE PATH "The directory containing ${PRODUCT_NAME}")
11   endif()
12
13   # search for product directory inside 3RDPARTY_DIR directory
14   if (NOT 3RDPARTY_${PRODUCT_NAME}_DIR AND 3RDPARTY_DIR)
15     FIND_PRODUCT_DIR ("${3RDPARTY_DIR}" "${PRODUCT_NAME}" ${PRODUCT_NAME}_DIR_NAME)
16     if (${PRODUCT_NAME}_DIR_NAME)
17       message (STATUS "Info: ${PRODUCT_NAME}: ${${PRODUCT_NAME}_DIR_NAME} folder is used")
18       set (3RDPARTY_${PRODUCT_NAME}_DIR "${3RDPARTY_DIR}/${${PRODUCT_NAME}_DIR_NAME}" CACHE PATH "The directory containing ${PRODUCT_NAME}" FORCE)
19     endif()
20   endif()
21
22   if (NOT DEFINED INSTALL_${PRODUCT_NAME})
23     set (INSTALL_${PRODUCT_NAME} OFF CACHE BOOL "Is ${PRODUCT_NAME} required to be copied into install directory")
24   endif()
25
26   # search for include directory
27   if (NOT 3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR OR NOT EXISTS "${3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR}")
28     set (3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR "3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR-NOTFOUND" CACHE FILEPATH "The directory containing the headers of the ${PRODUCT_NAME}" FORCE)
29     find_path (3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR ${HEADER_NAME} PATHS
30                                                                     "${3RDPARTY_${PRODUCT_NAME}_DIR}/include"
31                                                                     ${3RDPARTY_${PRODUCT_NAME}_ADDITIONAL_PATH_FOR_HEADER}
32                                                                    NO_DEFAULT_PATH)
33     find_path (3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR ${HEADER_NAME})
34   endif()
35
36   if (NOT 3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR OR NOT EXISTS "${3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR}")
37     set (3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR "" CACHE FILEPATH "The directory containing the headers of the ${PRODUCT_NAME}" FORCE)
38   endif()
39
40   if (NOT 3RDPARTY_${PRODUCT_NAME}_LIBRARY_DIR)
41     set (3RDPARTY_${PRODUCT_NAME}_LIBRARY "" CACHE FILEPATH "${PRODUCT_NAME} library" FORCE)
42   elseif (3RDPARTY_${PRODUCT_NAME}_LIBRARY AND EXISTS "${3RDPARTY_${PRODUCT_NAME}_LIBRARY}")
43     get_filename_component(3RDPARTY_${PRODUCT_NAME}_LIBRARY_DIR_TMP "${3RDPARTY_${PRODUCT_NAME}_LIBRARY}" PATH)
44     if (NOT "${3RDPARTY_${PRODUCT_NAME}_LIBRARY_DIR}" STREQUAL "${3RDPARTY_${PRODUCT_NAME}_LIBRARY_DIR_TMP}")
45       set (3RDPARTY_${PRODUCT_NAME}_LIBRARY "" CACHE FILEPATH "${PRODUCT_NAME} library" FORCE)
46     endif()
47   endif()
48
49   # search for library
50   if (NOT 3RDPARTY_${PRODUCT_NAME}_LIBRARY OR NOT EXISTS "${3RDPARTY_${PRODUCT_NAME}_LIBRARY}")
51     set (3RDPARTY_${PRODUCT_NAME}_LIBRARY "3RDPARTY_${PRODUCT_NAME}_LIBRARY-NOTFOUND" CACHE FILEPATH "${PRODUCT_NAME} library" FORCE)
52
53     find_library (3RDPARTY_${PRODUCT_NAME}_LIBRARY ${LIBRARY_NAME} PATHS
54                                                                    "${3RDPARTY_${PRODUCT_NAME}_LIBRARY_DIR}"
55                                                                    "${3RDPARTY_${PRODUCT_NAME}_DIR}/lib"
56                                                                    ${3RDPARTY_${PRODUCT_NAME}_ADDITIONAL_PATH_FOR_LIB}
57                                                                    NO_DEFAULT_PATH)
58     # second search if previous one do not find anything
59     find_library (3RDPARTY_${PRODUCT_NAME}_LIBRARY ${LIBRARY_NAME})
60   endif()
61
62   if (NOT DEFINED 3RDPARTY_${PRODUCT_NAME}_LIBRARY_DIR)
63     set (3RDPARTY_${PRODUCT_NAME}_LIBRARY_DIR "" CACHE FILEPATH "The directory containing ${PRODUCT_NAME} library" FORCE)
64   endif()
65
66   # library path
67   if (3RDPARTY_${PRODUCT_NAME}_LIBRARY AND EXISTS "${3RDPARTY_${PRODUCT_NAME}_LIBRARY}")
68     get_filename_component (3RDPARTY_${PRODUCT_NAME}_LIBRARY_DIR "${3RDPARTY_${PRODUCT_NAME}_LIBRARY}" PATH)
69     set (3RDPARTY_${PRODUCT_NAME}_LIBRARY_DIR "${3RDPARTY_${PRODUCT_NAME}_LIBRARY_DIR}" CACHE FILEPATH "The directory containing ${PRODUCT_NAME} library" FORCE)
70   endif()
71
72   # search for shared library (just for win case)
73   if (WIN32)
74     set (CMAKE_FIND_LIBRARY_SUFFIXES ".lib" ".dll")
75
76     if (NOT 3RDPARTY_${PRODUCT_NAME}_DLL_DIR)
77       set (3RDPARTY_${PRODUCT_NAME}_DLL "" CACHE FILEPATH "${PRODUCT_NAME} shared library" FORCE)
78     elseif (3RDPARTY_${PRODUCT_NAME}_DLL AND EXISTS "${3RDPARTY_${PRODUCT_NAME}_DLL}")
79       get_filename_component(3RDPARTY_${PRODUCT_NAME}_DLL_DIR_TMP "${3RDPARTY_${PRODUCT_NAME}_DLL}" PATH)
80       if (NOT "${3RDPARTY_${PRODUCT_NAME}_DLL_DIR}" STREQUAL "${3RDPARTY_${PRODUCT_NAME}_DLL_DIR_TMP}")
81         set (3RDPARTY_${PRODUCT_NAME}_DLL "" CACHE FILEPATH "${PRODUCT_NAME} shared library" FORCE)
82       endif()
83     endif()
84
85     if (NOT 3RDPARTY_${PRODUCT_NAME}_DLL OR NOT EXISTS "${3RDPARTY_${PRODUCT_NAME}_DLL}")
86       set (3RDPARTY_${PRODUCT_NAME}_DLL "3RDPARTY_${PRODUCT_NAME}_DLL-NOTFOUND" CACHE FILEPATH "${PRODUCT_NAME} shared library" FORCE)
87
88       find_library (3RDPARTY_${PRODUCT_NAME}_DLL "${LIBRARY_NAME}" PATHS
89                                                                    "${3RDPARTY_${PRODUCT_NAME}_DLL_DIR}"
90                                                                    "${3RDPARTY_${PRODUCT_NAME}_DIR}/bin"
91                                                                    ${3RDPARTY_${PRODUCT_NAME}_ADDITIONAL_PATH_FOR_DLL}
92                                                                    NO_DEFAULT_PATH)
93
94         # second search if previous one do not find anything
95         find_library (3RDPARTY_${PRODUCT_NAME}_DLL "${LIBRARY_NAME}")
96     endif()
97
98     if (NOT DEFINED 3RDPARTY_${PRODUCT_NAME}_DLL_DIR)
99       set (3RDPARTY_${PRODUCT_NAME}_DLL_DIR "" CACHE FILEPATH "The directory containing ${PRODUCT_NAME} shared library" FORCE)
100     endif()
101
102     # shared library path
103     if (3RDPARTY_${PRODUCT_NAME}_DLL AND EXISTS "${3RDPARTY_${PRODUCT_NAME}_DLL}")
104       get_filename_component (3RDPARTY_${PRODUCT_NAME}_DLL_DIR "${3RDPARTY_${PRODUCT_NAME}_DLL}" PATH)
105       set (3RDPARTY_${PRODUCT_NAME}_DLL_DIR "${3RDPARTY_${PRODUCT_NAME}_DLL_DIR}" CACHE FILEPATH "The directory containing ${PRODUCT_NAME} shared library" FORCE)
106     endif()
107   endif()
108
109   if (3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR AND EXISTS "${3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR}")
110     list (APPEND 3RDPARTY_INCLUDE_DIRS "${3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR}")
111   else()
112     list (APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR)
113   endif()
114
115   if (3RDPARTY_${PRODUCT_NAME}_LIBRARY AND EXISTS "${3RDPARTY_${PRODUCT_NAME}_LIBRARY}")
116     list (APPEND 3RDPARTY_LIBRARY_DIRS "${3RDPARTY_${PRODUCT_NAME}_LIBRARY_DIR}")
117   else()
118     list (APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_${PRODUCT_NAME}_LIBRARY_DIR)
119   endif()
120
121   if (WIN32)
122     if (3RDPARTY_${PRODUCT_NAME}_DLL OR EXISTS "${3RDPARTY_${PRODUCT_NAME}_DLL}")
123       list (APPEND 3RDPARTY_DLL_DIRS "${3RDPARTY_${PRODUCT_NAME}_DLL_DIR}")
124     else()
125       list (APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_${PRODUCT_NAME}_DLL_DIR)
126     endif()
127   endif()
128
129   set (USED_3RDPARTY_${PRODUCT_NAME}_DIR "")
130
131   if (INSTALL_${PRODUCT_NAME})
132     OCCT_MAKE_OS_WITH_BITNESS()
133     OCCT_MAKE_COMPILER_SHORT_NAME()
134
135     if (WIN32)
136       install (FILES "${3RDPARTY_${PRODUCT_NAME}_DLL}" 
137                CONFIGURATIONS Release
138                DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bin")
139       install (FILES "${3RDPARTY_${PRODUCT_NAME}_DLL}" 
140                CONFIGURATIONS RelWithDebInfo
141                DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bin")
142       install (FILES "${3RDPARTY_${PRODUCT_NAME}_DLL}" 
143                CONFIGURATIONS Debug
144                DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bind")
145
146     else()
147       get_filename_component(ABS_PATH ${3RDPARTY_${PRODUCT_NAME}_LIBRARY} REALPATH)
148       if ("${PRODUCT_NAME}" STREQUAL "FREEIMAGE")
149         get_filename_component(FREEIMLIB ${3RDPARTY_${PRODUCT_NAME}_LIBRARY} NAME)
150         install (FILES "${ABS_PATH}"
151                  CONFIGURATIONS Release
152                  DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/lib"
153                  RENAME ${FREEIMLIB}.3)
154                  install (FILES "${ABS_PATH}"
155                  CONFIGURATIONS RelWithDebInfo
156                  DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/lib"
157                  RENAME ${FREEIMLIB}.3)
158         install (FILES "${ABS_PATH}"
159                  CONFIGURATIONS Debug
160                  DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/libd"
161                  RENAME ${FREEIMLIB}.3)
162       endif()
163       if("${PRODUCT_NAME}" STREQUAL "GL2PS")
164         get_filename_component(GL2PSLIB ${3RDPARTY_${PRODUCT_NAME}_LIBRARY} NAME)
165         install (FILES "${ABS_PATH}"
166                  CONFIGURATIONS Release
167                  DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/lib"
168                  RENAME ${GL2PSLIB}.1)
169         install (FILES "${ABS_PATH}"
170                  CONFIGURATIONS RelWithDebInfo
171                  DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/lib"
172                  RENAME ${GL2PSLIB}.1)
173         install (FILES "${ABS_PATH}"
174                  CONFIGURATIONS Debug
175                  DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/libd"
176                  RENAME ${GL2PSLIB}.1)
177       endif()
178     endif()
179   else()
180     # the library directory for using by the executable
181     if (WIN32)
182       set (USED_3RDPARTY_${PRODUCT_NAME}_DIR "${3RDPARTY_${PRODUCT_NAME}_DLL_DIR}")
183     else()
184       set (USED_3RDPARTY_${PRODUCT_NAME}_DIR "${3RDPARTY_${PRODUCT_NAME}_LIBRARY_DIR}")
185     endif()
186   endif()
187
188   mark_as_advanced (3RDPARTY_${PRODUCT_NAME}_LIBRARY 3RDPARTY_${PRODUCT_NAME}_DLL)
189 endmacro()