| 60 | |
| 61 | |
| 62 | def generate_modules(cmake_version: str): |
| 63 | dst = os.path.join(local_modules, 'prebuilt') |
| 64 | lib = 'lib/emscripten' |
| 65 | share = 'share/libc++/v1' |
| 66 | |
| 67 | build_dir = f'{emscripten_root}/out/libcxx/modules' |
| 68 | binary_dir = f'{build_dir}/out' |
| 69 | dist = f'{binary_dir}/dist/' |
| 70 | |
| 71 | clean_dir(build_dir) |
| 72 | os.makedirs(build_dir, exist_ok=True) |
| 73 | with open(f'{build_dir}/CMakeLists.txt', 'x', encoding='utf-8') as CMakeLists: |
| 74 | CMakeLists.write(f'''\ |
| 75 | cmake_minimum_required(VERSION {cmake_version}) |
| 76 | project(libcxx-modules) |
| 77 | add_subdirectory("{local_modules}" libcxx) |
| 78 | ''') |
| 79 | |
| 80 | vars = [ |
| 81 | ('LIBCXX_INSTALL_LIBRARY_DIR', lib), |
| 82 | ('LIBCXX_INSTALL_MODULES_DIR', share), |
| 83 | ('LIBCXX_LIBRARY_DIR', dist + lib), |
| 84 | ('LIBCXX_GENERATED_MODULE_DIR', dist + share), |
| 85 | ] |
| 86 | |
| 87 | cmd = ['cmake', '-B', binary_dir, '-S', build_dir] |
| 88 | cmd += [f'-D{key}={val}' for key, val in vars] |
| 89 | |
| 90 | subprocess.run(cmd, stdout=subprocess.DEVNULL) |
| 91 | subprocess.run(['cmake', '--build', binary_dir], stdout=subprocess.DEVNULL) |
| 92 | shutil.copytree(dist, dst, dirs_exist_ok=True) |
| 93 | |
| 94 | def main(): |
| 95 | # Exit early if cmake is not found |