From ee3003d99b96815c77109f3820a05de138fd6ebf Mon Sep 17 00:00:00 2001 From: Johannes Demel Date: Fri, 1 Jul 2022 14:41:52 +0200 Subject: [PATCH 1/3] cmake: Suppress superfluous warning CMake shows a warning if `find_package(CpuFeatures)` fails. This is unnecessary. We check for this exact situation and handle it accordingly. Signed-off-by: Johannes Demel --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c96f3372..6aec6a907 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -137,7 +137,7 @@ else() endif() if (VOLK_CPU_FEATURES) - find_package(CpuFeatures) + find_package(CpuFeatures QUIET) if(NOT CpuFeatures_FOUND) message(STATUS "cpu_features package not found. Requiring cpu_features submodule ...") if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/cpu_features/CMakeLists.txt" ) From 32709a6cae288f42f9f2682162a2b6a7930494a7 Mon Sep 17 00:00:00 2001 From: Johannes Demel Date: Fri, 1 Jul 2022 14:43:45 +0200 Subject: [PATCH 2/3] cmake: Fix Python install path calculation Yet again, the solution to determine the correct Python install path has changed subtly. This seems to be broken on new systems such as Fedora 36 and Ubuntu 22.04. Signed-off-by: Johannes Demel --- cmake/Modules/VolkPython.cmake | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/cmake/Modules/VolkPython.cmake b/cmake/Modules/VolkPython.cmake index 94899b5a7..1204cb56e 100644 --- a/cmake/Modules/VolkPython.cmake +++ b/cmake/Modules/VolkPython.cmake @@ -112,17 +112,26 @@ execute_process( COMMAND ${PYTHON_EXECUTABLE} -c "import os import sysconfig import site + install_dir = None prefix = '${CMAKE_INSTALL_PREFIX}' -#use sites when the prefix is already recognized + +#use `site` when the prefix is already recognized try: paths = [p for p in site.getsitepackages() if p.startswith(prefix)] if len(paths) == 1: install_dir = paths[0] except AttributeError: pass + if not install_dir: - #find where to install the python module - install_dir = sysconfig.get_path('platlib') - prefix = sysconfig.get_config_var('prefix') + # find where to install the python module + # for Python 3.11+, we could use the 'venv' scheme for all platforms + if os.name == 'nt': + scheme = 'nt' + else: + scheme = 'posix_prefix' + install_dir = sysconfig.get_path('platlib', scheme) + prefix = sysconfig.get_path('data', scheme) + #strip the prefix to return a relative path print(os.path.relpath(install_dir, prefix))" OUTPUT_STRIP_TRAILING_WHITESPACE From 75a98d5ebff2c7f7c8b43fe294c9cd6d2bcc194c Mon Sep 17 00:00:00 2001 From: Johannes Demel Date: Tue, 5 Jul 2022 14:11:23 +0200 Subject: [PATCH 3/3] cmake: Update Python install path documentation Python install paths are notoriusly difficult to determine. This commit is an effort to provide more info on the subject. Signed-off-by: Johannes Demel --- cmake/Modules/VolkPython.cmake | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/cmake/Modules/VolkPython.cmake b/cmake/Modules/VolkPython.cmake index 1204cb56e..5fd9cad1e 100644 --- a/cmake/Modules/VolkPython.cmake +++ b/cmake/Modules/VolkPython.cmake @@ -114,17 +114,23 @@ import sysconfig import site install_dir = None +# The next line passes a CMake variable into our script. prefix = '${CMAKE_INSTALL_PREFIX}' -#use `site` when the prefix is already recognized +# We use `site` to identify if our chosen prefix is a default one. +# https://docs.python.org/3/library/site.html try: - paths = [p for p in site.getsitepackages() if p.startswith(prefix)] - if len(paths) == 1: install_dir = paths[0] + # https://docs.python.org/3/library/site.html#site.getsitepackages + paths = [p for p in site.getsitepackages() if p.startswith(prefix)] + if len(paths) == 1: install_dir = paths[0] except AttributeError: pass +# If we found a default install path, `install_dir` is set. if not install_dir: - # find where to install the python module - # for Python 3.11+, we could use the 'venv' scheme for all platforms + # We use a custom install prefix! + # Determine the correct install path in that prefix on the current platform. + # For Python 3.11+, we could use the 'venv' scheme for all platforms + # https://docs.python.org/3.11/library/sysconfig.html#installation-paths if os.name == 'nt': scheme = 'nt' else: