From f9ceb5d563b6dca73d65d452730e8f68bf0ef6b1 Mon Sep 17 00:00:00 2001
From: Jorrit Schaap <schaap@astron.nl>
Date: Wed, 14 Oct 2015 08:20:51 +0000
Subject: [PATCH] Task #8574: added optional EXECUTABLE to python_install
 macro, which makes the installed python files executable

---
 CMake/PythonInstall.cmake | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/CMake/PythonInstall.cmake b/CMake/PythonInstall.cmake
index a62a2a43fd9..eacfcf7841e 100644
--- a/CMake/PythonInstall.cmake
+++ b/CMake/PythonInstall.cmake
@@ -67,9 +67,24 @@ macro(python_install)
   endif(NOT PYTHON_EXECUTABLE)
 
   # Parse arguments.
+  # apart from the python files list, there are two additional arguments
+  # DESTINATION (required), where to put the py files (relative to python lib dir)
+  # EXECUTABLE (optional), makes the py files executable
   string(REGEX REPLACE ";?DESTINATION.*" "" _py_files "${ARGN}")
+  string(REGEX REPLACE ";?EXECUTABLE.*" "" _py_files "${_py_files}")
   string(REGEX MATCH "DESTINATION;.*" _dest_dir "${ARGN}")
   string(REGEX REPLACE "^DESTINATION;" "" _dest_dir "${_dest_dir}")
+  string(REGEX REPLACE ";?EXECUTABLE.*" "" _dest_dir "${_dest_dir}")
+  string(REGEX MATCH "EXECUTABLE;" _executable "${ARGN}")
+
+  #check if optional argument EXECUTABLE is set
+  #if so, then install the _py_files as EXECUTABLE type (executable)
+  #else as normal files (not executable)
+  if("${_executable}" STRGREATER "")
+    set(INSTALL_TYPE PROGRAMS)
+  else()
+    set(INSTALL_TYPE FILES)
+  endif("${_executable}" STRGREATER "")
 
   if(_py_files MATCHES "^$")
     message(FATAL_ERROR "python_install: no sources files specified")
@@ -98,7 +113,7 @@ macro(python_install)
     file(MAKE_DIRECTORY ${_build_dir}/${_py_path})
     execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink
       ${_py_abs} ${_build_dir}/${_py})
-    install(FILES ${_py_abs} DESTINATION ${_inst_dir}/${_py_path})
+    install(${INSTALL_TYPE} ${_py_abs} DESTINATION ${_inst_dir}/${_py_path})
     if(USE_PYTHON_COMPILATION)
       set(_py_code
         "import py_compile, os"
-- 
GitLab