summaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
authorSebastian Koslowski <koslowski@kit.edu>2017-01-12 15:58:38 +0100
committerSebastian Koslowski <koslowski@kit.edu>2017-01-19 14:09:14 +0100
commit98806de9e5b623b8301426f648e097f408369316 (patch)
treeff88f98d2315467f95840c13d5c6db62b2c71a20 /cmake
parentc33862a14467b1c999d3c4247425c4f7106ae663 (diff)
cmake: add DIRECTORY support to GR_PYTHON_INSTALL and use it for grc
Diffstat (limited to 'cmake')
-rw-r--r--cmake/Modules/GrPython.cmake78
1 files changed, 76 insertions, 2 deletions
diff --git a/cmake/Modules/GrPython.cmake b/cmake/Modules/GrPython.cmake
index 0bfa92db8d..49461e5319 100644
--- a/cmake/Modules/GrPython.cmake
+++ b/cmake/Modules/GrPython.cmake
@@ -1,4 +1,4 @@
-# Copyright 2010-2011 Free Software Foundation, Inc.
+# Copyright 2010-2011,2016 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
@@ -130,7 +130,7 @@ endfunction(GR_UNIQUE_TARGET)
########################################################################
function(GR_PYTHON_INSTALL)
include(CMakeParseArgumentsCopy)
- CMAKE_PARSE_ARGUMENTS(GR_PYTHON_INSTALL "" "DESTINATION" "FILES;PROGRAMS" ${ARGN})
+ CMAKE_PARSE_ARGUMENTS(GR_PYTHON_INSTALL "" "DESTINATION" "FILES;PROGRAMS;DIRECTORY" ${ARGN})
####################################################################
if(GR_PYTHON_INSTALL_FILES)
@@ -185,6 +185,80 @@ function(GR_PYTHON_INSTALL)
)
####################################################################
+ elseif(GR_PYTHON_INSTALL_DIRECTORY)
+ ####################################################################
+ install(${ARGN}) #installs regular python files
+
+ # collect all python files in given directories
+ # #############################################
+ unset(pysrcfiles)
+ foreach(pydir ${GR_PYTHON_INSTALL_DIRECTORY})
+ file(GLOB_RECURSE pysrcfiles_tmp "${pydir}/*.py")
+ list(APPEND pysrcfiles ${pysrcfiles_tmp})
+ endforeach(pydir)
+
+ # build target lists
+ # ##################
+ unset(pycfiles) # pyc targets
+ unset(pyofiles) # pyo targets
+ unset(pygen_paths) # all paths of py[oc] targets
+ foreach(pyfile ${pysrcfiles})
+ # determine if this file is in the source or binary directory
+ file(RELATIVE_PATH source_rel_path ${CMAKE_CURRENT_SOURCE_DIR} ${pyfile})
+ string(LENGTH "${source_rel_path}" source_rel_path_len)
+ file(RELATIVE_PATH binary_rel_path ${CMAKE_CURRENT_BINARY_DIR} ${pyfile})
+ string(LENGTH "${binary_rel_path}" binary_rel_path_len)
+
+ # and set the generated path appropriately
+ if(${source_rel_path_len} GREATER ${binary_rel_path_len})
+ set(pygenfile ${CMAKE_CURRENT_BINARY_DIR}/${binary_rel_path})
+ else()
+ set(pygenfile ${CMAKE_CURRENT_BINARY_DIR}/${source_rel_path})
+ endif()
+ list(APPEND pycfiles "${pygenfile}c")
+ list(APPEND pyofiles "${pygenfile}o")
+
+ get_filename_component(pygen_path "${pygenfile}" DIRECTORY)
+ list(APPEND pygen_paths "${pygen_path}")
+ file(MAKE_DIRECTORY "${pygen_path}")
+ endforeach(pyfile)
+ list(REMOVE_DUPLICATES pygen_paths)
+ list(SORT pygen_paths)
+
+ # generate the py[oc] files
+ # #########################
+ add_custom_command(
+ DEPENDS ${pysrcfiles} OUTPUT ${pycfiles}
+ COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_BINARY_DIR}/python_compile_helper.py ${pysrcfiles} ${pycfiles}
+ )
+ add_custom_command(
+ DEPENDS ${pysrcfiles} OUTPUT ${pyofiles}
+ COMMAND ${PYTHON_EXECUTABLE} -O ${CMAKE_BINARY_DIR}/python_compile_helper.py ${pysrcfiles} ${pyofiles}
+ )
+ set(python_install_gen_targets ${pycfiles} ${pyofiles})
+
+ # per-directory install rules
+ # ###########################
+ foreach(pygen_path ${pygen_paths})
+ # find all targets in that directory (no "list(FILTER ...)")
+ unset(pygen_path_targets)
+ foreach(pyget_target ${python_install_gen_targets})
+ get_filename_component(pyget_target_path "${pyget_target}" PATH)
+ if(pygen_path STREQUAL pyget_target_path)
+ list(APPEND pygen_path_targets "${pyget_target}")
+ endif()
+ endforeach(pyget_target)
+
+ # install relative to current binary dir
+ file(RELATIVE_PATH pygen_path_rel "${CMAKE_CURRENT_BINARY_DIR}" "${pygen_path}")
+ list(SORT pygen_path_targets)
+ install(
+ FILES ${pygen_path_targets}
+ DESTINATION "${GR_PYTHON_INSTALL_DESTINATION}/${pygen_path_rel}"
+ )
+ endforeach(pygen_path)
+
+ ####################################################################
elseif(GR_PYTHON_INSTALL_PROGRAMS)
####################################################################
file(TO_NATIVE_PATH ${PYTHON_EXECUTABLE} pyexe_native)