[cmake-commits] alex committed FindPythonLibs.cmake 1.35 1.36

cmake-commits at cmake.org cmake-commits at cmake.org
Thu Aug 2 15:48:54 EDT 2007


Update of /cvsroot/CMake/CMake/Modules
In directory public:/mounts/ram/cvs-serv4653

Modified Files:
	FindPythonLibs.cmake 
Log Message:

ENH: make the python modules usable for C and C++ and only write the header
if it has changed

Alex


Index: FindPythonLibs.cmake
===================================================================
RCS file: /cvsroot/CMake/CMake/Modules/FindPythonLibs.cmake,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- FindPythonLibs.cmake	27 Jul 2007 12:59:59 -0000	1.35
+++ FindPythonLibs.cmake	2 Aug 2007 19:48:51 -0000	1.36
@@ -117,22 +117,44 @@
   GET_FILENAME_COMPONENT(_name "${_filename}" NAME)
   STRING(REPLACE "." "_" _name "${_name}")
   STRING(TOUPPER ${_name} _name)
-  FILE(WRITE ${_filename} "/*Created by cmake, do not edit, changes will be lost*/\n")
-  FILE(APPEND ${_filename} "#ifndef ${_name}\n")
-  FILE(APPEND ${_filename} "#define ${_name}\n\n")
-  FILE(APPEND ${_filename} "#include <Python.h>\n\n")
+
+  SET(_filenameTmp "${_filename}.in")
+  FILE(WRITE ${_filenameTmp} "/*Created by cmake, do not edit, changes will be lost*/\n")
+  FILE(APPEND ${_filenameTmp} 
+"#ifndef ${_name}
+#define ${_name}
+
+#include <Python.h>
+
+#ifdef __cplusplus
+extern \"C\" {
+#endif /* __cplusplus */
+
+")
 
   FOREACH(_currentModule ${PY_STATIC_MODULES_LIST})
-    FILE(APPEND ${_filename} "extern void init${_currentModule}(void);\n\n")
+    FILE(APPEND ${_filenameTmp} "extern void init${PYTHON_MODULE_PREFIX}${_currentModule}(void);\n\n")
   ENDFOREACH(_currentModule ${PY_STATIC_MODULES_LIST})
 
+  FILE(APPEND ${_filenameTmp} 
+"#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+")
+
+
   FOREACH(_currentModule ${PY_STATIC_MODULES_LIST})
-    FILE(APPEND ${_filename} "int CMakeLoadPythonModule_${_currentModule}(void) \n{\n  char name[]=\"${PYTHON_MODULE_PREFIX}${_currentModule}\"; return PyImport_AppendInittab(name, init${PYTHON_MODULE_PREFIX}${_currentModule});\n}\n\n")
+    FILE(APPEND ${_filenameTmp} "int CMakeLoadPythonModule_${_currentModule}(void) \n{\n  char name[]=\"${PYTHON_MODULE_PREFIX}${_currentModule}\"; return PyImport_AppendInittab(name, init${PYTHON_MODULE_PREFIX}${_currentModule});\n}\n\n")
   ENDFOREACH(_currentModule ${PY_STATIC_MODULES_LIST})
 
-  FILE(APPEND ${_filename} "#ifndef EXCLUDE_LOAD_ALL_FUNCTION\nvoid CMakeLoadAllPythonModules(void)\n{\n")
+  FILE(APPEND ${_filenameTmp} "#ifndef EXCLUDE_LOAD_ALL_FUNCTION\nvoid CMakeLoadAllPythonModules(void)\n{\n")
   FOREACH(_currentModule ${PY_STATIC_MODULES_LIST})
-    FILE(APPEND ${_filename} "  CMakeLoadPythonModule_${_currentModule}();\n")
+    FILE(APPEND ${_filenameTmp} "  CMakeLoadPythonModule_${_currentModule}();\n")
   ENDFOREACH(_currentModule ${PY_STATIC_MODULES_LIST})
-  FILE(APPEND ${_filename} "}\n#endif\n\n#endif\n")
+  FILE(APPEND ${_filenameTmp} "}\n#endif\n\n#endif\n")
+  
+# with CONFIGURE_FILE() cmake complains that you may not use a file created using FILE(WRITE) as input file for CONFIGURE_FILE()
+  EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E copy_if_different "${_filenameTmp}" "${_filename}" OUTPUT_QUIET ERROR_QUIET)
+
 ENDMACRO(PYTHON_WRITE_MODULES_HEADER)



More information about the Cmake-commits mailing list