|
| 1 | +# Copyright 2015 Open Source Robotics Foundation, Inc. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +macro(find_ros1_package name) |
| 16 | + cmake_parse_arguments(_ARG "REQUIRED" "" "" ${ARGN}) |
| 17 | + if(_ARG_UNPARSED_ARGUMENTS) |
| 18 | + message(FATAL_ERROR |
| 19 | + "find_ros1_package() called with unused arguments: " |
| 20 | + "${ARG_UNPARSED_ARGUMENTS}") |
| 21 | + endif() |
| 22 | + |
| 23 | + find_package(PkgConfig REQUIRED) |
| 24 | + # the error message of pkg_check_modules for not found required modules |
| 25 | + # doesn't include the module name which is not helpful |
| 26 | + pkg_check_modules(ros1_${name} ${name}) |
| 27 | + if(NOT ros1_${name}_FOUND) |
| 28 | + if(_ARG_REQUIRED) |
| 29 | + message(FATAL_ERROR |
| 30 | + "find_ros1_package() failed to find '${name}' using " |
| 31 | + "pkg_check_modules()") |
| 32 | + endif() |
| 33 | + else() |
| 34 | + set(_libraries "${ros1_${name}_LIBRARIES}") |
| 35 | + # Prior to catkin 0.7.7, dependent libraries in the pkg-config file were always generated |
| 36 | + # in the form "-l:/absolute/path/to/library". Because of the leading "-l", this made |
| 37 | + # them show up in ${ros1_${name}_LIBRARIES}. catkin 0.7.7 and later has changed this to |
| 38 | + # just be an absolute path (of the form "/absolute/path/to/library"), so we now have to |
| 39 | + # look through the LDFLAGS_OTHER and add those to the libraries that we need to link with. |
| 40 | + foreach(_flag ${ros1_${name}_LDFLAGS_OTHER}) |
| 41 | + if(IS_ABSOLUTE ${_flag}) |
| 42 | + list(APPEND _libraries "${_flag}") |
| 43 | + endif() |
| 44 | + endforeach() |
| 45 | + set(_library_dirs "${ros1_${name}_LIBRARY_DIRS}") |
| 46 | + set(ros1_${name}_LIBRARIES "") |
| 47 | + set(ros1_${name}_LIBRARY_DIRS "") |
| 48 | + foreach(_library ${_libraries}) |
| 49 | + string(SUBSTRING "${_library}" 0 1 _prefix) |
| 50 | + if("${_prefix} " STREQUAL ": ") |
| 51 | + string(SUBSTRING "${_library}" 1 -1 _rest) |
| 52 | + list(APPEND ros1_${name}_LIBRARIES ${_rest}) |
| 53 | + elseif(IS_ABSOLUTE ${_library}) |
| 54 | + list(APPEND ros1_${name}_LIBRARIES ${_library}) |
| 55 | + else() |
| 56 | + set(_lib "${_library}-NOTFOUND") |
| 57 | + set(_lib_path "") |
| 58 | + # since the path where the library is found is not returned |
| 59 | + # this has to be done for each path separately |
| 60 | + foreach(_path ${_library_dirs}) |
| 61 | + find_library(_lib ${_library} |
| 62 | + PATHS ${_path} |
| 63 | + NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH) |
| 64 | + if(_lib) |
| 65 | + set(_lib_path ${_path}) |
| 66 | + break() |
| 67 | + endif() |
| 68 | + endforeach() |
| 69 | + if(_lib) |
| 70 | + list(APPEND ros1_${name}_LIBRARIES ${_lib}) |
| 71 | + list_append_unique(ros1_${name}_LIBRARY_DIRS ${_lib_path}) |
| 72 | + else() |
| 73 | + # as a fall back try to search globally |
| 74 | + find_library(_lib ${_library}) |
| 75 | + if(NOT _lib) |
| 76 | + message(FATAL_ERROR "pkg-config module '${name}' failed to find library '${_library}'") |
| 77 | + endif() |
| 78 | + list(APPEND ros1_${name}_LIBRARIES ${_lib}) |
| 79 | + endif() |
| 80 | + endif() |
| 81 | + endforeach() |
| 82 | + endif() |
| 83 | +endmacro() |
0 commit comments