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" ) diff --git a/cmake/Modules/VolkPython.cmake b/cmake/Modules/VolkPython.cmake index 94899b5a7..5fd9cad1e 100644 --- a/cmake/Modules/VolkPython.cmake +++ b/cmake/Modules/VolkPython.cmake @@ -112,17 +112,32 @@ execute_process( COMMAND ${PYTHON_EXECUTABLE} -c "import os import sysconfig import site + install_dir = None +# The next line passes a CMake variable into our script. prefix = '${CMAKE_INSTALL_PREFIX}' -#use sites 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 - install_dir = sysconfig.get_path('platlib') - prefix = sysconfig.get_config_var('prefix') + # 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: + 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