0026763: CMake configuration process does not allow setup paths for TK library if...
[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     message (STATUS "${INSTALL_${PRODUCT_NAME}_DESCR}")
24     if (NOT "${INSTALL_${PRODUCT_NAME}_DESCR}" STREQUAL "")
25       set (INSTALL_${PRODUCT_NAME} OFF CACHE BOOL "${INSTALL_${PRODUCT_NAME}_DESCR}")
26     else()
27       set (INSTALL_${PRODUCT_NAME} OFF CACHE BOOL "Is ${PRODUCT_NAME} required to be copied into install directory")
28     endif()
29   endif()
30
31   # search for include directory
32   if (NOT 3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR OR NOT EXISTS "${3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR}")
33     set (3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR "3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR-NOTFOUND" CACHE FILEPATH "The directory containing the headers of the ${PRODUCT_NAME}" FORCE)
34     find_path (3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR ${HEADER_NAME} PATHS
35                                                                     "${3RDPARTY_${PRODUCT_NAME}_DIR}/include"
36                                                                     ${3RDPARTY_${PRODUCT_NAME}_ADDITIONAL_PATH_FOR_HEADER}
37                                                                    NO_DEFAULT_PATH)
38     find_path (3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR ${HEADER_NAME})
39   endif()
40
41   if (NOT 3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR OR NOT EXISTS "${3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR}")
42     set (3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR "" CACHE FILEPATH "The directory containing the headers of the ${PRODUCT_NAME}" FORCE)
43   endif()
44
45   if (NOT 3RDPARTY_${PRODUCT_NAME}_LIBRARY_DIR)
46     set (3RDPARTY_${PRODUCT_NAME}_LIBRARY "" CACHE FILEPATH "${PRODUCT_NAME} library" FORCE)
47   elseif (3RDPARTY_${PRODUCT_NAME}_LIBRARY AND EXISTS "${3RDPARTY_${PRODUCT_NAME}_LIBRARY}")
48     get_filename_component(3RDPARTY_${PRODUCT_NAME}_LIBRARY_DIR_TMP "${3RDPARTY_${PRODUCT_NAME}_LIBRARY}" PATH)
49     if (NOT "${3RDPARTY_${PRODUCT_NAME}_LIBRARY_DIR}" STREQUAL "${3RDPARTY_${PRODUCT_NAME}_LIBRARY_DIR_TMP}")
50       set (3RDPARTY_${PRODUCT_NAME}_LIBRARY "" CACHE FILEPATH "${PRODUCT_NAME} library" FORCE)
51     endif()
52   endif()
53
54   # search for library
55   if (NOT 3RDPARTY_${PRODUCT_NAME}_LIBRARY OR NOT EXISTS "${3RDPARTY_${PRODUCT_NAME}_LIBRARY}")
56     set (3RDPARTY_${PRODUCT_NAME}_LIBRARY "3RDPARTY_${PRODUCT_NAME}_LIBRARY-NOTFOUND" CACHE FILEPATH "${PRODUCT_NAME} library" FORCE)
57
58     find_library (3RDPARTY_${PRODUCT_NAME}_LIBRARY ${LIBRARY_NAME} PATHS
59                                                                    "${3RDPARTY_${PRODUCT_NAME}_LIBRARY_DIR}"
60                                                                    "${3RDPARTY_${PRODUCT_NAME}_DIR}/lib"
61                                                                    ${3RDPARTY_${PRODUCT_NAME}_ADDITIONAL_PATH_FOR_LIB}
62                                                                    NO_DEFAULT_PATH)
63     # second search if previous one do not find anything
64     find_library (3RDPARTY_${PRODUCT_NAME}_LIBRARY ${LIBRARY_NAME})
65   endif()
66
67   if (NOT DEFINED 3RDPARTY_${PRODUCT_NAME}_LIBRARY_DIR)
68     set (3RDPARTY_${PRODUCT_NAME}_LIBRARY_DIR "" CACHE FILEPATH "The directory containing ${PRODUCT_NAME} library" FORCE)
69   endif()
70
71   # library path
72   if (3RDPARTY_${PRODUCT_NAME}_LIBRARY AND EXISTS "${3RDPARTY_${PRODUCT_NAME}_LIBRARY}")
73     get_filename_component (3RDPARTY_${PRODUCT_NAME}_LIBRARY_DIR "${3RDPARTY_${PRODUCT_NAME}_LIBRARY}" PATH)
74     set (3RDPARTY_${PRODUCT_NAME}_LIBRARY_DIR "${3RDPARTY_${PRODUCT_NAME}_LIBRARY_DIR}" CACHE FILEPATH "The directory containing ${PRODUCT_NAME} library" FORCE)
75   endif()
76
77   # search for shared library (just for win case)
78   if (WIN32)
79     set (CMAKE_FIND_LIBRARY_SUFFIXES ".lib" ".dll")
80
81     if (NOT 3RDPARTY_${PRODUCT_NAME}_DLL_DIR)
82       set (3RDPARTY_${PRODUCT_NAME}_DLL "" CACHE FILEPATH "${PRODUCT_NAME} shared library" FORCE)
83     elseif (3RDPARTY_${PRODUCT_NAME}_DLL AND EXISTS "${3RDPARTY_${PRODUCT_NAME}_DLL}")
84       get_filename_component(3RDPARTY_${PRODUCT_NAME}_DLL_DIR_TMP "${3RDPARTY_${PRODUCT_NAME}_DLL}" PATH)
85       if (NOT "${3RDPARTY_${PRODUCT_NAME}_DLL_DIR}" STREQUAL "${3RDPARTY_${PRODUCT_NAME}_DLL_DIR_TMP}")
86         set (3RDPARTY_${PRODUCT_NAME}_DLL "" CACHE FILEPATH "${PRODUCT_NAME} shared library" FORCE)
87       endif()
88     endif()
89
90     if (NOT 3RDPARTY_${PRODUCT_NAME}_DLL OR NOT EXISTS "${3RDPARTY_${PRODUCT_NAME}_DLL}")
91       set (3RDPARTY_${PRODUCT_NAME}_DLL "3RDPARTY_${PRODUCT_NAME}_DLL-NOTFOUND" CACHE FILEPATH "${PRODUCT_NAME} shared library" FORCE)
92
93       find_library (3RDPARTY_${PRODUCT_NAME}_DLL "${LIBRARY_NAME}" PATHS
94                                                                    "${3RDPARTY_${PRODUCT_NAME}_DLL_DIR}"
95                                                                    "${3RDPARTY_${PRODUCT_NAME}_DIR}/bin"
96                                                                    ${3RDPARTY_${PRODUCT_NAME}_ADDITIONAL_PATH_FOR_DLL}
97                                                                    NO_DEFAULT_PATH)
98
99         # second search if previous one do not find anything
100         find_library (3RDPARTY_${PRODUCT_NAME}_DLL "${LIBRARY_NAME}")
101     endif()
102
103     if (NOT DEFINED 3RDPARTY_${PRODUCT_NAME}_DLL_DIR)
104       set (3RDPARTY_${PRODUCT_NAME}_DLL_DIR "" CACHE FILEPATH "The directory containing ${PRODUCT_NAME} shared library" FORCE)
105     endif()
106
107     # shared library path
108     if (3RDPARTY_${PRODUCT_NAME}_DLL AND EXISTS "${3RDPARTY_${PRODUCT_NAME}_DLL}")
109       get_filename_component (3RDPARTY_${PRODUCT_NAME}_DLL_DIR "${3RDPARTY_${PRODUCT_NAME}_DLL}" PATH)
110       set (3RDPARTY_${PRODUCT_NAME}_DLL_DIR "${3RDPARTY_${PRODUCT_NAME}_DLL_DIR}" CACHE FILEPATH "The directory containing ${PRODUCT_NAME} shared library" FORCE)
111     endif()
112   endif()
113
114   if (3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR AND EXISTS "${3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR}")
115     list (APPEND 3RDPARTY_INCLUDE_DIRS "${3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR}")
116   else()
117     list (APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_${PRODUCT_NAME}_INCLUDE_DIR)
118   endif()
119
120   if (3RDPARTY_${PRODUCT_NAME}_LIBRARY AND EXISTS "${3RDPARTY_${PRODUCT_NAME}_LIBRARY}")
121     list (APPEND 3RDPARTY_LIBRARY_DIRS "${3RDPARTY_${PRODUCT_NAME}_LIBRARY_DIR}")
122   else()
123     list (APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_${PRODUCT_NAME}_LIBRARY_DIR)
124   endif()
125
126   if (WIN32)
127     if (3RDPARTY_${PRODUCT_NAME}_DLL OR EXISTS "${3RDPARTY_${PRODUCT_NAME}_DLL}")
128       list (APPEND 3RDPARTY_DLL_DIRS "${3RDPARTY_${PRODUCT_NAME}_DLL_DIR}")
129     else()
130       list (APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_${PRODUCT_NAME}_DLL_DIR)
131     endif()
132   endif()
133
134   set (USED_3RDPARTY_${PRODUCT_NAME}_DIR "")
135
136   if (INSTALL_${PRODUCT_NAME})
137     OCCT_MAKE_OS_WITH_BITNESS()
138     OCCT_MAKE_COMPILER_SHORT_NAME()
139
140     if (WIN32)
141       install (FILES "${3RDPARTY_${PRODUCT_NAME}_DLL}" 
142                CONFIGURATIONS Release
143                DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bin")
144       install (FILES "${3RDPARTY_${PRODUCT_NAME}_DLL}" 
145                CONFIGURATIONS RelWithDebInfo
146                DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bini")
147       install (FILES "${3RDPARTY_${PRODUCT_NAME}_DLL}" 
148                CONFIGURATIONS Debug
149                DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bind")
150
151     else()
152       get_filename_component(ABS_PATH ${3RDPARTY_${PRODUCT_NAME}_LIBRARY} REALPATH)
153       if ("${PRODUCT_NAME}" STREQUAL "FREEIMAGE")
154         get_filename_component(FREEIMLIB ${3RDPARTY_${PRODUCT_NAME}_LIBRARY} NAME)
155         install (FILES "${ABS_PATH}"
156                  CONFIGURATIONS Release
157                  DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/lib"
158                  RENAME ${FREEIMLIB}.3)
159                  install (FILES "${ABS_PATH}"
160                  CONFIGURATIONS RelWithDebInfo
161                  DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/libi"
162                  RENAME ${FREEIMLIB}.3)
163         install (FILES "${ABS_PATH}"
164                  CONFIGURATIONS Debug
165                  DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/libd"
166                  RENAME ${FREEIMLIB}.3)
167       endif()
168       if("${PRODUCT_NAME}" STREQUAL "GL2PS")
169         get_filename_component(GL2PSLIB ${3RDPARTY_${PRODUCT_NAME}_LIBRARY} NAME)
170         install (FILES "${ABS_PATH}"
171                  CONFIGURATIONS Release
172                  DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/lib"
173                  RENAME ${GL2PSLIB}.1)
174         install (FILES "${ABS_PATH}"
175                  CONFIGURATIONS RelWithDebInfo
176                  DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/libi"
177                  RENAME ${GL2PSLIB}.1)
178         install (FILES "${ABS_PATH}"
179                  CONFIGURATIONS Debug
180                  DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/libd"
181                  RENAME ${GL2PSLIB}.1)
182       endif()
183     endif()
184   else()
185     # the library directory for using by the executable
186     if (WIN32)
187       set (USED_3RDPARTY_${PRODUCT_NAME}_DIR "${3RDPARTY_${PRODUCT_NAME}_DLL_DIR}")
188     else()
189       set (USED_3RDPARTY_${PRODUCT_NAME}_DIR "${3RDPARTY_${PRODUCT_NAME}_LIBRARY_DIR}")
190     endif()
191   endif()
192
193   mark_as_advanced (3RDPARTY_${PRODUCT_NAME}_LIBRARY 3RDPARTY_${PRODUCT_NAME}_DLL)
194 endmacro()
195
196 macro (COMPLIANCE_PRODUCT_CONSISTENCY LIBNAME)
197   if (3RDPARTY_${LIBNAME}_DIR AND EXISTS "${3RDPARTY_${LIBNAME}_DIR}")
198     # include dir
199     set (DOES_PATH_CONTAIN FALSE)
200     if (3RDPARTY_${LIBNAME}_INCLUDE_DIR AND EXISTS "${3RDPARTY_${LIBNAME}_INCLUDE_DIR}")
201       string (REGEX MATCH "${3RDPARTY_${LIBNAME}_DIR}" DOES_PATH_CONTAIN "${3RDPARTY_${LIBNAME}_INCLUDE_DIR}")
202     endif()
203     if (NOT DOES_PATH_CONTAIN)
204       set (3RDPARTY_${LIBNAME}_INCLUDE_DIR "" CACHE FILEPATH "The directory containing headers of ${LIBNAME}" FORCE)
205     endif()
206
207     # library dir
208     set (DOES_PATH_CONTAIN FALSE)
209     if (3RDPARTY_${LIBNAME}_LIBRARY_DIR AND EXISTS "${3RDPARTY_${LIBNAME}_LIBRARY_DIR}")
210       string (REGEX MATCH "${3RDPARTY_${LIBNAME}_DIR}" DOES_PATH_CONTAIN "${3RDPARTY_${LIBNAME}_LIBRARY_DIR}")
211     endif()
212     if (NOT DOES_PATH_CONTAIN)
213       set (3RDPARTY_${LIBNAME}_LIBRARY_DIR "" CACHE FILEPATH "The directory containing ${LIBNAME} library" FORCE)
214     endif()
215
216     # shared library dir
217     if (WIN32)
218       set (DOES_PATH_CONTAIN FALSE)
219       if (3RDPARTY_${LIBNAME}_DLL_DIR AND EXISTS "${3RDPARTY_${LIBNAME}_DLL_DIR}")
220         string (REGEX MATCH "${3RDPARTY_${LIBNAME}_DIR}" DOES_PATH_CONTAIN "${3RDPARTY_${LIBNAME}_DLL_DIR}")
221       endif()
222       if (NOT DOES_PATH_CONTAIN)
223         set (3RDPARTY_${LIBNAME}_DLL_DIR "" CACHE FILEPATH "The directory containing ${LIBNAME} shared library" FORCE)
224       endif()
225     endif()
226   endif()
227
228   # check library
229   set (DOES_PATH_CONTAIN FALSE)
230   if (3RDPARTY_${LIBNAME}_LIBRARY_DIR AND EXISTS "${3RDPARTY_${LIBNAME}_LIBRARY_DIR}")
231     if (3RDPARTY_${LIBNAME}_LIBRARY AND EXISTS "${3RDPARTY_${LIBNAME}_LIBRARY}")
232       string (REGEX MATCH "${3RDPARTY_${LIBNAME}_LIBRARY_DIR}" DOES_PATH_CONTAIN "${3RDPARTY_${LIBNAME}_LIBRARY}")
233     endif()
234   endif()
235   if (NOT DOES_PATH_CONTAIN)
236     set (3RDPARTY_${LIBNAME}_LIBRARY "" CACHE FILEPATH "${LIBNAME} library" FORCE)
237   endif()
238
239   # check shared library
240   if (WIN32)
241     set (DOES_PATH_CONTAIN FALSE)
242     if (3RDPARTY_${LIBNAME}_DLL_DIR AND EXISTS "${3RDPARTY_${LIBNAME}_DLL_DIR}")
243       if (3RDPARTY_${LIBNAME}_DLL AND EXISTS "${3RDPARTY_${LIBNAME}_DLL}")
244         string (REGEX MATCH "${3RDPARTY_${LIBNAME}_DLL_DIR}" DOES_PATH_CONTAIN "${3RDPARTY_${LIBNAME}_DLL}")
245       endif()
246     endif()
247     if (NOT DOES_PATH_CONTAIN)
248       set (3RDPARTY_${LIBNAME}_DLL "" CACHE FILEPATH "${LIBNAME} shared library" FORCE)
249     endif()
250   endif()
251 endmacro()