Browse Source

Configure module init file at configure times. See #449

Jean-Christophe Fillion-Robin 11 years ago
parent
commit
0ab2d2a3c0

+ 14 - 13
CMake/ctkMacroWrapPythonQt.cmake

@@ -89,9 +89,6 @@ macro(ctkMacroWrapPythonQt WRAPPING_NAMESPACE TARGET SRCS_LIST_NAME SOURCES IS_W
   # Clear log file
   file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/ctkMacroWrapPythonQt_log.txt" "")
 
-  # Convert wrapping namespace to subdir
-  string(REPLACE "." "_" WRAPPING_NAMESPACE_UNDERSCORE ${WRAPPING_NAMESPACE})
-
   set(SOURCES_TO_WRAP)
   set(SOURCES_TO_WRAP_ARG) # Custom_command argument
 
@@ -143,26 +140,32 @@ macro(ctkMacroWrapPythonQt WRAPPING_NAMESPACE TARGET SRCS_LIST_NAME SOURCES IS_W
     endif()
   endforeach()
 
+  # Convert wrapping namespace to subdir
+  string(REPLACE "." "_" WRAPPING_NAMESPACE_UNDERSCORE ${WRAPPING_NAMESPACE})
+
   # Define wrap type and wrap intermediate directory
   set(wrap_int_dir generated_cpp/${WRAPPING_NAMESPACE_UNDERSCORE}_${TARGET}/)
-  #message("wrap_int_dir:${wrap_int_dir}")
-
-  set(wrapper_init_cpp_filename ${WRAPPING_NAMESPACE_UNDERSCORE}_${TARGET}_init.cpp)
-  set(wrapper_init_cpp_file ${CMAKE_CURRENT_BINARY_DIR}/${wrap_int_dir}${wrapper_init_cpp_filename})
 
   set(wrapper_module_init_cpp_filename ${WRAPPING_NAMESPACE_UNDERSCORE}_${TARGET}_module_init.cpp)
-  set(wrapper_module_init_cpp_file ${CMAKE_CURRENT_BINARY_DIR}/${wrap_int_dir}${wrapper_module_init_cpp_filename})
+
+  # Configure 'ctkMacroWrapPythonQtModuleInit.cpp.in' using TARGET, HAS_DECORATOR and
+  # WRAPPING_NAMESPACE_UNDERSCORE.
+  set(TARGET_CONFIG ${TARGET})
+  configure_file(
+    ${CTK_CMAKE_DIR}/ctkMacroWrapPythonQtModuleInit.cpp.in
+    ${wrap_int_dir}${wrapper_module_init_cpp_filename}
+    @ONLY
+    )
 
   # Custom command allow to generate ${WRAPPING_NAMESPACE_UNDERSCORE}_${TARGET}_init.cpp and
   # associated wrappers ${WRAPPING_NAMESPACE_UNDERSCORE}_${TARGET}{0-N}.cpp
+  set(wrapper_init_cpp_filename ${WRAPPING_NAMESPACE_UNDERSCORE}_${TARGET}_init.cpp)
   add_custom_command(
     OUTPUT
       ${wrap_int_dir}${wrapper_init_cpp_filename}
-      ${wrap_int_dir}${wrapper_module_init_cpp_filename}
     DEPENDS
       ${SOURCES_TO_WRAP}
       ${CTK_CMAKE_DIR}/ctkScriptWrapPythonQt_Light.cmake
-      ${CTK_CMAKE_DIR}/ctkMacroWrapPythonQtModuleInit.cpp.in
     COMMAND ${CMAKE_COMMAND}
       -DPYTHON_EXECUTABLE:FILEPATH=${PYTHON_EXECUTABLE}
       -DPYTHON_LIBRARY_PATH:PATH=${PYTHON_LIBRARY_PATH}
@@ -171,7 +174,6 @@ macro(ctkMacroWrapPythonQt WRAPPING_NAMESPACE TARGET SRCS_LIST_NAME SOURCES IS_W
       -DTARGET:STRING=${TARGET}
       -DSOURCES:STRING=${SOURCES_TO_WRAP_ARG}
       -DOUTPUT_DIR:PATH=${CMAKE_CURRENT_BINARY_DIR}/${wrap_int_dir}
-      -DHAS_DECORATOR:BOOL=${HAS_DECORATOR}
       -P ${CTK_CMAKE_DIR}/ctkScriptWrapPythonQt_Light.cmake
     COMMENT "PythonQt Wrapping - Generating ${wrapper_init_cpp_filename}"
     VERBATIM
@@ -208,8 +210,7 @@ macro(ctkMacroWrapPythonQt WRAPPING_NAMESPACE TARGET SRCS_LIST_NAME SOURCES IS_W
     OUTPUT ${wrap_int_dir}${wrapper_master_moc_filename}
     DEPENDS
       ${wrap_int_dir}${wrapper_init_cpp_filename}
-      ${wrap_int_dir}${wrapper_module_init_cpp_filename}
-      ${extra_files} ${CTK_CMAKE_DIR}/ctkScriptMocPythonQtWrapper.cmake
+      ${CTK_CMAKE_DIR}/ctkScriptMocPythonQtWrapper.cmake
     COMMAND ${CMAKE_COMMAND}
       -DWRAPPING_NAMESPACE:STRING=${WRAPPING_NAMESPACE}
       -DTARGET:STRING=${TARGET}

+ 13 - 13
CMake/ctkMacroWrapPythonQtModuleInit.cpp.in

@@ -4,11 +4,11 @@
 #include <Python.h>
 
 //-----------------------------------------------------------------------------
-static PyMethodDef Py@TARGET@PythonQt_ClassMethods[] = {
+static PyMethodDef Py@TARGET_CONFIG@PythonQt_ClassMethods[] = {
 {NULL, NULL, 0, NULL}};
 
 //-----------------------------------------------------------------------------
-extern "C" { void Q_DECL_EXPORT init@TARGET@PythonQt(); }
+extern "C" { void Q_DECL_EXPORT init@TARGET_CONFIG@PythonQt(); }
 
 #ifdef __GNUC__
 // Disable warnings related to Py_DECREF() macro
@@ -50,26 +50,26 @@ void copyAttributes(PyObject* orig_module, PyObject* dest_module)
 } // end of anonymous namespace
 
 //-----------------------------------------------------------------------------
-void init@TARGET@PythonQt()
+void init@TARGET_CONFIG@PythonQt()
 {
-  static const char modulename[] = "@TARGET@PythonQt";
+  static const char modulename[] = "@TARGET_CONFIG@PythonQt";
   PyObject *m;
 
-  m = Py_InitModule((char*)modulename, Py@TARGET@PythonQt_ClassMethods);
-  extern void PythonQt_init_@WRAPPING_NAMESPACE_UNDERSCORE@_@TARGET@(PyObject*);
-  PythonQt_init_@WRAPPING_NAMESPACE_UNDERSCORE@_@TARGET@(m);
+  m = Py_InitModule((char*)modulename, Py@TARGET_CONFIG@PythonQt_ClassMethods);
+  extern void PythonQt_init_@WRAPPING_NAMESPACE_UNDERSCORE@_@TARGET_CONFIG@(PyObject*);
+  PythonQt_init_@WRAPPING_NAMESPACE_UNDERSCORE@_@TARGET_CONFIG@(m);
 
 #ifdef HAS_DECORATOR
-  extern void init@TARGET@PythonQtDecorators();
-  init@TARGET@PythonQtDecorators();
+  extern void init@TARGET_CONFIG@PythonQtDecorators();
+  init@TARGET_CONFIG@PythonQtDecorators();
 #endif
 
-  // Since invoking 'PythonQt_init_@WRAPPING_NAMESPACE_UNDERSCORE@_@TARGET@', will create
-  // the module "PythonQt.@TARGET@". Let's copy its content into the current module.
-  PythonQtObjectPtr currentModule = PyImport_ImportModule((char*)"PythonQt.@TARGET@");
+  // Since invoking 'PythonQt_init_@WRAPPING_NAMESPACE_UNDERSCORE@_@TARGET_CONFIG@', will create
+  // the module "PythonQt.@TARGET_CONFIG@". Let's copy its content into the current module.
+  PythonQtObjectPtr currentModule = PyImport_ImportModule((char*)"PythonQt.@TARGET_CONFIG@");
   if(currentModule.isNull())
     {
-    PyErr_SetString(PyExc_ImportError, (char*)"Failed to import PythonQt.@TARGET@");
+    PyErr_SetString(PyExc_ImportError, (char*)"Failed to import PythonQt.@TARGET_CONFIG@");
     return;
     }
   copyAttributes(currentModule, m);

+ 1 - 12
CMake/ctkScriptWrapPythonQt_Light.cmake

@@ -32,7 +32,6 @@
 #          -DOUTPUT_DIR:PATH=/path
 #          -DPYTHON_EXECUTABLE:FILEPATH=/path/to/python
 #          -DPYTHON_LIBRARY_PATH:PATH=/path/to/pythonlib
-#          -DHAS_DECORATOR:BOOL=True
 #          -P ctkScriptWrapPythonQt_Light.cmake
 #
 
@@ -43,7 +42,7 @@
 #
 
 # Check for non-defined var
-foreach(var WRAPPING_NAMESPACE TARGET SOURCES HAS_DECORATOR)
+foreach(var WRAPPING_NAMESPACE TARGET SOURCES)
   if(NOT DEFINED ${var})
     message(FATAL_ERROR "${var} not specified when calling ctkScriptWrapPythonQt")
   endif()
@@ -91,14 +90,4 @@ else()
   endif()
 endif()
 
-# Convert wrapping namespace to subdir
-string(REPLACE "." "_" WRAPPING_NAMESPACE_UNDERSCORE ${WRAPPING_NAMESPACE})
-
-# Configure 'ctkMacroWrapPythonQtModuleInit.cpp.in' using TARGET, HAS_DECORATOR and
-# WRAPPING_NAMESPACE_UNDERSCORE.
-configure_file(
-  ${CMAKE_CURRENT_LIST_DIR}/ctkMacroWrapPythonQtModuleInit.cpp.in
-  ${OUTPUT_DIR}/${WRAP_INT_DIR}${WRAPPING_NAMESPACE_UNDERSCORE}_${TARGET}_module_init.cpp
-  )
-