Files
swift-mirror/cmake/modules/SwiftHandleGybSources.cmake
John McCall 2ff77a9cd1 Only import *Ref typedefs as CF types if they have a bridging
attribute or appear in a whitelist.

The initial whitelist is based on an audit I performed of our current
public SDKs.  If there are CF types which appear only in our internal
SDKs, and somebody urgently needs to use them from Swift, they can
adopt the bridging attributes.  The goal is to eventually eliminate
the whitelist and rely solely on bridging attributes anyway.

Sadly, CoreCooling was not included in my SDK audit and must be
explicitly annotated. :(

I've left the main database organized by framework, but I wanted
a quasi-lexicographically sorted version to permit efficient lookup.
We generate that copy automatically with gyb.  I ended up having
to tweak handle_gyb_sources to allow it to drop the result in
CMAKE_CURRENT_BINARY_DIR instead of CMAKE_CURRENT_BINARY_DIR/{4,8}
if an architecture is not provided.  I think this is abstractly
reasonable for generated includes, which have independent ability
to detect the target word size.  But just between you and me,
I did it because I couldn't figure out how to add
"-I${CMAKE_CURRENT_BINARY_DIR/{4,8}" as a compile flag;
the obvious thing didn't work.  Anyway, I'd appreciate it if
someone double-checked my cmake hackery here.

Swift SVN r24850
2015-01-30 18:39:07 +00:00

85 lines
3.2 KiB
CMake

include(SwiftAddCustomCommandTarget)
include(SwiftSetIfArchBitness)
# Create a target to process .gyb files with the 'gyb' tool.
#
# handle_gyb_sources(
# dependency_out_var_name
# sources_var_name
# arch)
#
# Replace, in ${sources_var_name}, the given .gyb-suffixed sources with
# their un-suffixed intermediate files, which will be generated by processing
# the .gyb files with gyb.
#
# dependency_out_var_name
# The name of a variable, to be set in the parent scope to the list of
# targets that invoke gyb. Every target that depends on the generated
# sources should depend on ${dependency_out_var_name} targets.
#
# arch
# The architecture that the files will be compiled for. If this is
# false, the files are architecture-independent and will be emitted
# into ${CMAKE_CURRENT_BINARY_DIR} instead of an architecture-specific
# destination; this is useful for generated include files.
function(handle_gyb_sources dependency_out_var_name sources_var_name arch)
set(extra_gyb_flags "")
if (arch)
set_if_arch_bitness(ptr_size
ARCH "${arch}"
CASE_32_BIT "4"
CASE_64_BIT "8")
set(extra_gyb_flags "-DCMAKE_SIZEOF_VOID_P=${ptr_size}")
endif()
set(gyb_flags
"--test" # Run gyb's self-tests whenever we use it. They're cheap
# enough and it keeps us honest.
${SWIFT_GYB_FLAGS}
${extra_gyb_flags})
set(dependency_targets)
set(de_gybbed_sources)
set(gyb_sources)
set(gyb_tool "${SWIFT_SOURCE_DIR}/utils/gyb")
set(gyb_extra_sources
"${SWIFT_SOURCE_DIR}/utils/GYBUnicodeDataUtils.py"
"${SWIFT_SOURCE_DIR}/utils/SwiftIntTypes.py"
"${SWIFT_SOURCE_DIR}/utils/UnicodeData/GraphemeBreakProperty.txt"
"${SWIFT_SOURCE_DIR}/utils/UnicodeData/GraphemeBreakTest.txt")
foreach (src ${${sources_var_name}})
string(REGEX REPLACE "[.]gyb$" "" src_sans_gyb "${src}")
if(src STREQUAL src_sans_gyb)
list(APPEND de_gybbed_sources "${src}")
else()
if (arch)
set(dir "${CMAKE_CURRENT_BINARY_DIR}/${ptr_size}")
else()
set(dir "${CMAKE_CURRENT_BINARY_DIR}")
endif()
set(output_file_name "${dir}/${src_sans_gyb}")
list(APPEND de_gybbed_sources "${output_file_name}")
string(MD5 output_file_name_hash "${output_file_name}")
add_custom_command_target(
dependency_target
COMMAND
"${CMAKE_COMMAND}" -E make_directory "${dir}"
COMMAND
"${gyb_tool}" "${gyb_flags}" -o "${output_file_name}.tmp" "${src}"
COMMAND
"${CMAKE_COMMAND}" -E copy_if_different "${output_file_name}.tmp" "${output_file_name}"
COMMAND
"${CMAKE_COMMAND}" -E remove "${output_file_name}.tmp"
OUTPUT "${output_file_name}"
DEPENDS "${gyb_tool}" "${src}" "${gyb_extra_sources}"
COMMENT "Generating ${src_sans_gyb} from ${src} with ptr size = ${ptr_size}"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
IDEMPOTENT)
list(APPEND dependency_targets "${dependency_target}")
endif()
endforeach()
set("${dependency_out_var_name}" "${dependency_targets}" PARENT_SCOPE)
set("${sources_var_name}" "${de_gybbed_sources}" PARENT_SCOPE)
endfunction()