瀏覽代碼

Allow compiling/installing generated Python files

Modify ctkMacroCompilePythonScript to accept SCRIPTS and/or RESOURCES
that are generated files, rather than requiring them to exist at
configure time. Also, modify ctkFunctionAddCompilePythonScriptTargets to
accept additional arguments that are passed to add_custom_target. (The
second change allows passing e.g. 'DEPENDS <other targets>', which is
required to make the targets depend on other targets which generate the
aforementioned generated files, so that copying of the files will
succeed.)
Matthew Woehlke 11 年之前
父節點
當前提交
9208de739a
共有 1 個文件被更改,包括 13 次插入8 次删除
  1. 13 8
      CMake/ctkMacroCompilePythonScript.cmake

+ 13 - 8
CMake/ctkMacroCompilePythonScript.cmake

@@ -60,7 +60,11 @@ macro(ctkMacroCompilePythonScript)
       set(file "${file}.py")
       set(file "${file}.py")
     endif()
     endif()
 
 
-    set(src "${MY_SOURCE_DIR}/${file}")
+    if(NOT IS_ABSOLUTE ${file})
+      set(src "${MY_SOURCE_DIR}/${file}")
+    else()
+      set(src "${file}")
+    endif()
     set(tgt_file ${file})
     set(tgt_file ${file})
     if(IS_ABSOLUTE ${file})
     if(IS_ABSOLUTE ${file})
       set(src ${file})
       set(src ${file})
@@ -73,7 +77,11 @@ macro(ctkMacroCompilePythonScript)
   if(DEFINED MY_RESOURCES)
   if(DEFINED MY_RESOURCES)
     set(resource_input_files)
     set(resource_input_files)
     foreach(file ${MY_RESOURCES})
     foreach(file ${MY_RESOURCES})
-      set(src "${CMAKE_CURRENT_SOURCE_DIR}/${file}")
+      if(NOT IS_ABSOLUTE ${file})
+        set(src "${MY_SOURCE_DIR}/${file}")
+      else()
+        set(src "${file}")
+      endif()
       set_property(GLOBAL APPEND PROPERTY
       set_property(GLOBAL APPEND PROPERTY
       _CTK_${target}_PYTHON_RESOURCES "${src}|${file}|${MY_DESTINATION_DIR}")
       _CTK_${target}_PYTHON_RESOURCES "${src}|${file}|${MY_DESTINATION_DIR}")
     endforeach()
     endforeach()
@@ -117,10 +125,7 @@ function(_ctk_add_copy_python_files_target target type)
       list(APPEND copied_files ${tgt})
       list(APPEND copied_files ${tgt})
     endforeach()
     endforeach()
     if(entries)
     if(entries)
-      add_custom_target(${target_name} ALL
-        DEPENDS
-          ${copied_files}
-          )
+      add_custom_target(${target_name} ALL DEPENDS ${copied_files} ${ARGN})
     endif()
     endif()
   endif()
   endif()
 endfunction()
 endfunction()
@@ -173,8 +178,8 @@ function(_ctk_add_compile_python_directories_target target)
 endfunction()
 endfunction()
 
 
 function(ctkFunctionAddCompilePythonScriptTargets target)
 function(ctkFunctionAddCompilePythonScriptTargets target)
-  _ctk_add_copy_python_files_target(${target} Script)
-  _ctk_add_copy_python_files_target(${target} Resource)
+  _ctk_add_copy_python_files_target(${target} Script ${ARGN})
+  _ctk_add_copy_python_files_target(${target} Resource ${ARGN})
   _ctk_add_compile_python_directories_target(${target})
   _ctk_add_compile_python_directories_target(${target})
 endfunction()
 endfunction()