Переглянути джерело

Massively update CMake's Interrogate macro. This gets several modules to build...

Sam Edwards 12 роки тому
батько
коміт
72c180a82c
1 змінених файлів з 71 додано та 27 видалено
  1. 71 27
      cmake/macros/Interrogate.cmake

+ 71 - 27
cmake/macros/Interrogate.cmake

@@ -17,13 +17,21 @@ if(INTERROGATE_VERBOSE)
   list(APPEND IGATE_FLAGS "-v")
   list(APPEND IGATE_FLAGS "-v")
 endif()
 endif()
 
 
+if(INTERROGATE_PYTHON_INTERFACE AND PYTHON_NATIVE)
+  list(APPEND IGATE_FLAGS -python-native)
+endif()
+
 set(IMOD_FLAGS ${INTERROGATE_MODULE_OPTIONS})
 set(IMOD_FLAGS ${INTERROGATE_MODULE_OPTIONS})
 
 
+# This is a list of filename extensions that Interrogate will allow in the
+# sources lists.
+set(INTERROGATE_EXTENSIONS "cxx;h")
+
 #
 #
 # Function: target_interrogate(target [ALL] [source1 [source2 ...]])
 # Function: target_interrogate(target [ALL] [source1 [source2 ...]])
-# NB. This doesn't actually invoke interrogate, but merely adds the
-# sources to the list of scan sources associated with the target.
-# Interrogate will be invoked when add_python_module is called.
+# Currently, this adds the resultant TARGET_igate.cxx to the target by linking
+# it as a library. This is only temporary until the codebase is cleaned up a
+# bit more to reduce the dependency on interrogate.
 # If ALL is specified, all of the sources from the associated
 # If ALL is specified, all of the sources from the associated
 # target are added.
 # target are added.
 #
 #
@@ -52,6 +60,19 @@ function(target_interrogate target)
 
 
     list(REMOVE_DUPLICATES sources)
     list(REMOVE_DUPLICATES sources)
 
 
+    # Also remove the non-whitelisted filename extensions from sources:
+    foreach(source ${sources})
+      set(any_extension_matches OFF)
+      foreach(filex ${INTERROGATE_EXTENSIONS})
+        if("${source}" MATCHES ".*\\.${filex}$")
+          set(any_extension_matches ON)
+        endif()
+      endforeach(filex)
+      if(NOT any_extension_matches)
+        list(REMOVE_ITEM sources "${source}")
+      endif()
+    endforeach(source)
+
     # Go through the sources to determine the full name,
     # Go through the sources to determine the full name,
     # and also find out if there are any .N files to pick up.
     # and also find out if there are any .N files to pick up.
     foreach(source ${sources})
     foreach(source ${sources})
@@ -69,9 +90,52 @@ function(target_interrogate target)
       endif()
       endif()
     endforeach(source)
     endforeach(source)
 
 
-    set_target_properties("${target}" PROPERTIES IGATE_SOURCES "${sources}")
-    set_target_properties("${target}" PROPERTIES IGATE_SRCDIR "${CMAKE_CURRENT_SOURCE_DIR}")
-    set_target_properties("${target}" PROPERTIES IGATE_DEPS "${deps}")
+    # Interrogate also needs to know the include paths of the current module,
+    # so we'll run over the include directories property and add those to the
+    # interrogate command line.
+    set(igate_includes)
+    get_target_property(target_includes "${target}" INTERFACE_INCLUDE_DIRECTORIES)
+    foreach(include_directory ${target_includes})
+      set(igate_includes
+        ${igate_includes} -I "${include_directory}")
+    endforeach(include_directory)
+
+    add_custom_command(
+      OUTPUT "${target}_igate.cxx" "${target}.in"
+      COMMAND interrogate
+        -od "${target}.in"
+        -oc "${target}_igate.cxx"
+        -library ${target} ${IGATE_FLAGS}
+        -srcdir "${CMAKE_CURRENT_SOURCE_DIR}"
+        -S "${PROJECT_SOURCE_DIR}/dtool/src/parser-inc"
+        -S "${PROJECT_BINARY_DIR}/include/parser-inc"
+        -S "${PROJECT_BINARY_DIR}/include"
+        ${igate_includes}
+        ${sources}
+      DEPENDS interrogate ${deps}
+      COMMENT "Interrogating ${target}"
+    )
+
+    # Now that we've interrogated, let's associate the interrogate sources to
+    # the target:
+    set(igate_sources "${target}_igate.cxx")
+    # Also add all of the _ext sources:
+    foreach(source ${sources})
+      if("${source}" MATCHES ".*_ext.*")
+        set(igate_sources ${igate_sources} "${source}")
+      endif()
+    endforeach(source)
+
+    # Now record INTERROGATE_SOURCES to the target:
+    set_target_properties("${target}" PROPERTIES INTERROGATE_SOURCES ${igate_sources})
+
+
+    # HACK: This is REALLY ugly, but we can't add the _igate.cxx to the existing
+    # target (or at least, when I tried, it ignored the additional file), so as
+    # a (very!) temporary workaround, add another library and link it in.
+    add_library("${target}_igate" ${igate_sources})
+    target_link_libraries(${target} ${target}_igate)
+
   endif()
   endif()
 endfunction(target_interrogate)
 endfunction(target_interrogate)
 
 
@@ -83,29 +147,9 @@ function(add_python_module module)
   if(HAVE_PYTHON AND HAVE_INTERROGATE)
   if(HAVE_PYTHON AND HAVE_INTERROGATE)
     set(targets ${ARGN})
     set(targets ${ARGN})
     set(infiles)
     set(infiles)
-    set(sources)
 
 
     foreach(target ${targets})
     foreach(target ${targets})
-      get_target_property(scansrc "${target}" IGATE_SOURCES)
-      get_target_property(srcdir "${target}" IGATE_SRCDIR)
-      get_target_property(deps "${target}" IGATE_DEPS)
-
-      add_custom_command(
-        OUTPUT "${target}_igate.cxx" "${target}.in"
-        COMMAND interrogate
-          -od "${target}.in"
-          -oc "${target}_igate.cxx"
-          -module ${module} -library ${target} ${IGATE_FLAGS}
-          -srcdir "${srcdir}"
-          -I "${PROJECT_BINARY_DIR}/include"
-          -S "${PROJECT_SOURCE_DIR}/dtool/src/parser-inc"
-          -S "${PROJECT_BINARY_DIR}/include/parser-inc"
-          ${scansrc}
-        DEPENDS interrogate ${deps}
-      )
-
       list(APPEND infiles "${target}.in")
       list(APPEND infiles "${target}.in")
-      list(APPEND sources "${target}_igate.cxx")
     endforeach(target)
     endforeach(target)
 
 
     add_custom_command(
     add_custom_command(
@@ -117,7 +161,7 @@ function(add_python_module module)
       DEPENDS interrogate_module ${infiles}
       DEPENDS interrogate_module ${infiles}
     )
     )
 
 
-    add_library(${module} MODULE "${module}_module.cxx" ${sources})
+    add_library(${module} MODULE "${module}_module.cxx")
     target_link_libraries(${module} ${PYTHON_LIBRARIES})
     target_link_libraries(${module} ${PYTHON_LIBRARIES})
     target_link_libraries(${module} p3interrogatedb)
     target_link_libraries(${module} p3interrogatedb)