commit fa85bf9b595e0ff5721fcf32c21473199d662453
Author: Kornel Benko <[email protected]>
Date:   Sun Jul 24 11:20:08 2016 +0200

    Cmake build: Added check for pythons polib module
    
    Idea stolen from 
http://public.kitware.com/pipermail/cmake/2011-January/041666.html
---
 development/cmake/modules/LyXMacros.cmake |   22 ++++++++++++++++++++++
 po/CMakeLists.txt                         |    6 ++++++
 2 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/development/cmake/modules/LyXMacros.cmake 
b/development/cmake/modules/LyXMacros.cmake
index be7470c..cdcbae8 100644
--- a/development/cmake/modules/LyXMacros.cmake
+++ b/development/cmake/modules/LyXMacros.cmake
@@ -379,3 +379,25 @@ macro(lyx_target_link_libraries _target)
   endforeach()
 endmacro()
 
+# Check if python module exists
+# Idea stolen from 
http://public.kitware.com/pipermail/cmake/2011-January/041666.html
+function(find_python_module module)
+  string(TOUPPER ${module} module_upper)
+  if(NOT LYX_PY_${module_upper})
+    if(ARGC GREATER 1 AND ARGV1 STREQUAL "REQUIRED")
+      set(LYX_PY_${module}_FIND_REQUIRED TRUE)
+    endif()
+    # A module's location is usually a directory, but for binary modules
+    # it's a .so file.
+    execute_process(COMMAND "${LYX_PYTHON_EXECUTABLE}" "-c"
+      "import re, ${module}; 
print(re.compile('/__init__.py.*').sub('',${module}.__file__))"
+      RESULT_VARIABLE _${module}_status
+      OUTPUT_VARIABLE _${module}_location
+      ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
+    if(NOT _${module}_status)
+      set(LYX_PY_${module_upper} ${_${module}_location} CACHE STRING
+       "Location of Python module ${module}")
+    endif()
+  endif()
+  find_package_handle_standard_args(LYX_PY_${module} DEFAULT_MSG 
LYX_PY_${module_upper})
+endfunction(find_python_module)
diff --git a/po/CMakeLists.txt b/po/CMakeLists.txt
index 3ec0feb..e690e40 100755
--- a/po/CMakeLists.txt
+++ b/po/CMakeLists.txt
@@ -11,6 +11,9 @@ include_directories(${TOP_SRC_DIR}/po)
 
 SET(_lyxname ${PACKAGE})
 SET(_py_sources)
+
+# Idea stolen from 
http://public.kitware.com/pipermail/cmake/2011-January/041666.html
+
 macro(add_gettext_python  _par _dir)
   set(_sources)
   foreach(_arg ${ARGN})
@@ -40,6 +43,9 @@ macro(add_gettext_python  _par _dir)
     DEPENDS ${_tmp_src_files}
   )
   if (${_par} MATCHES "layouttranslations")
+    # lyx_pot.py requires the module "polib" if using target 
layouttranslations1,
+    # so we have to check for it
+    find_python_module("polib" REQUIRED)
     ADD_CUSTOM_COMMAND(
       OUTPUT "${_dst}"
       PRE_BUILD

Reply via email to