Browse Source

Merge pull request #4 from kestred/cmake-cfs-igate2

Update Interrogate.cmake; generate panda3d.core and panda3d.egg modules.
rdb 12 years ago
parent
commit
872ffb12c1

+ 7 - 1
cmake/macros/CompositeSources.cmake

@@ -84,7 +84,7 @@ function(composite_sources target sources_var)
               -DCOMPOSITE_FILE="${composite_file}"
               -DCOMPOSITE_SOURCES="${composite_sources}"
               -P "${COMPOSITE_GENERATOR}"
-            DEPENDS ${composite_sources})          
+            DEPENDS ${composite_sources})
 
           # Reset for the next composite file.
           set(composite_sources "")
@@ -93,6 +93,12 @@ function(composite_sources target sources_var)
     endif()
   endwhile()
 
+  # This exists for Interrogate's benefit, which needs the composite files to
+  # exist before it can run. Unfortunately, CMake does not expose the
+  # add_custom_command outputs as targets outside of the directory, so we have
+  # to create our own pseudotarget that gets exposed.
+  add_custom_target(${target}_composite DEPENDS ${composite_files})
+
   #set_source_files_properties(${composite_files} PROPERTIES GENERATED YES)
 
   # The new files are added to the existing files, which means the old files

+ 175 - 83
cmake/macros/Interrogate.cmake

@@ -8,7 +8,24 @@
 #   add_python_module(module [lib1 [lib2 ...]])
 #
 
-set(IGATE_FLAGS ${INTERROGATE_OPTIONS} -DCPPPARSER -D__cplusplus -Dvolatile -Dmutable)
+set(IGATE_FLAGS -DCPPPARSER -D__cplusplus -Dvolatile -Dmutable -python-native)
+
+# In addition, Interrogate needs to know if this is a 64-bit build:
+include(CheckTypeSize)
+check_type_size(long CMAKE_SIZEOF_LONG)
+if(CMAKE_SIZEOF_LONG EQUAL 8)
+  list(APPEND IGATE_FLAGS "-D_LP64")
+endif()
+
+
+# This is a list of regexes that are applied to every filename. If one of the
+# regexes matches, that file will not be passed to Interrogate.
+set(INTERROGATE_EXCLUDE_REGEXES
+  ".*\\.I$"
+  ".*\\.N$"
+  ".*\\.lxx$"
+  ".*\\.yxx$"
+  ".*_src\\..*")
 
 if(WIN32)
   list(APPEND IGATE_FLAGS -longlong __int64 -D_X86_ -D__STDC__=1 -DWIN32_VC -D "_declspec(param)=" -D "__declspec(param)=" -D_near -D_far -D__near -D__far -D_WIN32 -D__stdcall -DWIN32)
@@ -17,21 +34,14 @@ if(INTERROGATE_VERBOSE)
   list(APPEND IGATE_FLAGS "-v")
 endif()
 
-if(INTERROGATE_PYTHON_INTERFACE AND PYTHON_NATIVE)
-  list(APPEND IGATE_FLAGS -python-native)
-endif()
-
-set(IMOD_FLAGS ${INTERROGATE_MODULE_OPTIONS})
+set(IMOD_FLAGS -python-native)
 
-# 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 ...]])
-# 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.
+# 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.
 # If ALL is specified, all of the sources from the associated
 # target are added.
 #
@@ -39,16 +49,11 @@ function(target_interrogate target)
   if(HAVE_PYTHON AND HAVE_INTERROGATE)
     set(sources)
     set(want_all OFF)
-
-    # Find any .N files that would normally be picked up by interrogate.
-    # We let CMake add these as dependencies too, to allow rebuilding
-    # the wrappers when the .N files have been modified.
-    set(deps)
-    foreach(arg ${ARGV})
+    foreach(arg ${ARGN})
       if(arg STREQUAL "ALL")
         set(want_all ON)
       else()
-        list(APPEND sources "${source}")
+        list(APPEND sources "${arg}")
       endif()
     endforeach()
 
@@ -60,85 +65,152 @@ function(target_interrogate target)
 
     list(REMOVE_DUPLICATES sources)
 
