diff options
author | Alexander Neundorf <neundorf@kde.org> | 2007-08-02 15:48:51 -0400 |
---|---|---|
committer | Alexander Neundorf <neundorf@kde.org> | 2007-08-02 15:48:51 -0400 |
commit | f32aa8f296dc09ea8341d00702e61a4c0e3e9dbc (patch) | |
tree | 60bf43f2cf11be151c7ba1f78d1dd7e9a888d1eb | |
parent | 8dc897b60ccc6c3a3d017df492317ad54f4653ca (diff) | |
download | cmake-f32aa8f296dc09ea8341d00702e61a4c0e3e9dbc.tar.gz |
ENH: make the python modules usable for C and C++ and only write the header
if it has changed
Alex
-rw-r--r-- | Modules/FindPythonLibs.cmake | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/Modules/FindPythonLibs.cmake b/Modules/FindPythonLibs.cmake index 5e7da5a1fe..e7eac31e45 100644 --- a/Modules/FindPythonLibs.cmake +++ b/Modules/FindPythonLibs.cmake @@ -117,22 +117,44 @@ MACRO(PYTHON_WRITE_MODULES_HEADER _filename) 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) |