Browse Source

cmake: Fix AutoInclude workaround always being used irrespective of version.

Also fixes Interrogate's reliance on the INTERFACE_INCLUDE_DIRECTORIES target
property before generation time by using a generator expression to determine
Interrogate's include flags.
Sam Edwards 9 years ago
parent
commit
e58697bee4
2 changed files with 12 additions and 18 deletions
  1. 6 11
      cmake/macros/Interrogate.cmake
  2. 6 7
      cmake/modules/AutoInclude.cmake

+ 6 - 11
cmake/macros/Interrogate.cmake

@@ -167,18 +167,13 @@ function(interrogate_sources target output database module)
     endforeach(source)
 
     # Interrogate also needs the include paths, so we'll extract them from the
-    # target:
-    set(include_flags)
-    get_target_property(include_dirs "${target}" INTERFACE_INCLUDE_DIRECTORIES)
-    foreach(include_dir ${include_dirs})
-      # To keep the command-line small, also make this relative:
-      # Note that Interrogate does NOT handle -I paths relative to -srcdir, so
-      # we make them relative to the directory where it's invoked.
-      file(RELATIVE_PATH rel_include_dir "${CMAKE_CURRENT_BINARY_DIR}" "${include_dir}")
-      list(APPEND include_flags "-I${rel_include_dir}")
-    endforeach(include_dir)
+    # target using a generator expression.
+    # 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>")
     # The above must also be included when compiling the resulting _igate.cxx file:
-    include_directories(${include_dirs})
+    include_directories("$<TARGET_PROPERTY:${target},INTERFACE_INCLUDE_DIRECTORIES>")
 
     # Get the compiler definition flags. These must be passed to Interrogate
     # in the same way that they are passed to the compiler so that Interrogate

+ 6 - 7
cmake/modules/AutoInclude.cmake

@@ -6,10 +6,7 @@
 
 # Emulate CMake 2.8.11's CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE behavior if
 # this version doesn't define CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE.
-# CFSworks's version of CMake (2.8.12) doesn't have
-# CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE even though it should be supported,
-# hence test if it's defined (as either ON or OFF) before trying to use it.
-if("${CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE}" STREQUAL "")
+if(CMAKE_VERSION VERSION_LESS 2.8.11)
   # Replace some built-in functions in order to extend their functionality.
   function(add_library target)
     _add_library(${target} ${ARGN})
@@ -26,10 +23,12 @@ if("${CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE}" STREQUAL "")
     get_target_property(target_interface_dirs "${target}" INTERFACE_INCLUDE_DIRECTORIES)
 
     foreach(lib ${ARGN})
-      get_target_property(lib_interface_dirs "${lib}" INTERFACE_INCLUDE_DIRECTORIES)
+      if(TARGET "${lib}")
+        get_target_property(lib_interface_dirs "${lib}" INTERFACE_INCLUDE_DIRECTORIES)
 
-      if(lib_interface_dirs)
-        list(APPEND interface_dirs ${lib_interface_dirs})
+        if(lib_interface_dirs)
+          list(APPEND interface_dirs ${lib_interface_dirs})
+        endif()
       endif()
     endforeach()