Medical Imaging Interaction Toolkit  2018.4.99-4c24e3cb
Medical Imaging Interaction Toolkit
mitkFunctionGetLibrarySearchPaths.cmake
Go to the documentation of this file.
1 #! Helper function that gets all library search paths.
2 #!
3 #! Usage:
4 #!
5 #! mitkFunctionGetLibrarySearchPaths(search_path intermediate_dir [DEBUG|MINSIZEREL|RELWITHDEBINFO])
6 #!
7 #!
8 #! The function creates the variable ${search_path}. The variable intermediate_dir contains
9 #! paths that should be added to the search_path but should not be checked for existance,
10 #! because the are not yet created. The option DEBUG, MINSIZEREL or RELWITHDEBINFO can be used to indicate that
11 #! not the paths for release configuration are requested but the debug, min size release or "release with debug info"
12 #! paths.
13 #!
14 
15 function(mitkFunctionGetLibrarySearchPaths search_path intermediate_dir)
16 
17  cmake_parse_arguments(PARSE_ARGV 2 GLS "RELEASE;DEBUG;MINSIZEREL;RELWITHDEBINFO" "" "")
18 
19  set(_dir_candidates
20  "${MITK_CMAKE_RUNTIME_OUTPUT_DIRECTORY}"
21  "${MITK_CMAKE_RUNTIME_OUTPUT_DIRECTORY}/plugins"
22  "${MITK_CMAKE_LIBRARY_OUTPUT_DIRECTORY}"
23  "${MITK_CMAKE_LIBRARY_OUTPUT_DIRECTORY}/plugins"
24  )
25  if(MITK_EXTERNAL_PROJECT_PREFIX)
26  list(APPEND _dir_candidates
27  "${MITK_EXTERNAL_PROJECT_PREFIX}/bin"
28  "${MITK_EXTERNAL_PROJECT_PREFIX}/lib"
29  )
30  endif()
31 
32  # Determine the Qt5 library installation prefix
33  set(_qmake_location )
34  if(MITK_USE_Qt5 AND TARGET ${Qt5Core_QMAKE_EXECUTABLE})
35  get_property(_qmake_location TARGET ${Qt5Core_QMAKE_EXECUTABLE}
36  PROPERTY IMPORT_LOCATION)
37  endif()
38  if(_qmake_location)
39  if(NOT _qt_install_libs)
40  if(WIN32)
41  execute_process(COMMAND ${_qmake_location} -query QT_INSTALL_BINS
42  OUTPUT_VARIABLE _qt_install_libs
43  OUTPUT_STRIP_TRAILING_WHITESPACE)
44  else()
45  execute_process(COMMAND ${_qmake_location} -query QT_INSTALL_LIBS
46  OUTPUT_VARIABLE _qt_install_libs
47  OUTPUT_STRIP_TRAILING_WHITESPACE)
48  endif()
49  file(TO_CMAKE_PATH "${_qt_install_libs}" _qt_install_libs)
50  set(_qt_install_libs ${_qt_install_libs} CACHE INTERNAL "Qt library installation prefix" FORCE)
51  endif()
52  if(_qt_install_libs)
53  list(APPEND _dir_candidates ${_qt_install_libs})
54  endif()
55  elseif(MITK_USE_Qt5)
56  message(WARNING "The qmake executable could not be found.")
57  endif()
58 
59  get_property(_additional_paths GLOBAL PROPERTY MITK_ADDITIONAL_LIBRARY_SEARCH_PATHS)
60 
61  if(TARGET OpenSSL::SSL)
62  if(GLS_DEBUG)
63  get_target_property(_openssl_location OpenSSL::SSL IMPORTED_LOCATION_DEBUG)
64  else()
65  get_target_property(_openssl_location OpenSSL::SSL IMPORTED_LOCATION_RELEASE)
66  endif()
67  if(_openssl_location)
68  get_filename_component(_openssl_location ${_openssl_location} DIRECTORY)
69  set(_openssl_location "${_openssl_location}/../../bin")
70  if(EXISTS ${_openssl_location})
71  get_filename_component(_openssl_location ${_openssl_location} ABSOLUTE)
72  list(APPEND _dir_candidates ${_openssl_location})
73  endif()
74  endif()
75  endif()
76 
77  if(MITK_USE_HDF5)
78  FIND_PACKAGE(HDF5 COMPONENTS C HL NO_MODULE REQUIRED shared)
79  get_target_property(_location hdf5-shared LOCATION)
80  get_filename_component(_location ${_location} PATH)
81  list(APPEND _additional_paths ${_location})
82 
83  # This is a work-around. The hdf5-config.cmake file is not robust enough
84  # to be included several times via find_pakcage calls.
85  set(HDF5_LIBRARIES ${HDF5_LIBRARIES} PARENT_SCOPE)
86  endif()
87  if(MITK_USE_Vigra)
88  # we cannot use _find_package(Vigra) here because the vigra-config.cmake file
89  # always includes the target-exports files without using an include guard. This
90  # would lead to errors when another find_package(Vigra) call is processed. The
91  # (bad) assumption here is that for the time being, only the Classification module
92  # is using Vigra.
93  if(UNIX)
94  list(APPEND _additional_paths ${Vigra_DIR}/lib)
95  else()
96  list(APPEND _additional_paths ${Vigra_DIR}/bin)
97  endif()
98  endif()
99 
100  if(_additional_paths)
101  list(APPEND _dir_candidates ${_additional_paths})
102  endif()
103 
104  # The code below is sub-optimal. It makes assumptions about
105  # the structure of the build directories, pointed to by
106  # the *_DIR variables. Instead, we should rely on package
107  # specific "LIBRARY_DIRS" variables, if they exist.
108  if(WIN32)
109  list(APPEND _dir_candidates "${ITK_DIR}/bin")
110  endif()
111 
112  if(MITK_USE_MatchPoint)
113  if(WIN32)
114  list(APPEND _dir_candidates "${MatchPoint_DIR}/bin")
115  else()
116  list(APPEND _dir_candidates "${MatchPoint_DIR}/lib")
117  endif()
118  endif()
119 
120  # If OpenCV is built within the MITK superbuild set the binary directory
121  # according to the lib path provided by OpenCV.
122  # In the case where an external OpenCV is provided use the binary directory
123  # of this OpenCV directory
124  if(MITK_USE_OpenCV)
125  if(WIN32)
126  if (EXISTS ${OpenCV_LIB_PATH})
127  list(APPEND _dir_candidates "${OpenCV_LIB_PATH}/../bin") # OpenCV is built in superbuild
128  else()
129  list(APPEND _dir_candidates "${OpenCV_DIR}/bin") # External OpenCV build is used
130  endif()
131  endif()
132  endif()
133 
134  if(MITK_USE_Python3)
135  list(APPEND _dir_candidates "${CTK_DIR}/CMakeExternals/Install/bin")
136  get_filename_component(_python_dir "${Python3_EXECUTABLE}" DIRECTORY)
137  list(APPEND _dir_candidates "${_python_dir}")
138  endif()
139 
140  if(MITK_USE_TOF_PMDO3 OR MITK_USE_TOF_PMDCAMCUBE OR MITK_USE_TOF_PMDCAMBOARD)
141  list(APPEND _dir_candidates "${MITK_PMD_SDK_DIR}/plugins" "${MITK_PMD_SDK_DIR}/bin")
142  endif()
143 
144  if(MITK_USE_CTK)
145  list(APPEND _dir_candidates "${CTK_LIBRARY_DIRS}")
146  foreach(_ctk_library ${CTK_LIBRARIES})
147  if(${_ctk_library}_LIBRARY_DIRS)
148  list(APPEND _dir_candidates "${${_ctk_library}_LIBRARY_DIRS}")
149  endif()
150  endforeach()
151  endif()
152 
153  if(MITK_USE_BLUEBERRY)
154  if(DEFINED CTK_PLUGIN_RUNTIME_OUTPUT_DIRECTORY)
155  if(IS_ABSOLUTE "${CTK_PLUGIN_RUNTIME_OUTPUT_DIRECTORY}")
156  list(APPEND _dir_candidates "${CTK_PLUGIN_RUNTIME_OUTPUT_DIRECTORY}")
157  else()
158  list(APPEND _dir_candidates "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CTK_PLUGIN_RUNTIME_OUTPUT_DIRECTORY}")
159  endif()
160  endif()
161  endif()
162 
163  if(MITK_LIBRARY_DIRS)
164  list(APPEND _dir_candidates ${MITK_LIBRARY_DIRS})
165  endif()
166 
167  ###################################################################
168  #get the search paths added by the mitkFunctionAddLibrarySearchPath
169  file(GLOB _additional_path_info_files "${MITK_SUPERBUILD_BINARY_DIR}/MITK-AdditionalLibPaths/*.cmake")
170 
171  foreach(_additional_path_info_file ${_additional_path_info_files})
172  get_filename_component(_additional_info_name ${_additional_path_info_file} NAME_WE)
173  include(${_additional_path_info_file})
174  if(GLS_DEBUG)
175  list(APPEND _dir_candidates ${${_additional_info_name}_ADDITIONAL_DEBUG_LIBRARY_SEARCH_PATHS})
176  elseif(GLS_MINSIZEREL)
177  list(APPEND _dir_candidates ${${_additional_info_name}_ADDITIONAL_MINSIZEREL_LIBRARY_SEARCH_PATHS})
178  elseif(GLS_RELWITHDEBINFO)
179  list(APPEND _dir_candidates ${${_additional_info_name}_ADDITIONAL_RELWITHDEBINFO_LIBRARY_SEARCH_PATHS})
180  else() #Release
181  list(APPEND _dir_candidates ${${_additional_info_name}_ADDITIONAL_RELEASE_LIBRARY_SEARCH_PATHS})
182  endif()
183  endforeach(_additional_path_info_file ${_additional_path_info_files})
184 
185 
186  ###############################################
187  #sanitize all candidates and compile final list
188  list(REMOVE_DUPLICATES _dir_candidates)
189 
190  set(_search_dirs )
191  foreach(_dir ${_dir_candidates})
192  if(EXISTS "${_dir}/${intermediate_dir}")
193  list(APPEND _search_dirs "${_dir}/${intermediate_dir}")
194  else()
195  list(APPEND _search_dirs "${_dir}")
196  endif()
197  endforeach()
198 
199  # Special handling for "internal" search dirs. The intermediate directory
200  # might not have been created yet, so we can't check for its existence.
201  # Hence we just add it for Windows without checking.
202  set(_internal_search_dirs "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/plugins")
203  if(WIN32)
204  foreach(_dir ${_internal_search_dirs})
205  set(_search_dirs "${_dir}/${intermediate_dir}" ${_search_dirs})
206  endforeach()
207  else()
208  set(_search_dirs ${_internal_search_dirs} ${_search_dirs})
209  endif()
210  list(REMOVE_DUPLICATES _search_dirs)
211 
212  set(${search_path} ${_search_dirs} PARENT_SCOPE)
213 endfunction()
mitkFunctionGetLibrarySearchPaths(search_path, intermediate_dir)
const std::string TARGET