freeimage.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/usr/bin/env python
  2. # encoding: utf-8
  3. #
  4. # written by Sylvain Rouquette, 2011
  5. '''
  6. To add the freeimage tool to the waf file:
  7. $ ./waf-light --tools=compat15,freeimage
  8. or, if you have waf >= 1.6.2
  9. $ ./waf update --files=freeimage
  10. The wscript will look like:
  11. def options(opt):
  12. opt.load('compiler_cxx freeimage')
  13. def configure(conf):
  14. conf.load('compiler_cxx freeimage')
  15. # you can call check_freeimage with some parameters.
  16. # It's optional on Linux, it's 'mandatory' on Windows if
  17. # you didn't use --fi-path on the command-line
  18. # conf.check_freeimage(path='FreeImage/Dist', fip=True)
  19. def build(bld):
  20. bld(source='main.cpp', target='app', use='FREEIMAGE')
  21. '''
  22. from waflib import Utils
  23. from waflib.Configure import conf
  24. def options(opt):
  25. opt.add_option('--fi-path', type='string', default='', dest='fi_path',
  26. help='''path to the FreeImage directory \
  27. where the files are e.g. /FreeImage/Dist''')
  28. opt.add_option('--fip', action='store_true', default=False, dest='fip',
  29. help='link with FreeImagePlus')
  30. opt.add_option('--fi-static', action='store_true',
  31. default=False, dest='fi_static',
  32. help="link as shared libraries")
  33. @conf
  34. def check_freeimage(self, path=None, fip=False):
  35. self.start_msg('Checking FreeImage')
  36. if not self.env['CXX']:
  37. self.fatal('you must load compiler_cxx before loading freeimage')
  38. prefix = self.options.fi_static and 'ST' or ''
  39. platform = Utils.unversioned_sys_platform()
  40. if platform == 'win32':
  41. if not path:
  42. self.fatal('you must specify the path to FreeImage. \
  43. use --fi-path=/FreeImage/Dist')
  44. else:
  45. self.env['INCLUDES_FREEIMAGE'] = path
  46. self.env['%sLIBPATH_FREEIMAGE' % prefix] = path
  47. libs = ['FreeImage']
  48. if self.options.fip:
  49. libs.append('FreeImagePlus')
  50. if platform == 'win32':
  51. self.env['%sLIB_FREEIMAGE' % prefix] = libs
  52. else:
  53. self.env['%sLIB_FREEIMAGE' % prefix] = [i.lower() for i in libs]
  54. self.end_msg('ok')
  55. def configure(conf):
  56. platform = Utils.unversioned_sys_platform()
  57. if platform == 'win32' and not conf.options.fi_path:
  58. return
  59. conf.check_freeimage(conf.options.fi_path, conf.options.fip)