#!/usr/bin/env python3 """ Convert all NGL_ADD_LIBRARY with SHARED to NGL_ADD_LIBRARY2 to ensure export headers are generated for shared libraries. """ import os import re import sys def fix_cmake_file(filepath): """Convert NGL_ADD_LIBRARY to NGL_ADD_LIBRARY2 for SHARED libraries.""" with open(filepath, 'r', encoding='utf-8', errors='ignore') as f: content = f.read() original = content # Pattern: NGL_ADD_LIBRARY followed by args containing SHARED # We need to be careful to only match NGL_ADD_LIBRARY, not NGL_ADD_LIBRARY2 pattern = r'\bNGL_ADD_LIBRARY\s*\(([^)]*SHARED[^)]*)\)' def replace_match(m): args = m.group(1) return f'NGL_ADD_LIBRARY2({args})' content = re.sub(pattern, replace_match, content) if content != original: with open(filepath, 'w', encoding='utf-8') as f: f.write(content) return True, 1, 0 return False, 0, 0 def main(): if len(sys.argv) < 2: print("Usage: fix_add_library2.py ") sys.exit(1) base_dir = sys.argv[1] fixed = 0 skipped = 0 errors = 0 for root, dirs, files in os.walk(base_dir): # Skip .git and build directories dirs[:] = [d for d in dirs if d not in ['.git', 'build', 'build_test', 'build_test4']] for file in files: if file == 'CMakeLists.txt': filepath = os.path.join(root, file) try: changed, f, e = fix_cmake_file(filepath) if changed: fixed += 1 print(f"Fixed: {filepath}") else: skipped += 1 except Exception as ex: errors += 1 print(f"Error {filepath}: {ex}") print(f"\n=== Summary ===") print(f"Fixed: {fixed}") print(f"Skipped: {skipped}") print(f"Errors: {errors}") if __name__ == '__main__': main()