| OLD | NEW |
| 1 # Copyright (c) 2013 Google Inc. All rights reserved. | 1 # Copyright (c) 2013 Google Inc. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """cmake output module | 5 """cmake output module |
| 6 | 6 |
| 7 This module is under development and should be considered experimental. | 7 This module is under development and should be considered experimental. |
| 8 | 8 |
| 9 This module produces cmake (2.8.8+) input as its output. One CMakeLists.txt is | 9 This module produces cmake (2.8.8+) input as its output. One CMakeLists.txt is |
| 10 created for each configuration. | 10 created for each configuration. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 there is a mismatch between gyp and cmake with regard to linking. All attempts | 21 there is a mismatch between gyp and cmake with regard to linking. All attempts |
| 22 are made to work around this, but CMake sometimes sees -Wl,--start-group as a | 22 are made to work around this, but CMake sometimes sees -Wl,--start-group as a |
| 23 library and incorrectly repeats it. As a result the output of this generator | 23 library and incorrectly repeats it. As a result the output of this generator |
| 24 should not be relied on for building. | 24 should not be relied on for building. |
| 25 | 25 |
| 26 When using with kdevelop, use version 4.4+. Previous versions of kdevelop will | 26 When using with kdevelop, use version 4.4+. Previous versions of kdevelop will |
| 27 not be able to find the header file directories described in the generated | 27 not be able to find the header file directories described in the generated |
| 28 CMakeLists.txt file. | 28 CMakeLists.txt file. |
| 29 """ | 29 """ |
| 30 | 30 |
| 31 from __future__ import print_function |
| 32 |
| 31 import multiprocessing | 33 import multiprocessing |
| 32 import os | 34 import os |
| 33 import signal | 35 import signal |
| 34 import string | 36 import string |
| 35 import subprocess | 37 import subprocess |
| 36 import gyp.common | 38 import gyp.common |
| 37 import gyp.xcode_emulation | 39 import gyp.xcode_emulation |
| 38 | 40 |
| 41 try: |
| 42 string.maketrans |
| 43 except NameError: |
| 44 # maketrans was moved to str in python 3 |
| 45 string.maketrans = str.maketrans |
| 46 |
| 39 generator_default_variables = { | 47 generator_default_variables = { |
| 40 'EXECUTABLE_PREFIX': '', | 48 'EXECUTABLE_PREFIX': '', |
| 41 'EXECUTABLE_SUFFIX': '', | 49 'EXECUTABLE_SUFFIX': '', |
| 42 'STATIC_LIB_PREFIX': 'lib', | 50 'STATIC_LIB_PREFIX': 'lib', |
| 43 'STATIC_LIB_SUFFIX': '.a', | 51 'STATIC_LIB_SUFFIX': '.a', |
| 44 'SHARED_LIB_PREFIX': 'lib', | 52 'SHARED_LIB_PREFIX': 'lib', |
| 45 'SHARED_LIB_SUFFIX': '.so', | 53 'SHARED_LIB_SUFFIX': '.so', |
| 46 'SHARED_LIB_DIR': '${builddir}/lib.${TOOLSET}', | 54 'SHARED_LIB_DIR': '${builddir}/lib.${TOOLSET}', |
| 47 'LIB_DIR': '${obj}.${TOOLSET}', | 55 'LIB_DIR': '${obj}.${TOOLSET}', |
| 48 'INTERMEDIATE_DIR': '${obj}.${TOOLSET}/${TARGET}/geni', | 56 'INTERMEDIATE_DIR': '${obj}.${TOOLSET}/${TARGET}/geni', |
| (...skipping 812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 861 default_product_ext = generator_default_variables['STATIC_LIB_SUFFIX'] | 869 default_product_ext = generator_default_variables['STATIC_LIB_SUFFIX'] |
| 862 | 870 |
| 863 elif target_type in ('loadable_module', 'shared_library'): | 871 elif target_type in ('loadable_module', 'shared_library'): |
| 864 shared_library_prefix = generator_default_variables['SHARED_LIB_PREFIX'] | 872 shared_library_prefix = generator_default_variables['SHARED_LIB_PREFIX'] |
| 865 default_product_name = RemovePrefix(default_product_name, | 873 default_product_name = RemovePrefix(default_product_name, |
| 866 shared_library_prefix) | 874 shared_library_prefix) |
| 867 default_product_prefix = shared_library_prefix | 875 default_product_prefix = shared_library_prefix |
| 868 default_product_ext = generator_default_variables['SHARED_LIB_SUFFIX'] | 876 default_product_ext = generator_default_variables['SHARED_LIB_SUFFIX'] |
| 869 | 877 |
| 870 elif target_type != 'executable': | 878 elif target_type != 'executable': |
| 871 print ('ERROR: What output file should be generated?', | 879 print(('ERROR: What output file should be generated?', |
| 872 'type', target_type, 'target', target_name) | 880 'type', target_type, 'target', target_name)) |
| 873 | 881 |
| 874 product_prefix = spec.get('product_prefix', default_product_prefix) | 882 product_prefix = spec.get('product_prefix', default_product_prefix) |
| 875 product_name = spec.get('product_name', default_product_name) | 883 product_name = spec.get('product_name', default_product_name) |
| 876 product_ext = spec.get('product_extension') | 884 product_ext = spec.get('product_extension') |
| 877 if product_ext: | 885 if product_ext: |
| 878 product_ext = '.' + product_ext | 886 product_ext = '.' + product_ext |
| 879 else: | 887 else: |
| 880 product_ext = default_product_ext | 888 product_ext = default_product_ext |
| 881 | 889 |
| 882 SetTargetProperty(output, cmake_target_name, 'PREFIX', product_prefix) | 890 SetTargetProperty(output, cmake_target_name, 'PREFIX', product_prefix) |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1200 # output_dir: relative path from generator_dir to the build directory. | 1208 # output_dir: relative path from generator_dir to the build directory. |
| 1201 output_dir = generator_flags.get('output_dir', 'out') | 1209 output_dir = generator_flags.get('output_dir', 'out') |
| 1202 | 1210 |
| 1203 for config_name in configurations: | 1211 for config_name in configurations: |
| 1204 # build_dir: relative path from source root to our output files. | 1212 # build_dir: relative path from source root to our output files. |
| 1205 # e.g. "out/Debug" | 1213 # e.g. "out/Debug" |
| 1206 build_dir = os.path.normpath(os.path.join(generator_dir, | 1214 build_dir = os.path.normpath(os.path.join(generator_dir, |
| 1207 output_dir, | 1215 output_dir, |
| 1208 config_name)) | 1216 config_name)) |
| 1209 arguments = ['cmake', '-G', 'Ninja'] | 1217 arguments = ['cmake', '-G', 'Ninja'] |
| 1210 print 'Generating [%s]: %s' % (config_name, arguments) | 1218 print('Generating [%s]: %s' % (config_name, arguments)) |
| 1211 subprocess.check_call(arguments, cwd=build_dir) | 1219 subprocess.check_call(arguments, cwd=build_dir) |
| 1212 | 1220 |
| 1213 arguments = ['ninja', '-C', build_dir] | 1221 arguments = ['ninja', '-C', build_dir] |
| 1214 print 'Building [%s]: %s' % (config_name, arguments) | 1222 print('Building [%s]: %s' % (config_name, arguments)) |
| 1215 subprocess.check_call(arguments) | 1223 subprocess.check_call(arguments) |
| 1216 | 1224 |
| 1217 | 1225 |
| 1218 def CallGenerateOutputForConfig(arglist): | 1226 def CallGenerateOutputForConfig(arglist): |
| 1219 # Ignore the interrupt signal so that the parent process catches it and | 1227 # Ignore the interrupt signal so that the parent process catches it and |
| 1220 # kills all multiprocessing children. | 1228 # kills all multiprocessing children. |
| 1221 signal.signal(signal.SIGINT, signal.SIG_IGN) | 1229 signal.signal(signal.SIGINT, signal.SIG_IGN) |
| 1222 | 1230 |
| 1223 target_list, target_dicts, data, params, config_name = arglist | 1231 target_list, target_dicts, data, params, config_name = arglist |
| 1224 GenerateOutputForConfig(target_list, target_dicts, data, params, config_name) | 1232 GenerateOutputForConfig(target_list, target_dicts, data, params, config_name) |
| 1225 | 1233 |
| 1226 | 1234 |
| 1227 def GenerateOutput(target_list, target_dicts, data, params): | 1235 def GenerateOutput(target_list, target_dicts, data, params): |
| 1228 user_config = params.get('generator_flags', {}).get('config', None) | 1236 user_config = params.get('generator_flags', {}).get('config', None) |
| 1229 if user_config: | 1237 if user_config: |
| 1230 GenerateOutputForConfig(target_list, target_dicts, data, | 1238 GenerateOutputForConfig(target_list, target_dicts, data, |
| 1231 params, user_config) | 1239 params, user_config) |
| 1232 else: | 1240 else: |
| 1233 config_names = target_dicts[target_list[0]]['configurations'].keys() | 1241 config_names = target_dicts[target_list[0]]['configurations'] |
| 1234 if params['parallel']: | 1242 if params['parallel']: |
| 1235 try: | 1243 try: |
| 1236 pool = multiprocessing.Pool(len(config_names)) | 1244 pool = multiprocessing.Pool(len(config_names)) |
| 1237 arglists = [] | 1245 arglists = [] |
| 1238 for config_name in config_names: | 1246 for config_name in config_names: |
| 1239 arglists.append((target_list, target_dicts, data, | 1247 arglists.append((target_list, target_dicts, data, |
| 1240 params, config_name)) | 1248 params, config_name)) |
| 1241 pool.map(CallGenerateOutputForConfig, arglists) | 1249 pool.map(CallGenerateOutputForConfig, arglists) |
| 1242 except KeyboardInterrupt, e: | 1250 except KeyboardInterrupt as e: |
| 1243 pool.terminate() | 1251 pool.terminate() |
| 1244 raise e | 1252 raise e |
| 1245 else: | 1253 else: |
| 1246 for config_name in config_names: | 1254 for config_name in config_names: |
| 1247 GenerateOutputForConfig(target_list, target_dicts, data, | 1255 GenerateOutputForConfig(target_list, target_dicts, data, |
| 1248 params, config_name) | 1256 params, config_name) |
| OLD | NEW |