|
| 1 | +# create_python_xy function will precompile the Python/lib/*.py files |
| 2 | +# and create a zip file containing all the pyc files |
| 3 | +function(create_python_xy PythonExe PythonZipFilePath) |
| 4 | + get_filename_component(python_lib_dir "${PythonExe}" DIRECTORY) |
| 5 | + get_filename_component(python_lib_dir "${python_lib_dir}/Lib" ABSOLUTE) |
| 6 | + foreach(dir collections encodings importlib json urllib re) |
| 7 | + file(COPY ${python_lib_dir}/${dir} |
| 8 | + DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/python-lib |
| 9 | + FILES_MATCHING PATTERN "*.py" |
| 10 | + ) |
| 11 | + endforeach() |
| 12 | + file(GLOB python_lib_files "${python_lib_dir}/*.py") |
| 13 | + foreach(not_needed |
| 14 | + aifc.py imghdr.py socket.py |
| 15 | + antigravity.py imp.py socketserver.py |
| 16 | + argparse.py ipaddress.py ssl.py |
| 17 | + asynchat.py locale.py statistics.py |
| 18 | + asyncore.py lzma.py string.py |
| 19 | + bdb.py mailbox.py stringprep.py |
| 20 | + binhex.py mailcap.py sunau.py |
| 21 | + bisect.py mimetypes.py symbol.py |
| 22 | + bz2.py modulefinder.py symtable.py |
| 23 | + calendar.py netrc.py tabnanny.py |
| 24 | + cgi.py nntplib.py tarfile.py |
| 25 | + cgitb.py nturl2path.py telnetlib.py |
| 26 | + chunk.py numbers.py tempfile.py |
| 27 | + cmd.py optparse.py |
| 28 | + pathlib.py this.py |
| 29 | + pdb.py timeit.py |
| 30 | + colorsys.py pickle.py trace.py |
| 31 | + compileall.py pickletools.py tracemalloc.py |
| 32 | + configparser.py pipes.py tty.py |
| 33 | + contextvars.py plistlib.py turtle.py |
| 34 | + cProfile.py poplib.py typing.py |
| 35 | + crypt.py pprint.py uu.py |
| 36 | + csv.py profile.py |
| 37 | + dataclasses.py pstats.py wave.py |
| 38 | + pty.py webbrowser.py |
| 39 | + decimal.py pyclbr.py xdrlib.py |
| 40 | + difflib.py py_compile.py zipapp.py |
| 41 | + doctest.py queue.py zipfile.py |
| 42 | + dummy_threading.py quopri.py zipimport.py |
| 43 | + filecmp.py random.py _compat_pickle.py |
| 44 | + fileinput.py rlcompleter.py _compression.py |
| 45 | + formatter.py runpy.py _dummy_thread.py |
| 46 | + fractions.py sched.py _markupbase.py |
| 47 | + ftplib.py secrets.py _osx_support.py |
| 48 | + getopt.py selectors.py _pydecimal.py |
| 49 | + getpass.py shelve.py _pyio.py |
| 50 | + gettext.py shlex.py _py_abc.py |
| 51 | + gzip.py shutil.py _strptime.py |
| 52 | + hashlib.py smtpd.py _threading_local.py |
| 53 | + hmac.py smtplib.py |
| 54 | + imaplib.py sndhdr.py __phello__.foo.py |
| 55 | + ) |
| 56 | + list(FIND python_lib_files "${python_lib_dir}/${not_needed}" found_not_needed) |
| 57 | + if (NOT found_not_needed STREQUAL "-1") |
| 58 | + list(REMOVE_AT python_lib_files ${found_not_needed}) |
| 59 | + endif() |
| 60 | + endforeach() |
| 61 | + |
| 62 | + file(COPY ${python_lib_files} DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/python-lib") |
| 63 | + |
| 64 | + set(ENV{PYTHONOPTIMIZE} "2") |
| 65 | + execute_process( |
| 66 | + COMMAND "${PythonExe}" -OO -m compileall "${CMAKE_CURRENT_BINARY_DIR}/python-lib" -b |
| 67 | + ${QTC_COMMAND_ERROR_IS_FATAL} |
| 68 | + ) |
| 69 | + |
| 70 | + file(GLOB_RECURSE python_lib_files "${CMAKE_CURRENT_BINARY_DIR}/python-lib/*.py") |
| 71 | + file(REMOVE ${python_lib_files}) |
| 72 | + |
| 73 | + file(GLOB_RECURSE python_lib_files LIST_DIRECTORIES ON "${CMAKE_CURRENT_BINARY_DIR}/python-lib/*/__pycache__$") |
| 74 | + file(REMOVE_RECURSE ${python_lib_files}) |
| 75 | + |
| 76 | + execute_process( |
| 77 | + COMMAND ${CMAKE_COMMAND} -E tar cf "${PythonZipFilePath}" . --format=zip |
| 78 | + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/python-lib/" |
| 79 | + ${QTC_COMMAND_ERROR_IS_FATAL} |
| 80 | + ) |
| 81 | +endfunction() |
0 commit comments