SConstruct 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #
  2. # Native File Dialog
  3. #
  4. # Scons build script -- GCC, Clang, Visual Studio
  5. # Does not build test
  6. #
  7. # SCons builds are deprecated -- see README.md for details.
  8. import os
  9. # target arch is build arch -- extend here for OS cross compiling
  10. target_os=str(Platform())
  11. # Corresponds to TARGET_ARCH set to environ.
  12. target_arch = ARGUMENTS.get('target_arch', None)
  13. # visual studio does not import from environment
  14. if target_os != 'win32':
  15. IMPORT_FROM_ENV =['CC', 'CXX', 'CFLAGS', 'CXXFLAGS', 'ARFLAGS']
  16. else:
  17. IMPORT_FROM_ENV =[]
  18. debug = int(ARGUMENTS.get( 'debug', 0 ))
  19. nfd_files = ['nfd_common.c']
  20. # Due to a Scons limitation, TARGET_ARCH cannot be appended to an existing environment.
  21. if target_arch != None:
  22. nfd_env = Environment( TARGET_ARCH=target_arch )
  23. else:
  24. nfd_env = Environment()
  25. # import specific environment variables from the command line, overriding
  26. # Scons environment defaults
  27. for env_key in IMPORT_FROM_ENV:
  28. if env_key in os.environ:
  29. print "Making %s => %s" % ( env_key, os.environ[env_key] )
  30. nfd_env[env_key] = os.environ[env_key]
  31. # Windows runtime library types
  32. win_rtl = {'debug': '/MDd',
  33. 'release': '/MD'}
  34. def set_debug(env):
  35. if target_os == 'win32':
  36. env.Append( CCFLAGS=['/Z7', # obj contains full symbols
  37. win_rtl['debug']
  38. ])
  39. else:
  40. env.Append( CFLAGS=['-g'] )
  41. def set_release(env):
  42. if target_os == 'win32':
  43. env.Append( CCFLAGS=[win_rtl['release'],
  44. '/O2'] )
  45. else:
  46. env.Append( CFLAGS=['-O3'] )
  47. def set_warnings(env):
  48. if target_os == 'win32':
  49. env.Append( CCFLAGS=['/W3'],
  50. CPPDEFINES=['_CRT_SECURE_NO_WARNINGS'] )
  51. else:
  52. env.Append( CFLAGS=['-Wall', '-pedantic'] )
  53. def get_lib_name(base, is_debug):
  54. if is_debug:
  55. return base + '_d'
  56. else:
  57. return base
  58. # Cocoa OS X builds - clang
  59. if target_os == 'darwin':
  60. nfd_files.append('nfd_cocoa.m')
  61. nfd_env.CC='clang -fcolor-diagnostics'
  62. # Linux GTK+ 3 builds - GCC
  63. elif target_os == 'posix':
  64. nfd_files.append('nfd_gtk.c')
  65. nfd_env.ParseConfig( 'pkg-config --cflags gtk+-3.0' )
  66. # Windows builds - Visual Studio
  67. elif target_os == 'win32':
  68. nfd_files.append('nfd_win.cpp')
  69. if debug:
  70. set_debug(nfd_env)
  71. else:
  72. set_release(nfd_env)
  73. set_warnings(nfd_env)
  74. nfd_env.Append( CPPPATH=['.','./include'] )
  75. nfd_env.StaticLibrary( get_lib_name('nfd', debug), nfd_files )
  76. print "*** Scons builds are deprecated! See README.md for details."