Skip to content
Snippets Groups Projects
Commit 3ef91dc2 authored by Tomáš Pecka's avatar Tomáš Pecka Committed by Jan Trávníček
Browse files

CMakeGen: More constants to config

parent ffe02679
No related branches found
No related tags found
1 merge request!40Dev tp
......@@ -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
......
......@@ -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'])),
))
 
# ----------------------------------------------------------------------------------------------------------------------
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment