Skip to content
Snippets Groups Projects
Commit dc7a4389 authored by Dominik Thoennes's avatar Dominik Thoennes
Browse files

adjust refactor cmake script to add subdirectories

parent a385588d
No related branches found
No related tags found
No related merge requests found
import argparse
#!/usr/bin/env python3 #!/usr/bin/env python3
import os import os
import re import re
import argparse
def create_cmake_lists (folder, module_name, top_level=True, deps = []): def create_cmake_lists (folder, module_name, top_level=True, deps = []):
header_and_source = [] header_and_source = []
subfolder = [] subfolder = []
newline = '\n ' newline_and_indent = '\n '
newline = '\n'
add_sub = '\nadd_subdirectory( ' add_sub = '\nadd_subdirectory( '
for entry in os.scandir(folder): for entry in os.scandir(folder):
if entry.name == 'all.h': if entry.name == 'all.h':
continue continue
if entry.is_file(): if entry.is_file():
if entry.name.endswith('.h') or entry.name.endswith('.cpp'): if entry.name.endswith('.hpp') or entry.name.endswith('.h') or entry.name.endswith('.cpp'):
header_and_source += [entry.name] header_and_source += [entry.name]
else: else:
if entry.name != 'doc' and entry.name != 'CMakeFiles': if entry.name != 'doc' and entry.name != 'CMakeFiles':
subfolder += [entry.name] subfolder += [entry.name]
create_cmake_lists(folder + '/' + entry.name, module_name, False) create_cmake_lists(folder + '/' + entry.name, module_name, False)
print(subfolder) # print(subfolder)
if not header_and_source: # if not header_and_source:
return # return
if top_level: if top_level:
with open(folder + '/CMakeListsRefactor.txt', 'w') as f: with open(folder + '/CMakeListsRefactor.txt', 'w') as f:
...@@ -32,7 +31,7 @@ def create_cmake_lists (folder, module_name, top_level=True, deps = []): ...@@ -32,7 +31,7 @@ def create_cmake_lists (folder, module_name, top_level=True, deps = []):
target_link_libraries( {module_name} PUBLIC {' '.join(x for x in deps)} ) target_link_libraries( {module_name} PUBLIC {' '.join(x for x in deps)} )
target_sources( {module_name} target_sources( {module_name}
PRIVATE PRIVATE
{newline.join(x for x in header_and_source)} {newline_and_indent.join(x for x in header_and_source)}
) )
add_subdirectory( {add_sub.join(x + ' )' for x in subfolder)} add_subdirectory( {add_sub.join(x + ' )' for x in subfolder)}
...@@ -42,8 +41,9 @@ add_subdirectory( {add_sub.join(x + ' )' for x in subfolder)} ...@@ -42,8 +41,9 @@ add_subdirectory( {add_sub.join(x + ' )' for x in subfolder)}
with open(folder + '/CMakeLists.txt', 'w') as f: with open(folder + '/CMakeLists.txt', 'w') as f:
content = f"""target_sources( {module_name} content = f"""target_sources( {module_name}
PRIVATE PRIVATE
{newline.join(x for x in header_and_source)} {newline_and_indent.join(x for x in header_and_source)}
) )
{newline.join(['add_subdirectory( ' + x + ' )' for x in subfolder])}
""" """
f.write(content) f.write(content)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment