From 3a5ecff18c444eddc4eeb1de6c404a4b44081c60 Mon Sep 17 00:00:00 2001 From: Eduard Braun Date: Sat, 29 Apr 2017 23:16:31 +0200 Subject: cmake/MSYS2: Only install a fixed list of Python extensions (instead of all extensions that happen to be installed on the build system) (bzr r15650) --- CMakeScripts/HelperFunctions.cmake | 139 ++++++++++++++++++++++++++++++++++++- 1 file changed, 136 insertions(+), 3 deletions(-) (limited to 'CMakeScripts/HelperFunctions.cmake') diff --git a/CMakeScripts/HelperFunctions.cmake b/CMakeScripts/HelperFunctions.cmake index f4ed255d5..3cd9e2736 100644 --- a/CMakeScripts/HelperFunctions.cmake +++ b/CMakeScripts/HelperFunctions.cmake @@ -1,10 +1,8 @@ # pkg_check_variable() - a function to retrieve pkg-config variables in CMake # # source: http://bloerg.net/2015/03/06/pkg-config-variables-in-cmake.html - -find_package(PkgConfig REQUIRED) - function(pkg_check_variable _pkg _name) + find_package(PkgConfig REQUIRED) string(TOUPPER ${_pkg} _pkg_upper) string(TOUPPER ${_name} _name_upper) string(REPLACE "-" "_" _pkg_upper ${_pkg_upper}) @@ -32,3 +30,138 @@ function(join OUTPUT GLUE) endforeach() set(${OUTPUT} "${_TMP_RESULT}" PARENT_SCOPE) endfunction() + + + +# Checks if the last call to execute_process() was sucessful and throws an error otherwise. +# ${result} and ${stderr} should hold the value of RESULT_VARIABLE and ERROR_VARIABLE respectively +function(check_error result stderr) + if("${result}" STREQUAL 0) + if(NOT "${stderr}" STREQUAL "") + MESSAGE(WARNING "Process returned sucessfully but the following was output to stderr: ${stderr}") + endif() + else() + if("${stderr}" STREQUAL "") + MESSAGE(FATAL_ERROR "Process failed with error code: ${result}") + else() + MESSAGE(FATAL_ERROR "Process failed with error code: ${result} (stderr: ${stderr})") + endif() + endif() +endfunction(check_error) + + + +# Get the list of files installed by pacman for package ${package_name} and return it as ${file_list}. +# Paths are relative to the root directory of the MinGW installations (the directory returned by function "get_mingw_root()") +function(list_files_pacman package_name file_list) + set(MINGW_PACKAGE_PREFIX $ENV{MINGW_PACKAGE_PREFIX}) # e.g. "mingw-w64-x86_64" + get_filename_component(MINGW_PREFIX $ENV{MINGW_PREFIX} NAME) # e.g. "mingw64" + + # use pacman to list all files/folders installed by the package + execute_process( + COMMAND pacman -Ql ${MINGW_PACKAGE_PREFIX}-${package_name} + OUTPUT_FILE list_files_pacman_temp.txt + RESULT_VARIABLE res + ERROR_VARIABLE err + ) + check_error("${res}" "${err}") + + # clean up output + execute_process( + COMMAND grep -v '/$' # get rid of folders + COMMAND sed -e 's/^${MINGW_PACKAGE_PREFIX}-${package_name} //' # remove package name + COMMAND sed -e 's/^\\/${MINGW_PREFIX}\\///' # remove root path + COMMAND tr '\n' '\;' # finally replace newlines with semicolon + INPUT_FILE list_files_pacman_temp.txt + OUTPUT_VARIABLE out + RESULT_VARIABLE res + ERROR_VARIABLE err + ) + check_error("${res}" "${err}") + + SET(${file_list} ${out} PARENT_SCOPE) + file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/list_files_pacman_temp.txt) +endfunction(list_files_pacman) + + + +# Get the list of files installed by pip for package ${package_name} and return it as ${file_list}. +# Paths are relative to the python distributions "site-packages" folder, i.e. "${root}/lib/python2.7/site-packages" +function(list_files_pip package_name file_list) + # use pip to show package information including full list of files installed by the package + execute_process( + COMMAND pip show -f ${package_name} + OUTPUT_FILE list_files_pip_temp.txt + RESULT_VARIABLE res + ERROR_VARIABLE err + ) + check_error("${res}" "${err}") + + # clean up output + execute_process( + COMMAND sed -e '1,/Files:/d' # strip everything but the files list + COMMAND tr -d ' ' # strip spaces + COMMAND tr '\n' '\;' # finally replace newlines with semicolon + INPUT_FILE list_files_pip_temp.txt + OUTPUT_VARIABLE out + RESULT_VARIABLE res + ERROR_VARIABLE err + ) + check_error("${res}" "${err}") + + SET(${file_list} ${out} PARENT_SCOPE) + file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/list_files_pip_temp.txt) +endfunction(list_files_pip) + + + +# Install a list of files maintaining directory structure +# +# Options: +# FILES - the list of files (absolute or relative paths) +# ROOT - the root to search the files in (if file paths are relative) +# DESTINATION - the destination where to install files to +# INCLUDE - a (list of) regular expression(s) specifying which files to include +# (omit or leave empty to inlcude all files) +# EXCLUDE - a (list of) regular expression(s) specifying which files to exclude +# (takes precedence over include rules) +function(install_list) + # parse arguments + set(oneValueArgs ROOT DESTINATION) + set(multiValueArgs FILES INCLUDE EXCLUDE) + cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + #MESSAGE("ARG_FILES: ${ARG_FILES}" ) + #MESSAGE("ARG_ROOT: ${ARG_ROOT}" ) + #MESSAGE("ARG_DESTINATION: ${ARG_DESTINATION}" ) + #MESSAGE("ARG_INCLUDE: ${ARG_INCLUDE}" ) + #MESSAGE("ARG_EXCLUDE: ${ARG_EXCLUDE}" ) + #MESSAGE("ARG_UNPARSED_ARGUMENTS: ${ARG_UNPARSED_ARGUMENTS}" ) + + # install the files + foreach(file ${ARG_FILES}) + #MESSAGE("file: " ${file}) + + # check includes and excludes (excludes take precedence) + set(include_file 0) + if("${ARG_INCLUDE}" STREQUAL "") # start with the assumption to include all files by default + set(include_file 1) + endif() + foreach(include ${ARG_INCLUDE}) + if("${file}" MATCHES "${include}") + set(include_file 1) + endif() + endforeach() + foreach(exclude ${ARG_EXCLUDE}) + if("${file}" MATCHES "${exclude}") + set(include_file 0) + endif() + endforeach() + + # install if file should be included + if(${include_file}) + get_filename_component(directory ${file} DIRECTORY) + install(FILES "${ARG_ROOT}/${file}" DESTINATION "${ARG_DESTINATION}${directory}") + endif() + endforeach() +endfunction(install_list) -- cgit v1.2.3