| 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 """Resolves rel_path against base_path and returns the result. | 111 """Resolves rel_path against base_path and returns the result. |
| 112 TODO: what is this really used for? | 112 TODO: what is this really used for? |
| 113 If rel_path begins with '$' it is returned unchanged. | 113 If rel_path begins with '$' it is returned unchanged. |
| 114 Otherwise it is resolved against base_path if relative, then normalized. | 114 Otherwise it is resolved against base_path if relative, then normalized. |
| 115 """ | 115 """ |
| 116 if rel_path.startswith('$') and not rel_path.startswith('${configuration}'): | 116 if rel_path.startswith('$') and not rel_path.startswith('${configuration}'): |
| 117 return rel_path | 117 return rel_path |
| 118 return os.path.normpath(os.path.join(base_path, rel_path)) | 118 return os.path.normpath(os.path.join(base_path, rel_path)) |
| 119 | 119 |
| 120 | 120 |
| 121 def EnsureDirectoryExists(path): | |
| 122 """Python version of 'mkdir -p'.""" | |
| 123 dirPath = os.path.dirname(path) | |
| 124 if dirPath and not os.path.exists(dirPath): | |
| 125 os.makedirs(dirPath) | |
| 126 | |
| 127 | |
| 128 def CMakeStringEscape(a): | 121 def CMakeStringEscape(a): |
| 129 """Escapes the string 'a' for use inside a CMake string. | 122 """Escapes the string 'a' for use inside a CMake string. |
| 130 | 123 |
| 131 This means escaping | 124 This means escaping |
| 132 '\' otherwise it may be seen as modifying the next character | 125 '\' otherwise it may be seen as modifying the next character |
| 133 '"' otherwise it will end the string | 126 '"' otherwise it will end the string |
| 134 ';' otherwise the string becomes a list | 127 ';' otherwise the string becomes a list |
| 135 | 128 |
| 136 The following do not need to be escaped | 129 The following do not need to be escaped |
| 137 '#' when the lexer is in string state, this does not start a comment | 130 '#' when the lexer is in string state, this does not start a comment |
| (...skipping 896 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1034 | 1027 |
| 1035 # build_dir: relative path from source root to our output files. | 1028 # build_dir: relative path from source root to our output files. |
| 1036 # e.g. "out/Debug" | 1029 # e.g. "out/Debug" |
| 1037 build_dir = os.path.normpath(os.path.join(generator_dir, | 1030 build_dir = os.path.normpath(os.path.join(generator_dir, |
| 1038 output_dir, | 1031 output_dir, |
| 1039 config_to_use)) | 1032 config_to_use)) |
| 1040 | 1033 |
| 1041 toplevel_build = os.path.join(options.toplevel_dir, build_dir) | 1034 toplevel_build = os.path.join(options.toplevel_dir, build_dir) |
| 1042 | 1035 |
| 1043 output_file = os.path.join(toplevel_build, 'CMakeLists.txt') | 1036 output_file = os.path.join(toplevel_build, 'CMakeLists.txt') |
| 1044 EnsureDirectoryExists(output_file) | 1037 gyp.common.EnsureDirExists(output_file) |
| 1045 | 1038 |
| 1046 output = open(output_file, 'w') | 1039 output = open(output_file, 'w') |
| 1047 output.write('cmake_minimum_required(VERSION 2.8.8 FATAL_ERROR)\n') | 1040 output.write('cmake_minimum_required(VERSION 2.8.8 FATAL_ERROR)\n') |
| 1048 output.write('cmake_policy(VERSION 2.8.8)\n') | 1041 output.write('cmake_policy(VERSION 2.8.8)\n') |
| 1049 | 1042 |
| 1050 _, project_target, _ = gyp.common.ParseQualifiedTarget(target_list[-1]) | 1043 _, project_target, _ = gyp.common.ParseQualifiedTarget(target_list[-1]) |
| 1051 output.write('project(') | 1044 output.write('project(') |
| 1052 output.write(project_target) | 1045 output.write(project_target) |
| 1053 output.write(')\n') | 1046 output.write(')\n') |
| 1054 | 1047 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1141 arglists.append((target_list, target_dicts, data, | 1134 arglists.append((target_list, target_dicts, data, |
| 1142 params, config_name)) | 1135 params, config_name)) |
| 1143 pool.map(CallGenerateOutputForConfig, arglists) | 1136 pool.map(CallGenerateOutputForConfig, arglists) |
| 1144 except KeyboardInterrupt, e: | 1137 except KeyboardInterrupt, e: |
| 1145 pool.terminate() | 1138 pool.terminate() |
| 1146 raise e | 1139 raise e |
| 1147 else: | 1140 else: |
| 1148 for config_name in config_names: | 1141 for config_name in config_names: |
| 1149 GenerateOutputForConfig(target_list, target_dicts, data, | 1142 GenerateOutputForConfig(target_list, target_dicts, data, |
| 1150 params, config_name) | 1143 params, config_name) |
| OLD | NEW |