darling/cmake/pyc.cmake
Andrew Hyatt 27f8fac893
Resolve a clean build failure
Regression relating to removing the extensions from all the tools
2018-05-26 12:10:21 -04:00

28 lines
1.0 KiB
CMake

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" "${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)