Browse Source

CMake: Make sure Interrogate doesn't see package include directories

Sam Edwards 7 years ago
parent
commit
2399655920
2 changed files with 22 additions and 2 deletions
  1. 16 1
      cmake/macros/Interrogate.cmake
  2. 6 1
      cmake/macros/PackageConfig.cmake

+ 16 - 1
cmake/macros/Interrogate.cmake

@@ -166,10 +166,25 @@ function(interrogate_sources target output database language_flags)
   # Interrogate also needs the include paths, so we'll extract them from the
   # target. These are available via a generator expression.
 
+  # When we read the INTERFACE_INCLUDE_DIRECTORIES property, we need to read it
+  # from a target that has the IS_INTERROGATE=1 property.
+  # (See PackageConfig.cmake for an explanation why.)
+  # The problem is, custom commands are not targets, so we can't put target
+  # properties on them. And if you try to use the $<TARGET_PROPERTY:prop>
+  # generator expression from the context of a custom command, it'll instead
+  # read the property from the most recent actual target. As a workaround for
+  # this, we create a fake target with the IS_INTERROGATE property set and pull
+  # the INTERFACE_INCLUDE_DIRECTORIES property out through that.
+  # I hate it, but such is CMake.
+  add_custom_target(${target}_igate_internal EXCLUDE_FROM_ALL)
+  set_target_properties(${target}_igate_internal PROPERTIES
+    IS_INTERROGATE 1
+    INTERFACE_INCLUDE_DIRECTORIES "$<TARGET_PROPERTY:${target},INTERFACE_INCLUDE_DIRECTORIES>")
+
   # Note, the \t is a workaround for a CMake bug where using a plain space in
   # a JOIN will cause it to be escaped. Tabs are not escaped and will
   # separate correctly.
-  set(include_flags "-I$<JOIN:$<TARGET_PROPERTY:${target},INTERFACE_INCLUDE_DIRECTORIES>,\t-I>")
+  set(include_flags "-I$<JOIN:$<TARGET_PROPERTY:${target}_igate_internal,INTERFACE_INCLUDE_DIRECTORIES>,\t-I>")
   # The above must also be included when compiling the resulting _igate.cxx file:
   include_directories("$<TARGET_PROPERTY:${target},INTERFACE_INCLUDE_DIRECTORIES>")
 

+ 6 - 1
cmake/macros/PackageConfig.cmake

@@ -231,8 +231,13 @@ macro(target_use_packages target)
 
   foreach(lib ${libs})
     if(HAVE_${lib})
-      target_include_directories("${target}" PUBLIC ${_${lib}_INCLUDES})
       target_link_libraries("${target}" ${_${lib}_LIBRARIES})
+
+      # This is gross, but we actually want to hide package include directories
+      # from Interrogate to make sure it relies on parser-inc instead, so we'll
+      # use some generator expressions to do that.
+      target_include_directories("${target}" PUBLIC
+        $<$<NOT:$<BOOL:$<TARGET_PROPERTY:IS_INTERROGATE>>>:${_${lib}_INCLUDES}>)
     endif()
   endforeach(lib)
 endmacro(target_use_packages)