Description: <short summary of the patch>
 TODO: Put a short summary on the line above and replace this paragraph
 with a longer explanation of this change. Complete the meta-information
 with other relevant fields (see below for details). To make it easier, the
 information below has been extracted from the changelog. Adjust it or drop
 it.
 .
 rock-master-20.01-ruby-orogen (1.1-1) UNRELEASED; urgency=medium
 .
   * Initial release (Closes: #nnnn)
Author: MAINTAINER <rock-user@rock.dfki.uni-bremen.de>

---
The information above should follow the Patch Tagging Guidelines, please
checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:

Origin: <vendor|upstream|other>, <url of original patch>
Bug: <url in upstream bugtracker>
Bug-Debian: https://bugs.debian.org/<bugnumber>
Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
Forwarded: <no|not-needed|url proving that it has been forwarded>
Reviewed-By: <name and email of someone who approved the patch>
Last-Update: 2020-04-23

--- rock-master-20.01-ruby-orogen-1.1.orig/lib/orogen/gen/base.rb
+++ rock-master-20.01-ruby-orogen-1.1/lib/orogen/gen/base.rb
@@ -88,12 +88,26 @@ module OroGen
                     result << "list(APPEND DEPS_CFLAGS_OTHER ${#{s.var_name}_CFLAGS_OTHER})"
                 end
                 if s.in_context?(context, 'link')
-                    result << "link_directories(${#{s.var_name}_LIBRARY_DIRS})"
+                    result << "list(APPEND DEPS_LINK_LIBRARIES ${#{s.var_name}_LIBRARY_DIRS})"
                 end
                 result
             end.join("\n") + "\n"
             cmake_txt += "list(REMOVE_DUPLICATES DEPS_CFLAGS_OTHER)\n"
             cmake_txt += "add_definitions(${DEPS_CFLAGS_OTHER})\n"
+            cmake_txt += "foreach(LIB ${DEPS_LINK_LIBRARIES})\n"
+            cmake_txt += "    # This is a workaround, but only fixes the issues\n"
+            cmake_txt += "    # when the same install prefix is being used\n"
+            cmake_txt += "    # Aim for separate prefixes for include and library directories\n"
+            cmake_txt += "    if(\"${LIB}\" MATCHES \"^/opt/rock/\")\n"
+            cmake_txt += "        list(APPEND DEPS_SYSTEM_LINK_DIR ${LIB})\n"
+            cmake_txt += "    else()\n"
+            cmake_txt += "        link_directories(${LIB})\n"
+            cmake_txt += "    endif()\n"
+            cmake_txt += "endforeach()\n"
+            cmake_txt += ""
+            cmake_txt += "foreach(LIB ${DEPS_SYSTEM_LINK_DIR})\n"
+            cmake_txt += "    link_directories(${LIB})\n"
+            cmake_txt += "endforeach()\n"
             cmake_txt
         end
 
--- rock-master-20.01-ruby-orogen-1.1.orig/lib/orogen/gen/typekit.rb
+++ rock-master-20.01-ruby-orogen-1.1/lib/orogen/gen/typekit.rb
@@ -637,6 +637,8 @@ module OroGen
             attr_accessor :version
             # The set of include directories that should be considered in #load
             attr_accessor :include_dirs
+            # The set of system include directories that should be considered in #load
+            attr_accessor :system_include_dirs
             # The array of includes that have been loaded
             attr_reader :included_files
 
@@ -731,7 +733,13 @@ module OroGen
 
                 options = Kernel.validate_options options, :link => true
                 self.used_libraries << library
+                self.system_include_dirs ||= Set.new
                 self.include_dirs |= library.include_dirs.to_set
+                self.include_dirs.each do |dir|
+                    if library.raw_cflags.include?("-isystem#{dir}")
+                        self.system_include_dirs << dir
+                    end
+                end
                 if options[:link]
                     self.linked_used_libraries << library
                 end
@@ -1199,7 +1207,9 @@ module OroGen
                     end
                 end
 
-                include_dirs = self.include_dirs
+                self.system_include_dirs ||= Set.new
+                include_dirs = self.include_dirs.reject {|dir| self.system_include_dirs.include?(dir) }
+                system_include_dirs = self.system_include_dirs
 
                 # Get the full path for +file+
                 file =
@@ -1207,6 +1217,7 @@ module OroGen
                         File.expand_path(file)
                     else # File from used libraries/task libraries
                         dir = include_dirs.find { |dir| File.file?(File.join(dir, file)) }
+                        dir = system_include_dirs.find { |dir| File.file?(File.join(dir, file)) } unless dir
                         if !dir
                             raise LoadError, "cannot find #{file} in #{include_dirs.to_a.join(":")}"
                         end
@@ -1220,7 +1231,9 @@ module OroGen
 
                 # And resolve it to an include statement
                 include_path = include_dirs.map { |d| Pathname.new(d) }
-                inc = resolve_full_include_path_to_relative(file, include_path)
+                system_include_path = system_include_dirs.map { |d| Pathname.new(d) }
+
+                inc = resolve_full_include_path_to_relative(file, include_path + system_include_path)
                 included_files << inc
                 user_options[:rawflags] = self.used_libraries.
                     map { |lib| lib.raw_cflags_only_other }.
