run_cmake.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # This file is part of Desktop App Toolkit,
  2. # a set of libraries for developing nice desktop applications.
  3. #
  4. # For license and copyright information please follow this link:
  5. # https://github.com/desktop-app/legal/blob/master/LEGAL
  6. import sys, os, shutil, subprocess
  7. def run(project, arguments, buildType=''):
  8. scriptPath = os.path.dirname(os.path.realpath(__file__))
  9. basePath = scriptPath + '/../out/' + buildType
  10. cmake = ['cmake']
  11. vsArch = ''
  12. explicitGenerator = False
  13. for arg in arguments:
  14. if arg == 'debug':
  15. cmake.append('-DCMAKE_BUILD_TYPE=Debug')
  16. elif arg == 'x86' or arg == 'x64' or arg == 'arm':
  17. vsArch = arg
  18. elif arg != 'force':
  19. if arg.startswith('-G'):
  20. explicitGenerator = True
  21. cmake.append(arg)
  22. if sys.platform == 'win32' and not explicitGenerator:
  23. if vsArch == 'x64':
  24. cmake.append('-Ax64')
  25. elif vsArch == 'arm':
  26. cmake.append('-AARM64')
  27. else:
  28. cmake.append('-AWin32') # default
  29. elif vsArch != '':
  30. print("[ERROR] x86/x64/arm switch is supported only with Visual Studio.")
  31. return 1
  32. elif sys.platform == 'darwin':
  33. if not explicitGenerator:
  34. cmake.append('-GXcode')
  35. else:
  36. if not explicitGenerator:
  37. cmake.append('-GNinja Multi-Config')
  38. elif buildType:
  39. cmake.append('-DCMAKE_BUILD_TYPE=' + buildType)
  40. elif not '-DCMAKE_BUILD_TYPE=Debug' in cmake:
  41. cmake.append('-DCMAKE_BUILD_TYPE=Release')
  42. specialTarget = ''
  43. specialTargetFile = scriptPath + '/../' + project + '/build/target'
  44. if os.path.isfile(specialTargetFile):
  45. with open(specialTargetFile, 'r') as f:
  46. for line in f:
  47. target = line.strip()
  48. if len(target) > 0:
  49. cmake.append('-DDESKTOP_APP_SPECIAL_TARGET=' + target)
  50. cmake.extend(['-Werror=dev', '-Werror=deprecated', '--warn-uninitialized', '..' if not buildType else '../..'])
  51. command = '"' + '" "'.join(cmake) + '"'
  52. if not os.path.exists(basePath):
  53. os.makedirs(basePath)
  54. elif 'force' in arguments:
  55. paths = os.listdir(basePath)
  56. for path in paths:
  57. low = path.lower();
  58. if not low.startswith('debug') and not low.startswith('release'):
  59. full = basePath + '/' + path
  60. if os.path.isdir(full):
  61. shutil.rmtree(full, ignore_errors=False)
  62. else:
  63. os.remove(full)
  64. print('Cleared previous.')
  65. os.chdir(basePath)
  66. return subprocess.call(command, shell=True)