-
Notifications
You must be signed in to change notification settings - Fork 50
/
configure
executable file
·197 lines (169 loc) · 7.21 KB
/
configure
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#!/usr/bin/env ruby
require 'fileutils'
include FileUtils
require 'optparse'
require 'ostruct'
opt = OpenStruct.new
opt.generator = 'Make'
opt.mode = 'Release'
opt.cc = ENV['CC']
opt.cxx = ENV['CXX']
opt.third_party = ENV['GRAPPA_THIRD_PARTY']
# verify we're running a supported ruby version
required_version = '1.9.3'
rv_arr = required_version.split('.').map{ |s| s.to_i }
av_arr = RUBY_VERSION.split('.').map{ |s| s.to_i }
if (av_arr <=> rv_arr) < 0
abort("Ruby version #{required_version} required, but found #{RUBY_VERSION}. Aborting.")
end
case `hostname`
when /n[\d+]/
opt.boost = "/sampa/share/gcc-4.7.2/src/boost_1_51_0"
when /pal/
opt.boost = "~nels707/boost153-install"
end
OptionParser.new{|p|
p.set_banner "Usage: #{__FILE__} [options] [-- cmake options]\nOptions summary: (see more details in BUILD.md)"
p.set_summary_indent ""
line_break = "\n#{p.summary_indent}#{' '*p.summary_width} "
p.on('--gen=[Make]|Ninja|Xcode[,*]',"Build tool to generate scripts for.#{line_break}Default: Make.#{line_break}Can specify multiple with commas."){|a| opt.generator = a }
p.on('--mode=[Release]|Debug[,*]','Build mode. Default: Release (with debug symbols)'){|a| opt.mode = a }
p.on('--cc=path/to/c/compiler','Use alternative C compiler (infer C++ compiler from this path).'){|p| opt.cc = p; opt.used_cc_flag = true }
p.on('--cxx=path/to/c++/compiler','Use alternative C++ compiler (infer C compiler from this path).'){|p| opt.cxx = p; opt.used_cxx_flag = true }
p.on('--boost=path/to/boost/root',"Specify location of compatible boost (>= 1.53)#{line_break}(otherwise, cmake will download and build it)"){|p| opt.boost = p }
p.on('--name=NAME',"Add an additional name to this configuration to #{line_break}distinguish it (i.e. compiler version)"){|n| opt.name = n }
p.on('--tracing',"Enable VampirTrace/gperftools-based sampled tracing. #{line_break}Looks for VampirTrace build in 'third-party' dir."){|b| opt.tracing = true }
p.on('--profiling',"Enable gperftools-based sampled profiling."){|b| opt.profiling = true }
p.on('--vampir=path/to/vampirtrace/root',"Specify path to VampirTrace build (enables tracing)."){|p| opt.vampir = p; opt.tracing = true }
p.on('--third-party=path/to/built/deps/root',"Can optionally pre-build third-party dependencies #{line_break}instead of re-building for each configuration."){|p| opt.third_party = p }
p.on('--build-here', "Just configure into current directory rather than creating new build directories."){|b| opt.build_here = true }
p.on('--third-party-tarfile=/path/to/file.tar', "Instead of downloading third-party dependences from the web, extract them from the specified tar file (available from Grappa website)."){|p| opt.third_party_tarfile = p }
p.on('--verbose', "Output verbose configure information."){|b| opt.verbose = true }
p.on('--prefix=path/to/installed/grappa',"Specify destination for Grappa installation (default=/opt/grappa)."){|p| opt.install_prefix = p }
}.parse!(ARGV)
if opt.used_cc_flag
# automatically determine cxx from --cc
case opt.cc
when /gcc/
opt.cxx = opt.cc.gsub(/gcc$/,'g++')
when /clang/
opt.cxx = opt.cc.gsub(/clang$/,'clang++')
end
end
if opt.used_cxx_flag
# automatically determine cc from --cxx
case opt.cxx
when /g\+\+/
opt.cc = opt.cxx.gsub(/g\+\+$/,'gcc')
when /clang\+\+/
opt.cc = opt.cxx.gsub(/clang\+\+$/,'clang')
end
end
# Xcode generator must have CC set to a version of Clang, and must have a corresponding plugin
# see github.com/bholt/Clang-Head.xcplugin for an example
### unless opt.generator =~ /Xcode/ # (Xcode generator currently chokes on other compilers...)
if not(opt.cc) && not(opt.cxx)
abort("Must specify C compiler (either use '--cc=' or '--cxx=' flags, or set the environment variables CC & CXX\nhint: if the compiler you want is on your PATH, you can do: --cc=$(which gcc)...")
end
### end
if opt.tracing && opt.profiling
abort "Please choose one of profiling or tracing."
end
if opt.tracing && not(opt.vampir) && opt.third_party
opt.vampir = opt.third_party
end
# verify we're on a 64-bit machine
case `uname -m`
when /x86_64/
puts "64-bit architecture verified."
else
abort("Grappa requires a 64-bit Intel/AMD architecture machine. This appears to be something else.")
end
def configure(generator, mode, opt)
root_dir = File.expand_path(File.dirname(__FILE__))
args = [ root_dir ]
case generator
when /Make/
args << %Q[-G"Unix Makefiles"]
when /Xcode/
puts "Note: '--mode' not supported for Xcode, ignoring..."
mode = nil
args << "-GXcode"
# need to specify --cc && have the corresponding Xcode plugin
###########################
### workaround, since it looks like the Xcode generator currently needs to use clang:
### opt.cc = nil
### opt.cxx = nil
else
args << %Q[-G"#{generator}"]
end
if opt.third_party_tarfile
args << "-DTHIRD_PARTY_TARFILE:FILEPATH=#{opt.third_party_tarfile}"
end
if opt.tracing
vtcc = "#{opt.vampir}/bin/vtcc"
abort("error: Unable to find VampirTrace wrappers at #{vtcc}") if not File.exists?(vtcc)
args << "-DVAMPIR_ROOT:PATH=#{opt.vampir}"
args << "-DCMAKE_C_COMPILER:FILEPATH=#{opt.vampir}/bin/vtcc"
args << "-DCMAKE_CXX_COMPILER:FILEPATH=#{opt.vampir}/bin/vtcxx"
args << "-DBASE_C_COMPILER:FILEPATH=#{opt.cc}"
args << "-DBASE_CXX_COMPILER:FILEPATH=#{opt.cxx}"
args << "-DCMAKE_C_FLAGS:STRING='-vt:cc #{opt.cc}'"
args << "-DCMAKE_CXX_FLAGS:STRING='-vt:cxx #{opt.cxx}'"
args << "-DTRACING:BOOL=ON"
else
if opt.profiling
args << "-DPROFILING:BOOL=ON"
end
args << "-DCMAKE_C_COMPILER=#{opt.cc}" if opt.cc
args << "-DCMAKE_CXX_COMPILER=#{opt.cxx}" if opt.cxx
args << "-DBASE_C_COMPILER=#{opt.cc}"
args << "-DBASE_CXX_COMPILER=#{opt.cxx}"
end
args << "-DTHIRD_PARTY_ROOT:PATH=#{opt.third_party}" if opt.third_party
if mode
# note: use 'RelWithDebInfo' because it adds '-g'...
args << "-DCMAKE_BUILD_TYPE=" + {'Debug'=>'Debug', 'Release'=>'RelWithDebInfo'}[mode]
end
if opt.boost =~ /^download|none$/
args << "-DBoost_NO_SYSTEM_PATHS=ON"
elsif opt.boost
args << "-DBOOST_ROOT=#{opt.boost}"
end
if opt.verbose
args << "-DVERBOSE=ON"
end
if opt.build_here
build_dir = "."
else
build_dir = "build/#{generator}"
build_dir << "+#{mode}" if mode
build_dir << "+Tracing" if opt.tracing
build_dir << "+Profiling" if opt.profiling
build_dir << "+#{opt.name}" if opt.name
mkdir_p build_dir
end
if opt.install_prefix
args << "-DGRAPPA_INSTALL_PREFIX=" + opt.install_prefix
end
cd build_dir do
puts "cmake #{args.join(' ')} #{ARGV.join(' ')}"
system "cmake #{args.join(' ')} #{ARGV.join(' ')}"
if $?.success?
puts "-------------------------------------"
unless opt.build_here
puts ("created #{build_dir}; to build:\n> cd #{build_dir}; " +
{'Make'=>'make','Ninja'=>'ninja','Xcode'=>'xcodebuild'}[generator])
if generator == 'Make'
puts '(use make -j<numcores> to build in parallel)'
end
puts "-------------------------------------"
end
end
end
end
opt.generator.split(',').each do |generator|
opt.mode.split(',').each do |mode|
configure(generator, mode, opt)
end
end