1 2function(find_python_site_packages VAR) 3 if(Python_SITELIB) 4 set("${VAR}" "${Python_SITELIB}" PARENT_SCOPE) 5 return() 6 endif() 7 8 execute_process( 9 COMMAND "${PYTHON_EXECUTABLE}" -c "if True: 10 from distutils import sysconfig 11 print(sysconfig.get_python_lib(prefix='', plat_specific=True))" 12 OUTPUT_VARIABLE "${VAR}" 13 OUTPUT_STRIP_TRAILING_WHITESPACE) 14 set("${VAR}" "${${VAR}}" PARENT_SCOPE) 15endfunction() 16 17function(get_python_extension_suffix VAR) 18 # from PySide2 CMakeLists.txt 19 # Result of imp.get_suffixes() depends on the platform, but generally looks something like: 20 # [('.cpython-34m-x86_64-linux-gnu.so', 'rb', 3), ('.cpython-34m.so', 'rb', 3), 21 # ('.abi3.so', 'rb', 3), ('.so', 'rb', 3), ('.py', 'r', 1), ('.pyc', 'rb', 2)] 22 # We pick the first most detailed one, strip of the file extension part. 23 24 execute_process( 25 COMMAND "${PYTHON_EXECUTABLE}" -c "if True: 26 import importlib.machinery, re 27 first_suffix = importlib.machinery.EXTENSION_SUFFIXES[0] 28 res = re.search(r'^(.+)\\.', first_suffix) 29 if res: 30 first_suffix = res.group(1) 31 else: 32 first_suffix = '' 33 print(first_suffix) 34 " 35 OUTPUT_VARIABLE "${VAR}" 36 OUTPUT_STRIP_TRAILING_WHITESPACE) 37 set("${VAR}" "${${VAR}}" PARENT_SCOPE) 38endfunction()