Introduce pyc() CMake function, use it to generate .pyc files

This commit is contained in:
Lubos Dolezel 2017-07-18 13:50:26 +02:00
parent 31eeb61ed0
commit ff98b0c051
5 changed files with 37 additions and 2 deletions

27
cmake/pyc.cmake Normal file
View File

@ -0,0 +1,27 @@
include(CMakeParseArguments)
function(pyc target_name)
cmake_parse_arguments(PYC "" "DESTINATION" "SOURCES" ${ARGN})
set(generated_files "")
foreach(pyfile ${PYC_SOURCES})
STRING(REGEX REPLACE "^${CMAKE_CURRENT_SOURCE_DIR}" "" pyfile_rel ${pyfile})
get_filename_component(bareName "${pyfile_rel}" NAME)
get_filename_component(dirName "${pyfile_rel}" DIRECTORY)
# message(STATUS "Process ${pyfile}, dirName ${dirName}, bareName ${bareName}")
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${dirName}")
set(output_name "${CMAKE_CURRENT_BINARY_DIR}/${dirName}/${bareName}c")
add_custom_command(OUTPUT "${output_name}"
COMMAND "${CMAKE_SOURCE_DIR}/tools/pyc.py" "${pyfile}" "${CMAKE_CURRENT_BINARY_DIR}/${dirName}/${bareName}c"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
list(APPEND generated_files "${output_name}")
install(FILES "${output_name}" DESTINATION "${PYC_DESTINATION}")
endforeach(pyfile)
add_custom_target("${target_name}" ALL DEPENDS ${generated_files})
endfunction(pyc)

View File

@ -5,6 +5,7 @@ cmake_policy(SET CMP0005 NEW)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
include(mig)
include(pyc)
add_definitions(-D_DARWIN_C_SOURCE -D_POSIX_C_SOURCE -DDARLING)
set(DARLING TRUE)

2
src/external/python vendored

@ -1 +1 @@
Subproject commit 04a11a96fcbdb9e0e3e6c9aeb52313c5a4d40fa3
Subproject commit 70b7e1aa1ef3b49d4e55402e13191c82927536b3

@ -1 +1 @@
Subproject commit 0f3141f651d90ac2a11e9e36e9aee1f4d26b6b0d
Subproject commit b12011190adaec88b5418f8ed0f00eb04d0b9064

7
tools/pyc.py Executable file
View File

@ -0,0 +1,7 @@
#!/usr/bin/env python2
import py_compile
import sys
py_compile.compile(sys.argv[1], cfile=sys.argv[2], doraise=True)