in tools/make_cmake.py [0:0]
def process_cmake_template_segment(segment, segment_ct, cmake_path, variables):
prefix = None
library = None
set = None
includes = []
suffix = '_SRCS' # Appended to each group name before the platform name.
platform_sep = ':' # Used to separate value from platform name.
append_macro = 'APPEND_PLATFORM_SOURCES' # CMake macro name.
# Extract values from |segment|. Example |segment| contents:
# 'prefix': 'cefsimple',
# 'includes': [
# 'cefsimple_sources_common',
# 'cefsimple_sources_win:WINDOWS',
# 'cefsimple_sources_mac:MAC',
# 'cefsimple_sources_linux:LINUX',
# ],
values = eval('{' + segment + '}', {'__builtins__': None}, None)
if 'prefix' in values:
prefix = values['prefix']
else:
raise Exception('Missing prefix value in segment %d' % segment_ct)
if 'library' in values:
library = values['library']
if 'set' in values:
set = values['set']
if 'append_macro' in values:
append_macro = values['append_macro']
if 'includes' in values and len(values['includes']) > 0:
for include in values['includes']:
parts = include.strip().split(platform_sep)
files = get_files_for_variable(cmake_path, variables, parts[0])
if len(parts) == 2:
# Append the platform to each file path.
files = [file + platform_sep + parts[1] for file in files]
includes.extend(files)
else:
raise Exception('Missing includes value in segment %d' % segment_ct)
# Sort the file paths alphabetically.
includes.sort()
# Group files by path.
# For example, '../include/base/foo.h' and '../include/base/bar.h' will be
# grouped as 'PREFIX_INCLUDE_BASE'.
groups = {}
for include in includes:
paths = include.split('/')
label = prefix
for path in paths[0:-1]:
if path == '..':
continue
label += '_' + path
label = label.replace('.', '_').upper()
if not label in groups:
groups[label] = []
groups[label].append(include)
# Create the output results.
result = ''
keys = sorted(groups.keys())
for key in keys:
# Add a group of files that share the same path.
result += format_cmake_group(cmake_path, key + suffix, groups[key], \
platform_sep, append_macro)
if not library is None:
# Add the library declaration if requested.
result += format_cmake_library(library, [key + suffix for key in keys])
if not set is None:
# Add the set declaration if requested.
result += format_cmake_set(set, \
['${' + key + suffix + '}' for key in keys])
return result.strip()