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