1# generated from catkin/cmake/template/pkgConfig.cmake.in 2 3# append elements to a list and remove existing duplicates from the list 4# copied from catkin/cmake/list_append_deduplicate.cmake to keep pkgConfig 5# self contained 6macro(_list_append_deduplicate listname) 7 if(NOT "${ARGN}" STREQUAL "") 8 if(${listname}) 9 list(REMOVE_ITEM ${listname} ${ARGN}) 10 endif() 11 list(APPEND ${listname} ${ARGN}) 12 endif() 13endmacro() 14 15# append elements to a list if they are not already in the list 16# copied from catkin/cmake/list_append_unique.cmake to keep pkgConfig 17# self contained 18macro(_list_append_unique listname) 19 foreach(_item ${ARGN}) 20 list(FIND ${listname} ${_item} _index) 21 if(_index EQUAL -1) 22 list(APPEND ${listname} ${_item}) 23 endif() 24 endforeach() 25endmacro() 26 27# pack a list of libraries with optional build configuration keywords 28# copied from catkin/cmake/catkin_libraries.cmake to keep pkgConfig 29# self contained 30macro(_pack_libraries_with_build_configuration VAR) 31 set(${VAR} "") 32 set(_argn ${ARGN}) 33 list(LENGTH _argn _count) 34 set(_index 0) 35 while(${_index} LESS ${_count}) 36 list(GET _argn ${_index} lib) 37 if("${lib}" MATCHES "^(debug|optimized|general)$") 38 math(EXPR _index "${_index} + 1") 39 if(${_index} EQUAL ${_count}) 40 message(FATAL_ERROR "_pack_libraries_with_build_configuration() the list of libraries '${ARGN}' ends with '${lib}' which is a build configuration keyword and must be followed by a library") 41 endif() 42 list(GET _argn ${_index} library) 43 list(APPEND ${VAR} "${lib}${CATKIN_BUILD_CONFIGURATION_KEYWORD_SEPARATOR}${library}") 44 else() 45 list(APPEND ${VAR} "${lib}") 46 endif() 47 math(EXPR _index "${_index} + 1") 48 endwhile() 49endmacro() 50 51# unpack a list of libraries with optional build configuration keyword prefixes 52# copied from catkin/cmake/catkin_libraries.cmake to keep pkgConfig 53# self contained 54macro(_unpack_libraries_with_build_configuration VAR) 55 set(${VAR} "") 56 foreach(lib ${ARGN}) 57 string(REGEX REPLACE "^(debug|optimized|general)${CATKIN_BUILD_CONFIGURATION_KEYWORD_SEPARATOR}(.+)$" "\\1;\\2" lib "${lib}") 58 list(APPEND ${VAR} "${lib}") 59 endforeach() 60endmacro() 61 62 63if(@PROJECT_NAME@_CONFIG_INCLUDED) 64 return() 65endif() 66set(@PROJECT_NAME@_CONFIG_INCLUDED TRUE) 67 68# set variables for source/devel/install prefixes 69if("@DEVELSPACE@" STREQUAL "TRUE") 70 set(@PROJECT_NAME@_SOURCE_PREFIX @CMAKE_CURRENT_SOURCE_DIR@) 71 set(@PROJECT_NAME@_DEVEL_PREFIX @CATKIN_DEVEL_PREFIX@) 72 set(@PROJECT_NAME@_INSTALL_PREFIX "") 73 set(@PROJECT_NAME@_PREFIX ${@PROJECT_NAME@_DEVEL_PREFIX}) 74else() 75 set(@PROJECT_NAME@_SOURCE_PREFIX "") 76 set(@PROJECT_NAME@_DEVEL_PREFIX "") 77 set(@PROJECT_NAME@_INSTALL_PREFIX @CMAKE_INSTALL_PREFIX@) 78 set(@PROJECT_NAME@_PREFIX ${@PROJECT_NAME@_INSTALL_PREFIX}) 79endif() 80 81# warn when using a deprecated package 82if(NOT "@PROJECT_DEPRECATED@" STREQUAL "") 83 set(_msg "WARNING: package '@PROJECT_NAME@' is deprecated") 84 # append custom deprecation text if available 85 if(NOT "@PROJECT_DEPRECATED@" STREQUAL "TRUE") 86 set(_msg "${_msg} (@PROJECT_DEPRECATED@)") 87 endif() 88 message("${_msg}") 89endif() 90 91# flag project as catkin-based to distinguish if a find_package()-ed project is a catkin project 92set(@PROJECT_NAME@_FOUND_CATKIN_PROJECT TRUE) 93 94if(NOT "@PROJECT_CMAKE_CONFIG_INCLUDE_DIRS@ " STREQUAL " ") 95 set(@PROJECT_NAME@_INCLUDE_DIRS "") 96 set(_include_dirs "@PROJECT_CMAKE_CONFIG_INCLUDE_DIRS@") 97 if(NOT "@PROJECT_URL_BUGTRACKER@ " STREQUAL " ") 98 set(_report "Check the issue tracker '@PROJECT_URL_BUGTRACKER@' and consider creating a ticket if the problem has not been reported yet.") 99 elseif(NOT "@PROJECT_URL_WEBSITE@ " STREQUAL " ") 100 set(_report "Check the website '@PROJECT_URL_WEBSITE@' for information and consider reporting the problem.") 101 else() 102 set(_report "Report the problem to the maintainer '@PROJECT_MAINTAINER@' and request to fix the problem.") 103 endif() 104 foreach(idir ${_include_dirs}) 105 if(IS_ABSOLUTE ${idir} AND IS_DIRECTORY ${idir}) 106 set(include ${idir}) 107 elseif("${idir} " STREQUAL "@CATKIN_GLOBAL_INCLUDE_DESTINATION@ ") 108 get_filename_component(include "${@PROJECT_NAME@_DIR}/../../../@CATKIN_GLOBAL_INCLUDE_DESTINATION@" ABSOLUTE) 109 if(NOT IS_DIRECTORY ${include}) 110 message(FATAL_ERROR "Project '@PROJECT_NAME@' specifies '${idir}' as an include dir, which is not found. It does not exist in '${include}'. ${_report}") 111 endif() 112 else() 113 message(FATAL_ERROR "Project '@PROJECT_NAME@' specifies '${idir}' as an include dir, which is not found. It does neither exist as an absolute directory nor in '@PKG_INCLUDE_PREFIX@/${idir}'. ${_report}") 114 endif() 115 _list_append_unique(@PROJECT_NAME@_INCLUDE_DIRS ${include}) 116 endforeach() 117endif() 118 119set(libraries "@PKG_CONFIG_LIBRARIES@") 120foreach(library ${libraries}) 121 # keep build configuration keywords, target names and absolute libraries as-is 122 if("${library}" MATCHES "^(debug|optimized|general)$") 123 list(APPEND @PROJECT_NAME@_LIBRARIES ${library}) 124 elseif(${library} MATCHES "^-l") 125 list(APPEND @PROJECT_NAME@_LIBRARIES ${library}) 126 elseif(${library} MATCHES "^-") 127 # This is a linker flag/option (like -pthread) 128 # There's no standard variable for these, so create an interface library to hold it 129 if(NOT @PROJECT_NAME@_NUM_DUMMY_TARGETS) 130 set(@PROJECT_NAME@_NUM_DUMMY_TARGETS 0) 131 endif() 132 # Make sure the target name is unique 133 set(interface_target_name "catkin::@PROJECT_NAME@::wrapped-linker-option${@PROJECT_NAME@_NUM_DUMMY_TARGETS}") 134 while(TARGET "${interface_target_name}") 135 math(EXPR @PROJECT_NAME@_NUM_DUMMY_TARGETS "${@PROJECT_NAME@_NUM_DUMMY_TARGETS}+1") 136 set(interface_target_name "catkin::@PROJECT_NAME@::wrapped-linker-option${@PROJECT_NAME@_NUM_DUMMY_TARGETS}") 137 endwhile() 138 add_library("${interface_target_name}" INTERFACE IMPORTED) 139 if("${CMAKE_VERSION}" VERSION_LESS "3.13.0") 140 set_property( 141 TARGET 142 "${interface_target_name}" 143 APPEND PROPERTY 144 INTERFACE_LINK_LIBRARIES "${library}") 145 else() 146 target_link_options("${interface_target_name}" INTERFACE "${library}") 147 endif() 148 list(APPEND @PROJECT_NAME@_LIBRARIES "${interface_target_name}") 149 elseif(TARGET ${library}) 150 list(APPEND @PROJECT_NAME@_LIBRARIES ${library}) 151 elseif(IS_ABSOLUTE ${library}) 152 list(APPEND @PROJECT_NAME@_LIBRARIES ${library}) 153 else() 154 set(lib_path "") 155 set(lib "${library}-NOTFOUND") 156 # since the path where the library is found is returned we have to iterate over the paths manually 157 foreach(path @PKG_CONFIG_LIB_PATHS@) 158 find_library(lib ${library} 159 PATHS ${path} 160 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH) 161 if(lib) 162 set(lib_path ${path}) 163 break() 164 endif() 165 endforeach() 166 if(lib) 167 _list_append_unique(@PROJECT_NAME@_LIBRARY_DIRS ${lib_path}) 168 list(APPEND @PROJECT_NAME@_LIBRARIES ${lib}) 169 else() 170 # as a fall back for non-catkin libraries try to search globally 171 find_library(lib ${library}) 172 if(NOT lib) 173 message(FATAL_ERROR "Project '${PROJECT_NAME}' tried to find library '${library}'. The library is neither a target nor built/installed properly. Did you compile project '@PROJECT_NAME@'? Did you find_package() it before the subdirectory containing its code is included?") 174 endif() 175 list(APPEND @PROJECT_NAME@_LIBRARIES ${lib}) 176 endif() 177 endif() 178endforeach() 179 180set(@PROJECT_NAME@_EXPORTED_TARGETS "@PKG_EXPORTED_TARGETS@") 181# create dummy targets for exported code generation targets to make life of users easier 182foreach(t ${@PROJECT_NAME@_EXPORTED_TARGETS}) 183 if(NOT TARGET ${t}) 184 add_custom_target(${t}) 185 endif() 186endforeach() 187 188set(depends "@PROJECT_DEPENDENCIES@") 189foreach(depend ${depends}) 190 string(REPLACE " " ";" depend_list ${depend}) 191 # the package name of the dependency must be kept in a unique variable so that it is not overwritten in recursive calls 192 list(GET depend_list 0 @PROJECT_NAME@_dep) 193 list(LENGTH depend_list count) 194 if(${count} EQUAL 1) 195 # simple dependencies must only be find_package()-ed once 196 if(NOT ${@PROJECT_NAME@_dep}_FOUND) 197 find_package(${@PROJECT_NAME@_dep} REQUIRED NO_MODULE) 198 endif() 199 else() 200 # dependencies with components must be find_package()-ed again 201 list(REMOVE_AT depend_list 0) 202 find_package(${@PROJECT_NAME@_dep} REQUIRED NO_MODULE ${depend_list}) 203 endif() 204 _list_append_unique(@PROJECT_NAME@_INCLUDE_DIRS ${${@PROJECT_NAME@_dep}_INCLUDE_DIRS}) 205 206 # merge build configuration keywords with library names to correctly deduplicate 207 _pack_libraries_with_build_configuration(@PROJECT_NAME@_LIBRARIES ${@PROJECT_NAME@_LIBRARIES}) 208 _pack_libraries_with_build_configuration(_libraries ${${@PROJECT_NAME@_dep}_LIBRARIES}) 209 _list_append_deduplicate(@PROJECT_NAME@_LIBRARIES ${_libraries}) 210 # undo build configuration keyword merging after deduplication 211 _unpack_libraries_with_build_configuration(@PROJECT_NAME@_LIBRARIES ${@PROJECT_NAME@_LIBRARIES}) 212 213 _list_append_unique(@PROJECT_NAME@_LIBRARY_DIRS ${${@PROJECT_NAME@_dep}_LIBRARY_DIRS}) 214 list(APPEND @PROJECT_NAME@_EXPORTED_TARGETS ${${@PROJECT_NAME@_dep}_EXPORTED_TARGETS}) 215endforeach() 216 217set(pkg_cfg_extras "@PKG_CFG_EXTRAS@") 218foreach(extra ${pkg_cfg_extras}) 219 if(NOT IS_ABSOLUTE ${extra}) 220 set(extra ${@PROJECT_NAME@_DIR}/${extra}) 221 endif() 222 include(${extra}) 223endforeach() 224