| 1 | #!/usr/bin/ruby |
|---|
| 2 | # -*- coding: utf-8 -*- |
|---|
| 3 | require 'fileutils' |
|---|
| 4 | require 'optparse' |
|---|
| 5 | require 'ostruct' |
|---|
| 6 | require 'pathname' |
|---|
| 7 | require 'pp' |
|---|
| 8 | require 'set' |
|---|
| 9 | require 'yaml' |
|---|
| 10 | |
|---|
| 11 | @opts = OpenStruct.new |
|---|
| 12 | |
|---|
| 13 | ##################### |
|---|
| 14 | # UTILITY FUNCTIONS # |
|---|
| 15 | ##################### |
|---|
| 16 | |
|---|
| 17 | def pp_s(*objs) |
|---|
| 18 | s = StringIO.new |
|---|
| 19 | objs.each {|obj| PP.pp(obj, s) } |
|---|
| 20 | s.rewind |
|---|
| 21 | s.read |
|---|
| 22 | end |
|---|
| 23 | |
|---|
| 24 | # sets a member only if previously undefined |
|---|
| 25 | def @opts.supplement(name, value) |
|---|
| 26 | if !respond_to?(name) |
|---|
| 27 | puts "Detected #{name} = #{value}" |
|---|
| 28 | new_ostruct_member(name) |
|---|
| 29 | send((name.to_s + "=").to_sym, value) |
|---|
| 30 | end |
|---|
| 31 | end |
|---|
| 32 | |
|---|
| 33 | def @opts.table |
|---|
| 34 | @table |
|---|
| 35 | end |
|---|
| 36 | |
|---|
| 37 | def package_name |
|---|
| 38 | "LibGeoDecomp" |
|---|
| 39 | end |
|---|
| 40 | |
|---|
| 41 | def cflags |
|---|
| 42 | ret = "-O2 -Wall -Werror -Wno-sign-compare" |
|---|
| 43 | if @opts.build_type == "Debug" |
|---|
| 44 | ret = "-g -fno-inline -fno-default-inline -finline-limit=1" |
|---|
| 45 | end |
|---|
| 46 | |
|---|
| 47 | return ret |
|---|
| 48 | end |
|---|
| 49 | |
|---|
| 50 | def set_gnu_make_opts |
|---|
| 51 | num_proc = `grep "^processor.*\: " /proc/cpuinfo | wc -l`.to_i |
|---|
| 52 | @opts.make = "make" |
|---|
| 53 | @opts.makeopts = "-j#{num_proc + 1}" |
|---|
| 54 | end |
|---|
| 55 | |
|---|
| 56 | def set_codegear_make_opts |
|---|
| 57 | @opts.make = "make" |
|---|
| 58 | @opts.makeopts = "" |
|---|
| 59 | end |
|---|
| 60 | |
|---|
| 61 | def set_nmake_opts |
|---|
| 62 | @opts.make = "nmake" |
|---|
| 63 | @opts.makeopts = "" |
|---|
| 64 | end |
|---|
| 65 | |
|---|
| 66 | def download_boost_archive(url, archive) |
|---|
| 67 | if File.exist?(archive) |
|---|
| 68 | `md5sum '#{archive}'` =~ /(\w+) .*/ |
|---|
| 69 | md5sum = $1 |
|---|
| 70 | if md5sum == "ec3875caeac8c52c7c129802a8483bd7" |
|---|
| 71 | puts " Skipping download" |
|---|
| 72 | return |
|---|
| 73 | end |
|---|
| 74 | FileUtils.rm archive |
|---|
| 75 | end |
|---|
| 76 | system "cd '#{archive.parent}' && wget '#{url}'" |
|---|
| 77 | end |
|---|
| 78 | |
|---|
| 79 | def extract_boost_archive(archive, boost_sourcedir) |
|---|
| 80 | if File.exists?(boost_sourcedir.parent) |
|---|
| 81 | puts " Skipping boost extraction" |
|---|
| 82 | return |
|---|
| 83 | end |
|---|
| 84 | |
|---|
| 85 | puts " Extracting boost" |
|---|
| 86 | FileUtils.rm_rf(boost_sourcedir.parent) |
|---|
| 87 | system "cd '#{archive.parent}' && tar -xf '#{archive}'" |
|---|
| 88 | end |
|---|
| 89 | |
|---|
| 90 | def copy_boost_libs(sourcedir, targetdir) |
|---|
| 91 | puts " Copying boost libraries" |
|---|
| 92 | @opts.boost_libs.each do |lib| |
|---|
| 93 | Dir.glob("#{sourcedir + lib}{,.hpp}").each do |f| |
|---|
| 94 | lib_file = Pathname.new(f).relative_path_from(sourcedir) |
|---|
| 95 | if File.exists?(targetdir + lib_file) |
|---|
| 96 | puts " Skipping #{lib_file}" |
|---|
| 97 | end |
|---|
| 98 | FileUtils.cp_r(f, targetdir) |
|---|
| 99 | end |
|---|
| 100 | end |
|---|
| 101 | |
|---|
| 102 | end |
|---|
| 103 | |
|---|
| 104 | def add_boost_libs |
|---|
| 105 | return if @opts.boost_libs.empty? |
|---|
| 106 | puts "Adding boost libs to build: #{pp_s(@opts.boost_libs)}" |
|---|
| 107 | boost_targetdir = @opts.srcdir + "boost" |
|---|
| 108 | boost_releasename = "boost_1_40_0" |
|---|
| 109 | boost_filename = "#{boost_releasename}.tar.bz2" |
|---|
| 110 | boost_url = "http://dfn.dl.sourceforge.net/project/boost/boost/1.40.0/#{boost_filename}" |
|---|
| 111 | boost_archive = @opts.builddir.parent + boost_filename |
|---|
| 112 | boost_sourcedir = @opts.builddir.parent + boost_releasename + "boost" |
|---|
| 113 | @opts.distclean_files += |
|---|
| 114 | [boost_archive, |
|---|
| 115 | boost_sourcedir.parent, |
|---|
| 116 | boost_targetdir] |
|---|
| 117 | |
|---|
| 118 | FileUtils.mkdir_p(boost_targetdir) |
|---|
| 119 | download_boost_archive(boost_url, boost_archive) |
|---|
| 120 | extract_boost_archive(boost_archive, boost_sourcedir) |
|---|
| 121 | copy_boost_libs(boost_sourcedir, boost_targetdir) |
|---|
| 122 | |
|---|
| 123 | puts |
|---|
| 124 | end |
|---|
| 125 | |
|---|
| 126 | def dump_options |
|---|
| 127 | cmake_opts = "" |
|---|
| 128 | config_header = <<EOF |
|---|
| 129 | #ifndef _libgeodecomp_config_h_ |
|---|
| 130 | #define _libgeodecomp_config_h_ |
|---|
| 131 | EOF |
|---|
| 132 | |
|---|
| 133 | cmake_opts += <<EOF |
|---|
| 134 | set(PACKAGE_NAME libgeodecomp) |
|---|
| 135 | set(CMAKE_BUILD_TYPE #{@opts.build_type}) |
|---|
| 136 | set(CMAKE_INSTALL_PREFIX #{@opts.prefix}) |
|---|
| 137 | set(LIB_LINKAGE_TYPE #{@opts.lib_linkage_type}) |
|---|
| 138 | set(BOOST_LINK_SUFFIX #{@opts.boost_link_suffix}) |
|---|
| 139 | EOF |
|---|
| 140 | |
|---|
| 141 | if @opts.cflags |
|---|
| 142 | cmake_opts += <<EOF |
|---|
| 143 | set(CMAKE_C_FLAGS "#{@opts.cflags} ${CMAKE_C_FLAGS}") |
|---|
| 144 | set(CMAKE_CXX_FLAGS "#{@opts.cflags} ${CMAKE_CXX_FLAGS}") |
|---|
| 145 | EOF |
|---|
| 146 | end |
|---|
| 147 | |
|---|
| 148 | if @opts.allowed_tests[:unit] |
|---|
| 149 | cmake_opts += <<EOF |
|---|
| 150 | set(LIBGEODECOMP_FEATURE_UNIT true) |
|---|
| 151 | EOF |
|---|
| 152 | end |
|---|
| 153 | |
|---|
| 154 | if @opts.mpi |
|---|
| 155 | cmake_opts += <<EOF |
|---|
| 156 | set(LIBGEODECOMP_FEATURE_MPI true) |
|---|
| 157 | set(CMAKE_C_COMPILER #{@opts.mpiprefix}/bin/mpicc) |
|---|
| 158 | set(CMAKE_CXX_COMPILER #{@opts.mpiprefix}/bin/mpic++) |
|---|
| 159 | EOF |
|---|
| 160 | config_header += <<EOF |
|---|
| 161 | #define LIBGEODECOMP_FEATURE_MPI |
|---|
| 162 | EOF |
|---|
| 163 | end |
|---|
| 164 | |
|---|
| 165 | if @opts.opencl |
|---|
| 166 | cmake_opts += <<EOF |
|---|
| 167 | set(LIBGEODECOMP_FEATURE_OPENCL true) |
|---|
| 168 | EOF |
|---|
| 169 | config_header += <<EOF |
|---|
| 170 | #define LIBGEODECOMP_FEATURE_OPENCL |
|---|
| 171 | EOF |
|---|
| 172 | end |
|---|
| 173 | |
|---|
| 174 | if @opts.cell |
|---|
| 175 | cmake_opts += <<EOF |
|---|
| 176 | set(LIBGEODECOMP_FEATURE_CELL true) |
|---|
| 177 | EOF |
|---|
| 178 | config_header += <<EOF |
|---|
| 179 | #define LIBGEODECOMP_FEATURE_CELL |
|---|
| 180 | EOF |
|---|
| 181 | end |
|---|
| 182 | |
|---|
| 183 | if @opts.verbose |
|---|
| 184 | cmake_opts += <<EOF |
|---|
| 185 | set(CMAKE_VERBOSE_MAKEFILE true) |
|---|
| 186 | EOF |
|---|
| 187 | end |
|---|
| 188 | |
|---|
| 189 | config_header += <<EOF |
|---|
| 190 | #endif |
|---|
| 191 | EOF |
|---|
| 192 | |
|---|
| 193 | @opts.include_dirs.each do |dir| |
|---|
| 194 | cmake_opts += <<EOF |
|---|
| 195 | include_directories("#{dir}") |
|---|
| 196 | EOF |
|---|
| 197 | end |
|---|
| 198 | |
|---|
| 199 | @opts.link_dirs.each do |dir| |
|---|
| 200 | cmake_opts += <<EOF |
|---|
| 201 | link_directories("#{dir}") |
|---|
| 202 | EOF |
|---|
| 203 | end |
|---|
| 204 | |
|---|
| 205 | cmake_opts += <<EOF |
|---|
| 206 | # packaging stuff |
|---|
| 207 | set(PACKAGE_NAME "#{package_name}") |
|---|
| 208 | set(PACKAGE_VERSION "$ENV{LIBGEODECOMP_VERSION}") |
|---|
| 209 | if(NOT PACKAGE_VERSION) |
|---|
| 210 | set(PACKAGE_VERSION "0.0.1") |
|---|
| 211 | endif(NOT PACKAGE_VERSION) |
|---|
| 212 | |
|---|
| 213 | set(PACKAGE_VENDOR "Chair for Computer Science 3, FAU Erlangen, Germany") |
|---|
| 214 | set(PACKAGE_HOMEPAGE "http:\\\\\\\\www.libgeodecomp.org") |
|---|
| 215 | set(PACKAGE_EMAIL "users@libgeodecomp.org") |
|---|
| 216 | |
|---|
| 217 | # installer stuff |
|---|
| 218 | set(CPACK_PACKAGE_NAME ${PACKAGE_NAME}) |
|---|
| 219 | set(CPACK_PACKAGE_DESCRIPTION_SUMMARY ${PACKAGE_NAME}) |
|---|
| 220 | set(CPACK_PACKAGE_VERSION ${PACKAGE_VERSION}) |
|---|
| 221 | set(CPACK_PACKAGE_INSTALL_DIRECTORY ${PACKAGE_NAME}) |
|---|
| 222 | |
|---|
| 223 | # will be shown e.g. in windows' control center package info |
|---|
| 224 | set(CPACK_PACKAGE_VENDOR ${PACKAGE_VENDOR}) |
|---|
| 225 | set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/../README") |
|---|
| 226 | set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/../LICENSE") |
|---|
| 227 | set(CPACK_PACKAGE_INSTALL_DIRECTORY ${PACKAGE_NAME}) |
|---|
| 228 | |
|---|
| 229 | if(WIN32 AND NOT UNIX) |
|---|
| 230 | # unused in current nsis versions, fix pending (http://www.cmake.org/Bug/print_bug_page.php?bug_id=8682) |
|---|
| 231 | set(CPACK_NSIS_DISPLAY_NAME ${PACKAGE_NAME}) |
|---|
| 232 | |
|---|
| 233 | # name to show in software tab of control center |
|---|
| 234 | set(CPACK_NSIS_DISPLAY_NAME ${PACKAGE_NAME}) |
|---|
| 235 | # will be shown e.g. in windows' control center package info |
|---|
| 236 | set(CPACK_NSIS_HELP_LINK ${PACKAGE_HOMEPAGE}) |
|---|
| 237 | # will be shown e.g. in windows' control center package info |
|---|
| 238 | set(CPACK_NSIS_URL_INFO_ABOUT ${PACKAGE_HOMEPAGE}) |
|---|
| 239 | # will be shown e.g. in windows' control center package info |
|---|
| 240 | set(CPACK_NSIS_CONTACT ${PACKAGE_EMAIL}) |
|---|
| 241 | set(CPACK_NSIS_MODIFY_PATH ON) |
|---|
| 242 | |
|---|
| 243 | # There is a bug in NSI that does not handle full unix paths properly. Make |
|---|
| 244 | # sure there is at least one set of four (4) backlasshes. |
|---|
| 245 | set(CPACK_PACKAGE_ICON "${CMake_SOURCE_DIR}/..\\\\libgeodecomp_icon.png") |
|---|
| 246 | set(CPACK_NSIS_INSTALLED_ICON_NAME "${CMake_SOURCE_DIR}/..\\\\libgeodecomp_icon.png") |
|---|
| 247 | # further options: |
|---|
| 248 | #else(WIN32 AND NOT UNIX) |
|---|
| 249 | # set(CPACK_STRIP_FILES "bin/MyExecutable") |
|---|
| 250 | # set(CPACK_SOURCE_STRIP_FILES "") |
|---|
| 251 | # set(CPACK_PACKAGE_EXECUTABLES "helloworld" "My Hello World") |
|---|
| 252 | endif(WIN32 AND NOT UNIX) |
|---|
| 253 | |
|---|
| 254 | include(CPack) |
|---|
| 255 | EOF |
|---|
| 256 | |
|---|
| 257 | File.open(@opts.srcdir + "libgeodecomp" + "config.h", "w") do |f| |
|---|
| 258 | f.write(config_header) |
|---|
| 259 | end |
|---|
| 260 | |
|---|
| 261 | File.open(@opts.srcdir + "conf.cmake", "w") do |f| |
|---|
| 262 | f.write(cmake_opts) |
|---|
| 263 | end |
|---|
| 264 | |
|---|
| 265 | File.open(@opts.srcdir.parent + "conf.yaml", "w") do |f| |
|---|
| 266 | f.write(YAML.dump(@opts)) |
|---|
| 267 | end |
|---|
| 268 | end |
|---|
| 269 | |
|---|
| 270 | def set_platform_profile(profile) |
|---|
| 271 | puts "Setting platform profile #{profile.to_s}" |
|---|
| 272 | |
|---|
| 273 | case profile |
|---|
| 274 | when :codegear |
|---|
| 275 | @opts.supplement(:cflags, nil) |
|---|
| 276 | @opts.lib_linkage_type = "STATIC" |
|---|
| 277 | @opts.typemaps = false |
|---|
| 278 | @opts.mpi = false |
|---|
| 279 | @opts.cmake = "cmake -G'Borland Makefiles'" |
|---|
| 280 | @opts.allowed_tests[:unit] = false |
|---|
| 281 | @opts.boost_libs += ["multi_array"] |
|---|
| 282 | @opts.boost_link_suffix = "-bcb" |
|---|
| 283 | puts "Warning: assuming CodeGear RAD Studio at c:/Programme/CodeGear/RAD Studio/6.0 with Boost 1.35 installed. Adjust include and link dirs if otherwise." |
|---|
| 284 | @opts.include_dirs += ["c:/Programme/CodeGear/RAD Studio/6.0/include/boost_1_35"] |
|---|
| 285 | @opts.link_dirs += ["c:/Programme/CodeGear/RAD Studio/6.0/lib"] |
|---|
| 286 | set_codegear_make_opts |
|---|
| 287 | |
|---|
| 288 | when :nmake |
|---|
| 289 | @opts.supplement(:cflags, nil) |
|---|
| 290 | @opts.lib_linkage_type = "STATIC" |
|---|
| 291 | @opts.typemaps = false |
|---|
| 292 | @opts.mpi = false |
|---|
| 293 | @opts.cmake = "cmake -G'NMake Makefiles'" |
|---|
| 294 | @opts.boost_link_suffix = "-vc90-mt-1_40" |
|---|
| 295 | puts "Warning: Be sure that boost include and library directories are set, e.g. via" |
|---|
| 296 | puts "#{$0} --include 'c:/Dokumente\ und\ Einstellungen/gentryx/Eigene\ Dateien/boost_1_40_0' \\" |
|---|
| 297 | puts " --link 'c:/Dokumente\ und\ Einstellungen/gentryx/Eigene\ Dateien/boost_1_40_0/lib'" |
|---|
| 298 | puts "Warning: Assuming Boost 1.40 compiled with Visual C++ 9.0. Adjust boost-link-suffix if otherwise." |
|---|
| 299 | set_nmake_opts |
|---|
| 300 | |
|---|
| 301 | when :gnumake |
|---|
| 302 | # intentionally left blank, defaults should suffice |
|---|
| 303 | end |
|---|
| 304 | |
|---|
| 305 | puts |
|---|
| 306 | end |
|---|
| 307 | |
|---|
| 308 | def print_report |
|---|
| 309 | puts "Configured with the following options" |
|---|
| 310 | puts "-------------------------------------" |
|---|
| 311 | puts |
|---|
| 312 | puts "Prefix: #{@opts.prefix}" |
|---|
| 313 | puts "Linkage: #{@opts.lib_linkage_type}" |
|---|
| 314 | puts "Build type: #{@opts.build_type}" |
|---|
| 315 | puts "MPI: #{@opts.mpi}" |
|---|
| 316 | puts "MPI prefix: #{@opts.mpiprefix.to_s}" if @opts.mpi |
|---|
| 317 | puts "OpenCL: #{@opts.opencl ? 'yes' : 'no'}" |
|---|
| 318 | puts "Typemaps: #{@opts.typemaps}" |
|---|
| 319 | allowed_tests = |
|---|
| 320 | @opts.allowed_tests.keys.find_all { |key| @opts.allowed_tests[key] } |
|---|
| 321 | allowed_tests.map! { |test| test.to_s } |
|---|
| 322 | puts "Tests: #{pp_s(allowed_tests)}" |
|---|
| 323 | puts "Make: #{@opts.make}" |
|---|
| 324 | puts "Makeopts: #{pp_s(@opts.makeopts)}" |
|---|
| 325 | puts "Cflags: #{@opts.cflags}" |
|---|
| 326 | end |
|---|
| 327 | |
|---|
| 328 | ################## |
|---|
| 329 | # MAIN FUNCTIONS # |
|---|
| 330 | ################## |
|---|
| 331 | |
|---|
| 332 | def init_default_options |
|---|
| 333 | # fixed settings: |
|---|
| 334 | dir = Pathname.new(__FILE__).parent |
|---|
| 335 | dir = Pathname.new(FileUtils.pwd) + dir if dir.relative? |
|---|
| 336 | arch = `uname -ms`.chomp.gsub(/ /, '-') |
|---|
| 337 | @opts.srcdir = dir + "src" |
|---|
| 338 | @opts.builddir = dir + "build" + arch |
|---|
| 339 | @opts.cxxtestdir = dir + "lib" + "cxxtest" |
|---|
| 340 | @opts.package_namespace = package_name |
|---|
| 341 | |
|---|
| 342 | %w{cmake cpack doxygen}.each do |p| |
|---|
| 343 | print "Checking for #{p}... " |
|---|
| 344 | system "#{p} --version >/dev/null" |
|---|
| 345 | if $?.success? |
|---|
| 346 | puts "OK" |
|---|
| 347 | else |
|---|
| 348 | puts "FAILED" |
|---|
| 349 | raise "Could not find #{p}" |
|---|
| 350 | end |
|---|
| 351 | end |
|---|
| 352 | puts |
|---|
| 353 | |
|---|
| 354 | @opts.cmake = "cmake" |
|---|
| 355 | @opts.doxygen = "doxygen" |
|---|
| 356 | |
|---|
| 357 | # configurable options: |
|---|
| 358 | @opts.boost_libs = [] |
|---|
| 359 | @opts.distclean_files = [] |
|---|
| 360 | @opts.include_dirs = [] |
|---|
| 361 | @opts.link_dirs = [] |
|---|
| 362 | @opts.allowed_tests = { } |
|---|
| 363 | end |
|---|
| 364 | |
|---|
| 365 | def read_commandline_options |
|---|
| 366 | parser = OptionParser.new do |o| |
|---|
| 367 | o.banner = "Usage: #$0 PARAMS" |
|---|
| 368 | o.separator "Configure build options with the following parameters:" |
|---|
| 369 | |
|---|
| 370 | o.on("--prefix DIR", |
|---|
| 371 | "Install relative to DIR.") do |prefix| |
|---|
| 372 | @opts.prefix = prefix |
|---|
| 373 | end |
|---|
| 374 | |
|---|
| 375 | o.on("--cmake COMMAND", |
|---|
| 376 | "Use COMMAND to call CMake.") do |cmake| |
|---|
| 377 | @opts.cmake = cmake |
|---|
| 378 | end |
|---|
| 379 | |
|---|
| 380 | o.on("-v", "--verbose", |
|---|
| 381 | "Give debugging information during build.") do |
|---|
| 382 | @opts.verbose = true |
|---|
| 383 | end |
|---|
| 384 | |
|---|
| 385 | o.on("--mpi-prefix DIR", |
|---|
| 386 | "Use the MPI installation located in DIR.") do |prefix| |
|---|
| 387 | @opts.mpiprefix = Pathname.new(prefix) |
|---|
| 388 | end |
|---|
| 389 | |
|---|
| 390 | o.on("--[no-]typemaps", |
|---|
| 391 | "Control MPI typemap generation.") do |f| |
|---|
| 392 | @opts.typemaps = f |
|---|
| 393 | end |
|---|
| 394 | |
|---|
| 395 | o.on("--[no-]mpi", |
|---|
| 396 | "Control MPI support.") do |f| |
|---|
| 397 | @opts.mpi = f |
|---|
| 398 | end |
|---|
| 399 | |
|---|
| 400 | o.on("--[no-]opencl", |
|---|
| 401 | "Build/disable OpenCL components.") do |f| |
|---|
| 402 | @opts.opencl = f |
|---|
| 403 | end |
|---|
| 404 | |
|---|
| 405 | o.on("--[no-]cell", |
|---|
| 406 | "Set whether Cell BE specific modules are built..") do |f| |
|---|
| 407 | @opts.cell = f |
|---|
| 408 | end |
|---|
| 409 | |
|---|
| 410 | o.on("--linkage-type TYPE", ["shared", "static", "SHARED", "STATIC"], |
|---|
| 411 | "Set the library's linkage type (shared or static).") do |linkage| |
|---|
| 412 | @opts.lib_linkage_type = linkage.upcase |
|---|
| 413 | end |
|---|
| 414 | |
|---|
| 415 | o.on("--cflags CFLAGS", |
|---|
| 416 | "Compiler flags to pass on to the C/C++ compilers.") do |new_cflags| |
|---|
| 417 | @opts.cflags = new_cflags |
|---|
| 418 | end |
|---|
| 419 | |
|---|
| 420 | o.on("--boost-libs LIB[,LIB...]", Array, |
|---|
| 421 | "Add the given boost (header-only) libraries to the build.") do |libraries| |
|---|
| 422 | @opts.boost_libs = libraries |
|---|
| 423 | end |
|---|
| 424 | |
|---|
| 425 | o.on("--boost-link-suffix SUFFIX", |
|---|
| 426 | "Add the given SUFFIX to all boost library names to link", |
|---|
| 427 | "against.") do |suffix| |
|---|
| 428 | @opts.boost_link_suffix = suffix |
|---|
| 429 | end |
|---|
| 430 | |
|---|
| 431 | o.on("--include DIR[,DIR...]", Array, |
|---|
| 432 | "Add DIR to the include path. Useful when required", |
|---|
| 433 | "libraries (e.g. boost) are located outside the default", |
|---|
| 434 | "paths.") do |paths| |
|---|
| 435 | @opts.include_dirs += paths |
|---|
| 436 | end |
|---|
| 437 | |
|---|
| 438 | o.on("--lib DIR[,DIR...]", Array, |
|---|
| 439 | "Add DIR to the link path. Useful when required", |
|---|
| 440 | "libraries (e.g. boost) are located outside the default", |
|---|
| 441 | "paths.") do |paths| |
|---|
| 442 | @opts.link_dirs += paths |
|---|
| 443 | end |
|---|
| 444 | |
|---|
| 445 | o.on("--enable-test TYPE[,TYPE...]", Array, |
|---|
| 446 | "Add TYPE to the list of test types to be run (e.g. unit).") do |tests| |
|---|
| 447 | tests.each { |t| @opts.allowed_tests[t.to_sym] = true } |
|---|
| 448 | end |
|---|
| 449 | |
|---|
| 450 | o.on("--disable-test TYPE[,TYPE...]", Array, |
|---|
| 451 | "Remove TYPE from the list of test types to be run (e.g. mpi).") do |tests| |
|---|
| 452 | tests.each { |t| @opts.allowed_tests[t.to_sym] = false } |
|---|
| 453 | end |
|---|
| 454 | |
|---|
| 455 | o.on("--platform-profile PROFILE", [:codegear, :nmake, :gnumake], |
|---|
| 456 | "Guess options most suitable for the given build platform.", |
|---|
| 457 | "Available profiles: codegear, nmake, gnumake.") do |profile| |
|---|
| 458 | set_platform_profile profile |
|---|
| 459 | end |
|---|
| 460 | |
|---|
| 461 | o.on("--build-type TYPE", ["Debug", "Release", "MinSizeRel", "RelWithDebInfo"], |
|---|
| 462 | 'Set the cmake build type (Debug, Release, MinSizeRel (short', |
|---|
| 463 | 'for "minimum size release"), RelWithDebInfo (short for', |
|---|
| 464 | '"release with debug information")).') do |type| |
|---|
| 465 | @opts.build_type = type |
|---|
| 466 | end |
|---|
| 467 | end |
|---|
| 468 | parser.parse!(ARGV) |
|---|
| 469 | end |
|---|
| 470 | |
|---|
| 471 | def find_opencl |
|---|
| 472 | paths = ENV['CPLUS_INCLUDE_PATH'].nil? ? [] : ENV['CPLUS_INCLUDE_PATH'].split(":") |
|---|
| 473 | paths << "/usr/include" |
|---|
| 474 | paths.each do |path| |
|---|
| 475 | header = Pathname.new(path) + "CL" + "cl.h" |
|---|
| 476 | return true if File.exist?(header) |
|---|
| 477 | end |
|---|
| 478 | |
|---|
| 479 | return nil |
|---|
| 480 | end |
|---|
| 481 | |
|---|
| 482 | # fill in options which are currently unspecified |
|---|
| 483 | def detect_defaults |
|---|
| 484 | puts "Detecting defaults" |
|---|
| 485 | puts "------------------" |
|---|
| 486 | puts |
|---|
| 487 | |
|---|
| 488 | @opts.supplement(:cflags, cflags) |
|---|
| 489 | |
|---|
| 490 | # MPI related settings |
|---|
| 491 | mpicc = `which mpicc 2>/dev/null`.chomp |
|---|
| 492 | mpiprefix = ENV['OMPI_PREFIX'] |
|---|
| 493 | mpiprefix = Pathname.new(mpiprefix) if !mpiprefix.nil? |
|---|
| 494 | mpiprefix ||= Pathname.new(mpicc).parent.parent if !mpicc.empty? |
|---|
| 495 | @opts.supplement(:mpiprefix, mpiprefix) |
|---|
| 496 | # If mpi-prefix is not set we have to switch off MPI support |
|---|
| 497 | @opts.supplement(:mpi, @opts.mpiprefix != nil) |
|---|
| 498 | |
|---|
| 499 | # MPI is required for typemaps to work |
|---|
| 500 | @opts.supplement(:mpiexec, @opts.mpiprefix + "bin" + "mpiexec") if @opts.mpi |
|---|
| 501 | @opts.supplement(:typemaps, @opts.mpi == true) |
|---|
| 502 | @opts.supplement(:opencl, find_opencl) |
|---|
| 503 | |
|---|
| 504 | cpuinfo = `cat /proc/cpuinfo 2>/dev/null` |
|---|
| 505 | @opts.supplement(:cell, cpuinfo =~ /Cell Broadband Engine/ ? true : false) |
|---|
| 506 | |
|---|
| 507 | |
|---|
| 508 | if @opts.allowed_tests[:mpi].nil? && @opts.mpi |
|---|
| 509 | @opts.allowed_tests[:mpi] = true |
|---|
| 510 | end |
|---|
| 511 | |
|---|
| 512 | if @opts.allowed_tests[:unit].nil? |
|---|
| 513 | @opts.allowed_tests[:unit] = true |
|---|
| 514 | end |
|---|
| 515 | |
|---|
| 516 | @opts.supplement(:lib_linkage_type, "SHARED") |
|---|
| 517 | @opts.supplement(:boost_link_suffix, "") |
|---|
| 518 | @opts.supplement(:prefix, "/usr/local") |
|---|
| 519 | @opts.supplement(:typemapsdir, |
|---|
| 520 | @opts.srcdir + "libgeodecomp" + "mpilayer") |
|---|
| 521 | @opts.supplement(:verbose, false) |
|---|
| 522 | @opts.supplement(:cmake, "cmake") |
|---|
| 523 | @opts.supplement(:build_type, "Release") |
|---|
| 524 | |
|---|
| 525 | if @opts.make.nil? |
|---|
| 526 | case `make -v 2>/dev/null` |
|---|
| 527 | when /GNU Make/ |
|---|
| 528 | set_gnu_make_opts |
|---|
| 529 | when /CodeGear/ |
|---|
| 530 | set_codegear_make_opts |
|---|
| 531 | else |
|---|
| 532 | if `nmake 2>/dev/null` =~ /Microsoft.*Program Maintenance Utility/ |
|---|
| 533 | set_nmake_opts |
|---|
| 534 | end |
|---|
| 535 | end |
|---|
| 536 | end |
|---|
| 537 | |
|---|
| 538 | puts |
|---|
| 539 | end |
|---|
| 540 | |
|---|
| 541 | def process_options |
|---|
| 542 | add_boost_libs |
|---|
| 543 | dump_options |
|---|
| 544 | print_report |
|---|
| 545 | end |
|---|
| 546 | |
|---|
| 547 | init_default_options |
|---|
| 548 | read_commandline_options |
|---|
| 549 | detect_defaults |
|---|
| 550 | process_options |
|---|