Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkFunctionGetLibrarySearchPaths.cmake
Go to the documentation of this file.
1 function(mitkFunctionGetLibrarySearchPaths search_path intermediate_dir)
2 
3  set(_dir_candidates
4  "${MITK_CMAKE_RUNTIME_OUTPUT_DIRECTORY}"
5  "${MITK_CMAKE_RUNTIME_OUTPUT_DIRECTORY}/plugins"
6  "${MITK_CMAKE_LIBRARY_OUTPUT_DIRECTORY}"
7  "${MITK_CMAKE_LIBRARY_OUTPUT_DIRECTORY}/plugins"
8  )
9  if(MITK_EXTERNAL_PROJECT_PREFIX)
10  list(APPEND _dir_candidates
11  "${MITK_EXTERNAL_PROJECT_PREFIX}/bin"
12  "${MITK_EXTERNAL_PROJECT_PREFIX}/lib"
13  )
14  endif()
15 
16  # Determine the Qt5 library installation prefix
17  set(_qmake_location )
18  if(MITK_USE_Qt5 AND TARGET ${Qt5Core_QMAKE_EXECUTABLE})
19  get_property(_qmake_location TARGET ${Qt5Core_QMAKE_EXECUTABLE}
20  PROPERTY IMPORT_LOCATION)
21  endif()
22  if(_qmake_location)
23  if(NOT _qt_install_libs)
24  if(WIN32)
25  execute_process(COMMAND ${_qmake_location} -query QT_INSTALL_BINS
26  OUTPUT_VARIABLE _qt_install_libs
27  OUTPUT_STRIP_TRAILING_WHITESPACE)
28  else()
29  execute_process(COMMAND ${_qmake_location} -query QT_INSTALL_LIBS
30  OUTPUT_VARIABLE _qt_install_libs
31  OUTPUT_STRIP_TRAILING_WHITESPACE)
32  endif()
33  file(TO_CMAKE_PATH "${_qt_install_libs}" _qt_install_libs)
34  set(_qt_install_libs ${_qt_install_libs} CACHE INTERNAL "Qt library installation prefix" FORCE)
35  endif()
36  if(_qt_install_libs)
37  list(APPEND _dir_candidates ${_qt_install_libs})
38  endif()
39  elseif(MITK_USE_Qt5)
40  message(WARNING "The qmake executable could not be found.")
41  endif()
42 
43  get_property(_additional_paths GLOBAL PROPERTY MITK_ADDITIONAL_LIBRARY_SEARCH_PATHS)
44 
45  if(MITK_USE_HDF5)
46  FIND_PACKAGE(HDF5 COMPONENTS C HL NO_MODULE REQUIRED shared)
47  get_target_property(_location hdf5-shared LOCATION)
48  get_filename_component(_location ${_location} PATH)
49  list(APPEND _additional_paths ${_location})
50 
51  # This is a work-around. The hdf5-config.cmake file is not robust enough
52  # to be included several times via find_pakcage calls.
53  set(HDF5_LIBRARIES ${HDF5_LIBRARIES} PARENT_SCOPE)
54  endif()
55  if(MITK_USE_Vigra)
56  # we cannot use _find_package(Vigra) here because the vigra-config.cmake file
57  # always includes the target-exports files without using an include guard. This
58  # would lead to errors when another find_package(Vigra) call is processed. The
59  # (bad) assumption here is that for the time being, only the Classification module
60  # is using Vigra.
61  if(UNIX)
62  list(APPEND _additional_paths ${Vigra_DIR}/lib)
63  else()
64  list(APPEND _additional_paths ${Vigra_DIR}/bin)
65  endif()
66  endif()
67 
68  if(_additional_paths)
69  list(APPEND _dir_candidates ${_additional_paths})
70  endif()
71 
72  # The code below is sub-optimal. It makes assumptions about
73  # the structure of the build directories, pointed to by
74  # the *_DIR variables. Instead, we should rely on package
75  # specific "LIBRARY_DIRS" variables, if they exist.
76  if(WIN32)
77  if(SOFA_DIR)
78  list(APPEND _dir_candidates "${SOFA_DIR}/bin")
79  endif()
80  list(APPEND _dir_candidates "${ITK_DIR}/bin")
81  else()
82  if(SOFA_DIR)
83  list(APPEND _dir_candidates "${SOFA_DIR}/lib")
84  endif()
85  endif()
86 
87  if(MITK_USE_MatchPoint)
88  if(WIN32)
89  list(APPEND _dir_candidates "${MatchPoint_DIR}/bin")
90  else()
91  list(APPEND _dir_candidates "${MatchPoint_DIR}/lib")
92  endif()
93  endif()
94 
95  if(OpenCV_DIR)
96  set(_opencv_link_directories
97  "${OpenCV_LIB_DIR_DBG}"
98  "${OpenCV_LIB_DIR_OPT}"
99  "${OpenCV_3RDPARTY_LIB_DIR_DBG}"
100  "${OpenCV_3RDPARTY_LIB_DIR_OPT}")
101  list(REMOVE_DUPLICATES _opencv_link_directories)
102  if(WIN32)
103  foreach(_opencv_link_directory ${_opencv_link_directories})
104  list(APPEND _dir_candidates "${_opencv_link_directory}/../bin")
105  endforeach()
106  else()
107  list(APPEND _dir_candidates ${_opencv_link_directories})
108  endif()
109  endif()
110 
111  if(MITK_USE_Python)
112  list(APPEND _dir_candidates "${CTK_DIR}/CMakeExternals/Install/bin")
113  list(APPEND _dir_candidates "${MITK_EXTERNAL_PROJECT_PREFIX}/lib/python2.7/bin")
114  endif()
115 
116  if(MITK_USE_TOF_PMDO3 OR MITK_USE_TOF_PMDCAMCUBE OR MITK_USE_TOF_PMDCAMBOARD)
117  list(APPEND _dir_candidates "${MITK_PMD_SDK_DIR}/plugins" "${MITK_PMD_SDK_DIR}/bin")
118  endif()
119 
120  if(MITK_USE_CTK)
121  list(APPEND _dir_candidates "${CTK_LIBRARY_DIRS}")
122  foreach(_ctk_library ${CTK_LIBRARIES})
123  if(${_ctk_library}_LIBRARY_DIRS)
124  list(APPEND _dir_candidates "${${_ctk_library}_LIBRARY_DIRS}")
125  endif()
126  endforeach()
127  endif()
128 
129  if(MITK_USE_BLUEBERRY)
130  if(DEFINED CTK_PLUGIN_RUNTIME_OUTPUT_DIRECTORY)
131  if(IS_ABSOLUTE "${CTK_PLUGIN_RUNTIME_OUTPUT_DIRECTORY}")
132  list(APPEND _dir_candidates "${CTK_PLUGIN_RUNTIME_OUTPUT_DIRECTORY}")
133  else()
134  list(APPEND _dir_candidates "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CTK_PLUGIN_RUNTIME_OUTPUT_DIRECTORY}")
135  endif()
136  endif()
137  endif()
138 
139  if(MITK_LIBRARY_DIRS)
140  list(APPEND _dir_candidates ${MITK_LIBRARY_DIRS})
141  endif()
142 
143  list(REMOVE_DUPLICATES _dir_candidates)
144 
145  set(_search_dirs )
146  foreach(_dir ${_dir_candidates})
147  if(EXISTS "${_dir}/${intermediate_dir}")
148  list(APPEND _search_dirs "${_dir}/${intermediate_dir}")
149  else()
150  list(APPEND _search_dirs "${_dir}")
151  endif()
152  endforeach()
153 
154  # Special handling for "internal" search dirs. The intermediate directory
155  # might not have been created yet, so we can't check for its existence.
156  # Hence we just add it for Windows without checking.
157  set(_internal_search_dirs "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/plugins")
158  if(WIN32)
159  foreach(_dir ${_internal_search_dirs})
160  set(_search_dirs "${_dir}/${intermediate_dir}" ${_search_dirs})
161  endforeach()
162  else()
163  set(_search_dirs ${_internal_search_dirs} ${_search_dirs})
164  endif()
165  list(REMOVE_DUPLICATES _search_dirs)
166 
167  set(${search_path} ${_search_dirs} PARENT_SCOPE)
168 endfunction()
mitkFunctionGetLibrarySearchPaths(search_path, intermediate_dir)
const std::string TARGET