diff --git a/CMake/config.ini b/CMake/config.ini index 4e9fd5c5899444e373109df424e810d182ff171f..6b8539753958018b88b926b22cff7c69329eb0a3 100644 --- a/CMake/config.ini +++ b/CMake/config.ini @@ -3,11 +3,17 @@ major = 0 minor = 0 patch = 1 -[Templates] + +[CMake:Templates] root = CMakeLists_root.txt lib = CMakeLists_lib.txt bin = CMakeLists_bin.txt +[CMake:Sources] +ExcludeSources: .txx, .cxx, .hxx +SourcesDir: src +TestSourcesDir: test-src + [ModulesLib] alib2algo alib2algo_experimental diff --git a/CMake/generate.py b/CMake/generate.py index e250be7063e59228ab05cce18c4b562f5fc8964d..8b2701d6d47081eb360a441970580948791824c4 100755 --- a/CMake/generate.py +++ b/CMake/generate.py @@ -9,6 +9,8 @@ import argparse class SmartOpen: + SEPARATOR_SIZE = 20 + def __init__(self, filename, mode='r', *, directory='.', encoding=None, dry_run=False): self._dry_run = dry_run self._filename = filename @@ -24,13 +26,13 @@ class SmartOpen: def __enter__(self): if self._dry_run and 'w' in self._mode: - self._fd.write(f'{self._filename}\n' + '-' * SEPARATOR_SIZE + '\n') + self._fd.write(f'{self._filename}\n' + '-' * self.SEPARATOR_SIZE + '\n') return self._fd def __exit__(self, d_type, value, traceback): if self._dry_run and 'w' in self._mode: - self._fd.write('-' * SEPARATOR_SIZE + '\n') + self._fd.write('-' * self.SEPARATOR_SIZE + '\n') if self._fd != sys.stdout: self._fd.close() @@ -40,9 +42,6 @@ class SmartOpen: SCRIPT_DIRECTORY = os.path.join(os.path.dirname(__file__)) ALIB_DIRECTORY = os.path.join(SCRIPT_DIRECTORY, "..") -SEPARATOR_SIZE = 20 - -SOURCES_EXCLUDE = ('.cxx', '.hxx', '.txx') config = configparser.ConfigParser(allow_no_value=True) config.read(os.path.join(SCRIPT_DIRECTORY, 'config.ini')) @@ -56,7 +55,7 @@ PACKAGES = { } TEMPLATES = { - tpl: SmartOpen(config['Templates'][tpl], directory=SCRIPT_DIRECTORY, mode='r').read() for tpl in ['root', 'lib', 'bin'] + tpl: SmartOpen(config['CMake:Templates'][tpl], directory=SCRIPT_DIRECTORY, mode='r').read() for tpl in ['root', 'lib', 'bin'] } @@ -74,9 +73,11 @@ def get_source_files(project_name, directory): source_files = [] relpath_ref = os.path.join(ALIB_DIRECTORY, project_name) + exclude_sources = tuple(map(lambda s: s.strip(), config['CMake:Sources']['ExcludeSources'].split(','))) + for dp, dn, fn in os.walk(os.path.join(relpath_ref, directory)): source_files = source_files + [os.path.relpath(os.path.join(dp, file), relpath_ref) - for file in fn if not file.endswith(SOURCES_EXCLUDE)] + for file in fn if not file.endswith(exclude_sources)] return source_files @@ -145,9 +146,6 @@ def create_root_cmakelist(dry_run, packages): alib_versioning_patch=config['Versioning']['patch'], )) - if dry_run: - f.write('-' * SEPARATOR_SIZE + '\n') - def create_library_package(project_name, dry_run): link_libs, link_test_libs, include_libs, include_test_libs, cmake_options = parse_makeconfig( @@ -161,8 +159,8 @@ def create_library_package(project_name, dry_run): include_paths=include_libs, include_test_paths=include_test_libs, cmake_options=cmake_options, - source_files=to_rows(get_source_files(project_name, 'src')), - source_files_test=to_rows(get_source_files(project_name, 'test-src')), + source_files=to_rows(get_source_files(project_name, config['CMake:Sources']['SourcesDir'])), + source_files_test=to_rows(get_source_files(project_name, config['CMake:Sources']['TestSourcesDir'])), )) @@ -178,7 +176,7 @@ def create_executable_package(project_name, dry_run): include_paths=include_libs, include_test_paths=include_test_libs, cmake_options=cmake_options, - source_files=to_rows(get_source_files(project_name, 'src')), + source_files=to_rows(get_source_files(project_name, config['CMake:Sources']['SourcesDir'])), )) # ----------------------------------------------------------------------------------------------------------------------