Warning, /sdk/pology/cmake/Python3Tools.cmake is written in an unsupported language. File is not indexed.

0001 # TODO: Add doc comments for all this stuff.
0002 
0003 if(NOT PYTHON3_EXECUTABLE)
0004     find_package(Python3)
0005 endif()
0006 
0007 if(NOT py2t_target_count)
0008     set(py2t_target_count 1)
0009 endif()
0010 
0011 
0012 set(py_compfile_script ${CMAKE_BINARY_DIR}/python3_compfile.py)
0013 file(WRITE ${py_compfile_script} "
0014 import os, sys, py_compile
0015 pyfile, pycfile = sys.argv[1:]
0016 py_compile.compile(pyfile, pycfile, doraise=True)
0017 ")
0018 
0019 
0020 macro(INSTALL_PYTHON3_MODULE_FILES pkgdirpath)
0021     set(pyfiles ${ARGN})
0022 
0023     if(IS_ABSOLUTE pkgdirpath)
0024         message(FATAL_ERROR
0025             "Installation directory for Python modules must be "
0026             "a relative path (subdirectory of PYTHON3_PACKAGES_DIR).")
0027     endif()
0028 
0029     set(instdir ${PYTHON3_PACKAGES_DIR}/${pkgdirpath})
0030 
0031     string(REPLACE ${CMAKE_SOURCE_DIR}/ "" srcsubdir
0032                    ${CMAKE_CURRENT_SOURCE_DIR})
0033     string(REPLACE "/" "-" targbase ${srcsubdir})
0034     set(target "${targbase}-plt${py2t_target_count}-compile-python3-files")
0035     math(EXPR py2t_target_count "${py2t_target_count} + 1")
0036 
0037     set(pycfiles)
0038     foreach(pyfile ${pyfiles})
0039         if(NOT IS_ABSOLUTE ${pyfile})
0040             set(pyfilerel ${pyfile})
0041             set(pyfile ${CMAKE_CURRENT_SOURCE_DIR}/${pyfilerel})
0042             set(pycfile ${CMAKE_CURRENT_BINARY_DIR}/${pyfilerel}c)
0043         else()
0044             set(pycfile ${pyfile}c)
0045         endif()
0046         add_custom_command(OUTPUT ${pycfile}
0047                            COMMAND ${PYTHON3_EXECUTABLE} ${py_compfile_script}
0048                                    ${pyfile} ${pycfile}
0049                            DEPENDS ${pyfile})
0050         set(pycfiles ${pycfiles} ${pycfile})
0051     endforeach()
0052     add_custom_target(${target} ALL DEPENDS ${pycfiles})
0053 
0054     install(FILES ${pyfiles} DESTINATION ${instdir})
0055     install(FILES ${pycfiles} DESTINATION ${instdir})
0056 
0057 endmacro()
0058 
0059