-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathcmake_package.py
More file actions
75 lines (61 loc) · 2.74 KB
/
cmake_package.py
File metadata and controls
75 lines (61 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from hashdist import build_stage
def rpath_flag(ctx, path):
if ctx.parameters['platform'] == 'linux':
return '-Wl,-rpath=%s' % path
else:
return ''
@build_stage()
def configure(ctx, stage_args):
"""
Generates cmake line.
Example::
- name: configure
extra: ['-D ENABLE_FOO:BOOL=ON', '-D ZLIB_DIR:PATH=${ZLIB_DIR}']
set_env_flags: true # default
build_in_source: false # default
debug: false # default
empty_osx_deployment_target: false # default
If set_env_flags is set, CPPFLAGS and LDFLAGS will be set, as appropriate
for the platform.
If build_in_source is set, build directory will be the same as source directory.
"""
conf_lines = ['${CMAKE} -DCMAKE_INSTALL_PREFIX:PATH="${ARTIFACT}"',
'-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON',
'-DCMAKE_INSTALL_RPATH:STRING="${ARTIFACT}/lib"',
'-DCMAKE_INSTALL_RPATH_USE_LINK_PATH:BOOL=ON']
#set the debug or release cmake flags
if stage_args['debug']:
conf_lines.append('-DCMAKE_BUILD_TYPE:STRING=Debug')
else:
conf_lines.append('-DCMAKE_BUILD_TYPE:STRING=Release')
if stage_args.get('empty_osx_deployment_target', False):
conf_lines.append('-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=""')
if stage_args.get('cmake_osx_sysroot', False):
conf_lines.append('-DCMAKE_OSX_SYSROOT:STRING=%s' % stage_args['cmake_osx_sysroot'])
#cmake needs to be given all the dependency dirs as prefix paths
#so that we search the hashdist directories before the system directories
#CMake doesn't use the CPPFLAGS implicitly to find libraries
prefix_paths = []
CPPFLAGS = []
LDFLAGS = []
for dep_var in ctx.dependency_dir_vars:
prefix_paths.append('${%s_DIR}'%dep_var)
CPPFLAGS.append('-I${%s_DIR}/include' % dep_var)
LDFLAGS.append('-L${%s_DIR}/lib' % dep_var)
LDFLAGS.append(rpath_flag(ctx, '${%s_DIR}/lib' % dep_var))
#join all the directories together as a cmake list
conf_lines.append('-DCMAKE_PREFIX_PATH="%s"' % ';'.join(prefix_paths))
if 'extra' in stage_args:
conf_lines.append(' '.join('%s' % arg for arg in stage_args['extra']))
builddir = stage_args.get('builddir', '..')
if stage_args.get('build_in_source', False):
builddir = '.'
conf_lines.append(builddir)
for i in range(len(conf_lines) - 1):
conf_lines[i] = conf_lines[i] + ' \\'
conf_lines[i + 1] = ' ' + conf_lines[i + 1]
env_lines = []
if stage_args.get('set_env_flags', True):
env_lines.append('export CPPFLAGS="%s"' % ' '.join(CPPFLAGS))
env_lines.append('export LDFLAGS="%s"' % ' '.join(LDFLAGS))
return ['('] + env_lines + conf_lines + [')']