-    # Also remove the non-whitelisted filename extensions from sources:
+    # Now let's get everything's absolute path, so that it can be passed
+    # through a property while still preserving the reference.
+    set(absolute_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()
+      get_source_file_property(location "${source}" LOCATION)
+      set(absolute_sources ${absolute_sources} ${location})
     endforeach(source)
 
-    # Go through the sources to determine the full name,
-    # and also find out if there are any .N files to pick up.
+    set_target_properties("${target}" PROPERTIES IGATE_SOURCES
+      "${absolute_sources}")
+
+    # CMake has no property for determining the source directory where the
+    # target was originally added. interrogate_sources makes use of this
+    # property (if it is set) in order to make all paths on the command-line
+    # relative to it, thereby shortening the command-line even more.
+    # Since this is not an Interrogate-specific property, it is not named with
+    # an IGATE_ prefix.
+    set_target_properties("${target}" PROPERTIES TARGET_SRCDIR
+      "${CMAKE_CURRENT_SOURCE_DIR}")
+
+    # HACK HACK HACK -- this is part of the below hack.
+    target_link_libraries(${target} ${target}_igate)
+  endif()
+endfunction(target_interrogate)
+
+#
+# Function: interrogate_sources(target output database module)
+#
+# This function actually runs a component-level interrogation against 'target'.
+# It generates the outfile.cxx (output) and dbfile.in (database) files, which
+# can then be used during the interrogate_module step to produce language
+# bindings.
+#
+# The target must first have had sources selected with target_interrogate.
+# Failure to do so will result in an error.
+#
+function(interrogate_sources target output database module)
+  if(HAVE_PYTHON AND HAVE_INTERROGATE)
+    get_target_property(sources "${target}" IGATE_SOURCES)
+
+    if(NOT sources)
+      message(FATAL_ERROR
+        "Cannot interrogate ${target} unless it's run through target_interrogate first!")
+    endif()
+
+    get_target_property(srcdir "${target}" TARGET_SRCDIR)
+    if(NOT srcdir)
+      # No TARGET_SRCDIR was set, so we'll do everything relative to our
+      # current binary dir instead:
+      set(srcdir "${CMAKE_CURRENT_BINARY_DIR}")
+    endif()
+
+    set(scan_sources)
+    set(nfiles)
     foreach(source ${sources})
-      get_source_file_property(exclude "${source}" WRAP_EXCLUDE)
+      get_filename_component(source_basename "${source}" NAME)
 
-      if(NOT exclude)
-        get_filename_component(basename "${source}" NAME_WE)
-        if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${basename}.N")
-          list(APPEND deps "${CMAKE_CURRENT_SOURCE_DIR}/${basename}.N")
+      # Only certain sources should actually be scanned by Interrogate. The
+      # rest are merely dependencies. This uses the exclusion regex above in
+      # order to determine what files are okay:
+      set(exclude OFF)
+      foreach(regex ${INTERROGATE_EXCLUDE_REGEXES})
+        if("${source_basename}" MATCHES "${regex}")
+          set(exclude ON)
         endif()
+      endforeach(regex)
 
-        # Add the full path to the source file itself.
-        get_source_file_property(location "${source}" LOCATION)
-        list(APPEND deps "${location}")
+      get_source_file_property(source_excluded ${source} WRAP_EXCLUDE)
+      if(source_excluded)
+        set(exclude ON)
+      endif()
+
+      if(NOT exclude)
+        # This file is to be scanned by Interrogate. In order to avoid
+        # cluttering up the command line, we should first make it relative:
+        file(RELATIVE_PATH rel_source "${srcdir}" "${source}")
+        list(APPEND scan_sources "${rel_source}")
+
+        # Also see if this file has a .N counterpart, which has directives
+        # specific for Interrogate. If there is a .N file, we add it as a dep,
+        # so that CMake will rerun Interrogate if the .N files are modified:
+        get_filename_component(source_path "${source}" PATH)
+        get_filename_component(source_name_we "${source}" NAME_WE)
+        set(nfile "${source_path}/${source_name_we}.N")
+        if(EXISTS "${nfile}")
+          list(APPEND nfiles "${nfile}")
+        endif()
       endif()
     endforeach(source)
 
-    # 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)
+    # 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)
+    # The above must also be included when compiling the resulting _igate.cxx file:
+    include_directories(${include_dirs})
+
+    # 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
+    # will preprocess each file in the same way.
+    set(define_flags)
+    get_target_property(target_defines "${target}" COMPILE_DEFINITIONS)
+    foreach(target_define ${target_defines})
+      list(APPEND define_flags "-D${target_define}")
+    endforeach(target_define)
+    # If this is a release build that has NDEBUG defined, we need that too:
+    string(TOUPPER "${CMAKE_BUILD_TYPE}" build_type)
+    if("${CMAKE_CXX_FLAGS_${build_type}}" MATCHES ".*NDEBUG.*")
+      list(APPEND define_flags "-DNDEBUG")
+    endif()
+
+    # CMake offers no way to directly depend on the composite files from here,
+    # because the composite files are created in a different directory from
+    # where CMake itself is run. Therefore, we need to depend on the
+    # TARGET_composite target, if it exists.
+    if(TARGET ${target}_composite)
+      set(sources ${target}_composite ${sources})
+    endif()
 
     add_custom_command(
-      OUTPUT "${target}_igate.cxx" "${target}.in"
+      OUTPUT "${output}" "${database}"
       COMMAND interrogate
-        -od "${target}.in"
-        -oc "${target}_igate.cxx"
-        -library ${target} ${IGATE_FLAGS}
-        -srcdir "${CMAKE_CURRENT_SOURCE_DIR}"
+        -oc "${output}"
+        -od "${database}"
+        -srcdir "${srcdir}"
+        -module ${module} -library ${target}
+        ${INTERROGATE_OPTIONS}
+        ${IGATE_FLAGS}
+        ${define_flags}
+        -S "${PROJECT_BINARY_DIR}/include"
         -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}
+        ${include_flags}
+        ${scan_sources}
+      DEPENDS interrogate ${sources} ${nfiles}
       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 and INTERROGATE_DATABASE to the target:
-    set_target_properties("${target}" PROPERTIES INTERROGATE_SOURCES ${igate_sources})
-    set_target_properties("${target}" PROPERTIES INTERROGATE_DATABASE "${target}.in")
-
-
-    # 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()
-endfunction(target_interrogate)
+endfunction(interrogate_sources)
 
 #
 # Function: add_python_module(module [lib1 [lib2 ...]])
@@ -148,9 +220,26 @@ function(add_python_module module)
   if(HAVE_PYTHON AND HAVE_INTERROGATE)
     set(targets ${ARGN})
     set(infiles)
+    set(sources)
+    set(HACKlinklibs)
 
     foreach(target ${targets})
+      interrogate_sources(${target} "${target}_igate.cxx" "${target}.in" "${module}")
       list(APPEND infiles "${target}.in")
+      #list(APPEND sources "${target}_igate.cxx")
+
+      # HACK HACK HACK:
+      # Currently, the codebase has dependencies on the Interrogate-generated
+      # code when HAVE_PYTHON is enabled. rdb is working to remove this, but
+      # until then, the generated code must somehow be made available to the
+      # modules themselves. The workaround here is to put the _igate.cxx into
+      # its own micro-library, which is linked both here on the module and
+      # against the component library in question.
+      add_library(${target}_igate ${target}_igate.cxx)
+      list(APPEND HACKlinklibs "${target}_igate")
+
+      get_target_property(target_links "${target}" LINK_LIBRARIES)
+      target_link_libraries(${target}_igate ${target_links})
     endforeach(target)
 
     add_custom_command(
@@ -158,13 +247,16 @@ function(add_python_module module)
       COMMAND interrogate_module
         -oc "${CMAKE_CURRENT_BINARY_DIR}/${module}_module.cxx"
         -module ${module} -library ${module}
+        ${INTERROGATE_MODULE_OPTIONS}
         ${IMOD_FLAGS} ${infiles}
       DEPENDS interrogate_module ${infiles}
+      COMMENT "Generating module ${module}"
     )
 
-    add_library(${module} MODULE "${module}_module.cxx")
-    target_link_libraries(${module} ${PYTHON_LIBRARIES})
-    target_link_libraries(${module} p3interrogatedb)
+    add_library(${module} MODULE "${module}_module.cxx" ${sources})
+    target_link_libraries(${module}
+      ${targets} ${PYTHON_LIBRARIES} p3interrogatedb)
+    target_link_libraries(${module} ${HACKlinklibs})
 
     set_target_properties(${module} PROPERTIES
       LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/panda3d"

+ 14 - 8
cmake/modules/AutoInclude.cmake

@@ -4,8 +4,12 @@
 #   behavior by default.
 #
 
-# Emulate CMake 2.8.11's CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE behavior.
-if(CMAKE_VERSION VERSION_LESS 2.8.11)
+# 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 "")
   # Replace some built-in functions in order to extend their functionality.
   function(add_library target)
     _add_library(${target} ${ARGN})
@@ -29,14 +33,16 @@ if(CMAKE_VERSION VERSION_LESS 2.8.11)
       endif()
     endforeach()
 
-    list(REMOVE_DUPLICATES interface_dirs)
+    if(interface_dirs)
+      list(REMOVE_DUPLICATES interface_dirs)
 
-    #NB. target_include_directories is new in 2.8.8.
-    #target_include_directories("${target}" ${interface_dirs})
-    include_directories(${interface_dirs})
+      #NB. target_include_directories is new in 2.8.8.
+      #target_include_directories("${target}" ${interface_dirs})
+      include_directories(${interface_dirs})
 
-    # Update this target's interface inc dirs.
-    set_target_properties("${target}" PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${target_interface_dirs};${interface_dirs}")
+      # Update this target's interface inc dirs.
+      set_target_properties("${target}" PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${target_interface_dirs};${interface_dirs}")
+    endif()
 
     # Call to the built-in function we are overriding.
     _target_link_libraries(${target} ${ARGN})

+ 0 - 0
dtool/src/parser-inc/crypto.h → dtool/src/parser-inc/openssl/crypto.h


+ 0 - 0
dtool/src/parser-inc/err.h → dtool/src/parser-inc/openssl/err.h


+ 0 - 0
dtool/src/parser-inc/evp.h → dtool/src/parser-inc/openssl/evp.h


+ 0 - 0
dtool/src/parser-inc/md5.h → dtool/src/parser-inc/openssl/md5.h


+ 0 - 0
dtool/src/parser-inc/pem.h → dtool/src/parser-inc/openssl/pem.h


+ 0 - 0
dtool/src/parser-inc/rand.h → dtool/src/parser-inc/openssl/rand.h


+ 0 - 0
dtool/src/parser-inc/rsa.h → dtool/src/parser-inc/openssl/rsa.h


+ 0 - 0
dtool/src/parser-inc/ssl.h → dtool/src/parser-inc/openssl/ssl.h


+ 0 - 0
dtool/src/parser-inc/x509.h → dtool/src/parser-inc/openssl/x509.h


+ 0 - 0
dtool/src/parser-inc/x509v3.h → dtool/src/parser-inc/openssl/x509v3.h


+ 8 - 2
panda/CMakeLists.txt

@@ -27,8 +27,6 @@ add_subdirectory(src/putil)
 add_subdirectory(src/pstatclient)
 add_subdirectory(src/linmath)
 add_subdirectory(src/event)
-add_subdirectory(src/egg)
-add_subdirectory(src/egg2pg)
 add_subdirectory(src/mathutil)
 add_subdirectory(src/gsgbase)
 add_subdirectory(src/glstuff)
@@ -54,6 +52,8 @@ add_subdirectory(src/tform)
 add_subdirectory(src/pgui)
 add_subdirectory(src/recorder)
 add_subdirectory(src/collide)
+add_subdirectory(src/egg)
+add_subdirectory(src/egg2pg)
 add_subdirectory(src/framework)
 add_subdirectory(src/testbed)
 
@@ -61,3 +61,9 @@ add_subdirectory(src/testbed)
 add_subdirectory(metalibs/panda)
 add_subdirectory(metalibs/pandagl)
 add_subdirectory(metalibs/pandaegg)
+
+add_python_module(core p3chan p3char p3collide p3cull p3device p3dgraph
+  p3display p3downloader p3event p3express p3gobj p3grutil p3gsgbase p3linmath
+  p3mathutil p3parametrics p3pgraph p3pgraphnodes p3pgui p3pipeline p3pnmimage
+  p3pnmtext p3pstatclient p3putil p3recorder p3text p3tform)
+add_python_module(egg p3egg p3egg2pg)

+ 7 - 4
panda/src/egg/CMakeLists.txt

@@ -86,12 +86,15 @@ if(HAVE_EGG)
     vector_PT_EggMaterial.cxx pt_EggTexture.cxx
     vector_PT_EggTexture.cxx pt_EggVertex.cxx
     vector_PT_EggVertex.cxx
-    lexer.cxx
-    parser.cxx
   )
 
+  # These cannot be interrogated, and are excluded from the composites.
+  set(P3EGG_PARSER_SOURCES
+    parser.cxx
+    lexer.cxx)
+
   composite_sources(p3egg P3EGG_SOURCES)
-  add_library(p3egg ${P3EGG_HEADERS} ${P3EGG_SOURCES})
+  add_library(p3egg ${P3EGG_HEADERS} ${P3EGG_SOURCES} ${P3EGG_PARSER_SOURCES})
   target_link_libraries(p3egg p3prc p3pandabase p3express p3linmath p3mathutil)
-  target_interrogate(p3egg ALL)
+  target_interrogate(p3egg ${P3EGG_HEADERS} ${P3EGG_SOURCES})
 endif()