detect.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. import os
  2. import platform
  3. import sys
  4. def is_active():
  5. return True
  6. def get_name():
  7. return "Server"
  8. def get_program_suffix():
  9. if (sys.platform == "darwin"):
  10. return "osx"
  11. return "x11"
  12. def can_build():
  13. if (os.name != "posix"):
  14. return False
  15. return True
  16. def get_opts():
  17. from SCons.Variables import BoolVariable
  18. return [
  19. BoolVariable('use_llvm', 'Use the LLVM compiler', False),
  20. BoolVariable('use_static_cpp', 'Link libgcc and libstdc++ statically for better portability', False),
  21. ]
  22. def get_flags():
  23. return []
  24. def configure(env):
  25. ## Build type
  26. if (env["target"] == "release"):
  27. env.Append(CCFLAGS=['-O2', '-ffast-math', '-fomit-frame-pointer'])
  28. elif (env["target"] == "release_debug"):
  29. env.Append(CCFLAGS=['-O2', '-ffast-math', '-DDEBUG_ENABLED'])
  30. elif (env["target"] == "debug"):
  31. env.Append(CCFLAGS=['-g2', '-DDEBUG_ENABLED', '-DDEBUG_MEMORY_ENABLED'])
  32. ## Architecture
  33. is64 = sys.maxsize > 2**32
  34. if (env["bits"] == "default"):
  35. env["bits"] = "64" if is64 else "32"
  36. ## Compiler configuration
  37. if env['use_llvm']:
  38. if ('clang++' not in os.path.basename(env['CXX'])):
  39. env["CC"] = "clang"
  40. env["CXX"] = "clang++"
  41. env["LINK"] = "clang++"
  42. env.Append(CPPFLAGS=['-DTYPED_METHOD_BIND'])
  43. env.extra_suffix = ".llvm" + env.extra_suffix
  44. ## Dependencies
  45. # FIXME: Check for existence of the libs before parsing their flags with pkg-config
  46. # freetype depends on libpng and zlib, so bundling one of them while keeping others
  47. # as shared libraries leads to weird issues
  48. if env['builtin_freetype'] or env['builtin_libpng'] or env['builtin_zlib']:
  49. env['builtin_freetype'] = True
  50. env['builtin_libpng'] = True
  51. env['builtin_zlib'] = True
  52. if not env['builtin_freetype']:
  53. env.ParseConfig('pkg-config freetype2 --cflags --libs')
  54. if not env['builtin_libpng']:
  55. env.ParseConfig('pkg-config libpng --cflags --libs')
  56. if not env['builtin_bullet']:
  57. # We need at least version 2.88
  58. import subprocess
  59. bullet_version = subprocess.check_output(['pkg-config', 'bullet', '--modversion']).strip()
  60. if bullet_version < "2.88":
  61. # Abort as system bullet was requested but too old
  62. print("Bullet: System version {0} does not match minimal requirements ({1}). Aborting.".format(bullet_version, "2.88"))
  63. sys.exit(255)
  64. env.ParseConfig('pkg-config bullet --cflags --libs')
  65. if not env['builtin_enet']:
  66. env.ParseConfig('pkg-config libenet --cflags --libs')
  67. if not env['builtin_squish'] and env['tools']:
  68. env.ParseConfig('pkg-config libsquish --cflags --libs')
  69. if not env['builtin_zstd']:
  70. env.ParseConfig('pkg-config libzstd --cflags --libs')
  71. # Sound and video libraries
  72. # Keep the order as it triggers chained dependencies (ogg needed by others, etc.)
  73. if not env['builtin_libtheora']:
  74. env['builtin_libogg'] = False # Needed to link against system libtheora
  75. env['builtin_libvorbis'] = False # Needed to link against system libtheora
  76. env.ParseConfig('pkg-config theora theoradec --cflags --libs')
  77. if not env['builtin_libvpx']:
  78. env.ParseConfig('pkg-config vpx --cflags --libs')
  79. if not env['builtin_libvorbis']:
  80. env['builtin_libogg'] = False # Needed to link against system libvorbis
  81. env.ParseConfig('pkg-config vorbis vorbisfile --cflags --libs')
  82. if not env['builtin_opus']:
  83. env['builtin_libogg'] = False # Needed to link against system opus
  84. env.ParseConfig('pkg-config opus opusfile --cflags --libs')
  85. if not env['builtin_libogg']:
  86. env.ParseConfig('pkg-config ogg --cflags --libs')
  87. if not env['builtin_libwebp']:
  88. env.ParseConfig('pkg-config libwebp --cflags --libs')
  89. if not env['builtin_mbedtls']:
  90. # mbedTLS does not provide a pkgconfig config yet. See https://github.com/ARMmbed/mbedtls/issues/228
  91. env.Append(LIBS=['mbedtls', 'mbedcrypto', 'mbedx509'])
  92. if not env['builtin_libwebsockets']:
  93. env.ParseConfig('pkg-config libwebsockets --cflags --libs')
  94. if not env['builtin_miniupnpc']:
  95. # No pkgconfig file so far, hardcode default paths.
  96. env.Append(CPPPATH=["/usr/include/miniupnpc"])
  97. env.Append(LIBS=["miniupnpc"])
  98. # On Linux wchar_t should be 32-bits
  99. # 16-bit library shouldn't be required due to compiler optimisations
  100. if not env['builtin_pcre2']:
  101. env.ParseConfig('pkg-config libpcre2-32 --cflags --libs')
  102. ## Flags
  103. # Linkflags below this line should typically stay the last ones
  104. if not env['builtin_zlib']:
  105. env.ParseConfig('pkg-config zlib --cflags --libs')
  106. env.Append(CPPPATH=['#platform/server'])
  107. env.Append(CPPFLAGS=['-DSERVER_ENABLED', '-DUNIX_ENABLED'])
  108. if (platform.system() == "Darwin"):
  109. env.Append(LINKFLAGS=['-framework', 'Cocoa', '-framework', 'Carbon', '-lz', '-framework', 'IOKit'])
  110. env.Append(LIBS=['pthread'])
  111. if (platform.system() == "Linux"):
  112. env.Append(LIBS=['dl'])
  113. if (platform.system().find("BSD") >= 0):
  114. env.Append(LIBS=['execinfo'])
  115. # Link those statically for portability
  116. if env['use_static_cpp']:
  117. env.Append(LINKFLAGS=['-static-libgcc', '-static-libstdc++'])