diff options
| author | Eduard Braun <eduard.braun2@gmx.de> | 2017-04-29 21:16:31 +0000 |
|---|---|---|
| committer | Eduard Braun <eduard.braun2@gmx.de> | 2017-04-29 21:16:31 +0000 |
| commit | 3a5ecff18c444eddc4eeb1de6c404a4b44081c60 (patch) | |
| tree | b87852cd42dd9e76ef97c81203ad79e9a26badaa /CMakeScripts | |
| parent | Code formating (diff) | |
| download | inkscape-3a5ecff18c444eddc4eeb1de6c404a4b44081c60.tar.gz inkscape-3a5ecff18c444eddc4eeb1de6c404a4b44081c60.zip | |
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)
Diffstat (limited to 'CMakeScripts')
| -rw-r--r-- | CMakeScripts/DefineDependsandFlags.cmake | 1 | ||||
| -rw-r--r-- | CMakeScripts/HelperFunctions.cmake | 139 | ||||
| -rw-r--r-- | CMakeScripts/InstallMSYS2.cmake | 26 |
3 files changed, 161 insertions, 5 deletions
diff --git a/CMakeScripts/DefineDependsandFlags.cmake b/CMakeScripts/DefineDependsandFlags.cmake index 29ccb3a91..8cc0f0cd9 100644 --- a/CMakeScripts/DefineDependsandFlags.cmake +++ b/CMakeScripts/DefineDependsandFlags.cmake @@ -39,6 +39,7 @@ if(WIN32) endif() endif() +find_package(PkgConfig REQUIRED) pkg_check_modules(INKSCAPE_DEP REQUIRED harfbuzz pangocairo 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) diff --git a/CMakeScripts/InstallMSYS2.cmake b/CMakeScripts/InstallMSYS2.cmake index bff09cabf..8d31aca46 100644 --- a/CMakeScripts/InstallMSYS2.cmake +++ b/CMakeScripts/InstallMSYS2.cmake @@ -173,7 +173,7 @@ if(WIN32) FILES_MATCHING
PATTERN "*gtk30.mo"
PATTERN "*gtkspell3.mo")
-
+
install(DIRECTORY ${MINGW_PATH}/share/poppler
DESTINATION ${CMAKE_INSTALL_PREFIX}/share)
@@ -234,5 +234,27 @@ if(WIN32) ${MINGW_BIN}/libpython2.7.dll
DESTINATION ${CMAKE_INSTALL_PREFIX})
install(DIRECTORY ${MINGW_LIB}/python2.7
- DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
+ DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
+ PATTERN "python2.7/site-packages" EXCLUDE)
+
+ set(site_packages "lib/python2.7/site-packages")
+ # Python packages installed via pacman
+ set(packages "python2-lxml" "python2-numpy")
+ foreach(package ${packages})
+ list_files_pacman(${package} paths)
+ install_list(FILES ${paths}
+ ROOT ${MINGW_PATH}
+ INCLUDE ${site_packages} # only include content from "site-packages" (we might consider to install everything)
+ )
+ endforeach()
+ # Python packages installed via pip
+ set(packages "coverage" "pyserial" "scour" "six")
+ foreach(package ${packages})
+ list_files_pip(${package} paths)
+ install_list(FILES ${paths}
+ ROOT ${MINGW_PATH}/${site_packages}
+ DESTINATION ${site_packages}/
+ EXCLUDE "^\\.\\.\\/" # exclude content in parent directories (notably scripts installed to /bin)
+ )
+ endforeach()
endif()
\ No newline at end of file |
