Files
swift-mirror/Runtimes/Core/cmake/modules/gyb.cmake
Evan Wilde f3b5fcdc15 Add stubs library to build
Adding stdlib stubs library, which uses gyb and requires knowing about
some of the platform info.

The stubs library pulls in several headers from the compiler repository.
We should probably clean that up, but not right now. I've made a note of
it.
2024-11-06 21:27:53 -08:00

48 lines
2.0 KiB
CMake

find_package(Python3 REQUIRED)
# Create a target to expand a gyb source
# target_name: Name of the target
# FLAGS list of flags passed to gyb
# DEPENDS list of dependencies
# COMMENT Custom comment
function(gyb_expand source output)
set(flags)
set(arguments)
set(multival_arguments FLAGS DEPENDS)
cmake_parse_arguments(GYB "${flags}" "${arguments}" "${multival_arguments}" ${ARGN})
get_filename_component(full_output_path ${output} ABSOLUTE BASE_DIR "${CMAKE_CURRENT_BINARY_DIR}")
get_filename_component(dir "${full_output_path}" DIRECTORY)
get_filename_component(fname "${full_output_path}" NAME)
file(READ "${source}" gyb_src)
string(REGEX MATCHALL "\\\$\{[\r\n\t ]*gyb.expand\\\([\r\n\t ]*[\'\"]([^\'\"]*)[\'\"]" gyb_expand_matches "${gyb_src}")
foreach(match ${gyb_expand_matches})
string(REGEX MATCH "[\'\"]\([^\'\"]*\)[\'\"]" gyb_dep "${match}")
list(APPEND gyb_expand_deps "${CMAKE_MATCH_1}")
endforeach()
list(REMOVE_DUPLICATES gyb_expand_deps)
set(utils_dir "${PROJECT_SOURCE_DIR}/../../utils/")
set(gyb_tool "${utils_dir}/gyb")
# All the tidbits to track for changes
list(APPEND GYB_DEPENDS
"${source}"
"${utils_dir}/GYBUnicodeDataUtils.py"
"${utils_dir}/SwiftIntTypes.py"
"${utils_dir}/SwiftFloatingPointTypes.py"
"${utils_dir}/UnicodeData/GraphemeBreakProperty.txt"
"${utils_dir}/UnicodeData/GraphemeBreakTest.txt"
"${utils_dir}/gyb_stdlib_support.py")
add_custom_command(
OUTPUT "${full_output_path}"
COMMAND "${CMAKE_COMMAND}" -E make_directory "${dir}"
COMMAND "${CMAKE_COMMAND}" -E env "$<TARGET_FILE:Python3::Interpreter>" "${gyb_tool}" ${GYB_FLAGS} -o "${full_output_path}.tmp" "${source}"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${full_output_path}.tmp" "${full_output_path}"
COMMAND "${CMAKE_COMMAND}" -E remove "${full_output_path}.tmp"
DEPENDS ${gyb_tool} ${gyb_tool}.py ${GYB_DEPENDS} ${gyb_expand_deps}
COMMENT "Generating GYB source ${fname} from ${source}"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
endfunction()