Skip to content
Snippets Groups Projects
Commit 900bdc7d authored by Timo Koch's avatar Timo Koch
Browse files

[util] Make cmake lists script executable and increase usability

now defaults to the dumux folder if no other folder is specified as command line argument.
parent c70ba861
No related branches found
No related tags found
1 merge request!1016[cmake] automatically generate CMakeLists.txt files
# Create files CMakeLists.txt for the current folder and all subfolders.
# Should be run from the folder `dumux` that contains the header files, namely,
# one level below the top dumux folder:
# python ../bin/create_cmakelists.py.
#!/usr/bin/env python
"""
Create files CMakeLists.txt for the given folder and all subfolders,
including the add_subdirectory(...) and install(...) commands.
Defaults to the folder `dumux` that contains the header files,
if no folder was specified.
"""
# Import the os module, for the os.walk function
import os
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('folder', type=str, nargs='?', help='the folder to create CMakeLists.txt\'s for', default=None)
args = vars(parser.parse_args())
# default to the dumux folder (relative path to the location of this script)
if args['folder'] is None:
rootDir = os.path.dirname(os.path.abspath(__file__)) + "/../../dumux"
else:
rootDir = args['folder']
# Set the directory you want to start from
rootDir = '.'
for folderName, subFolders, files in os.walk(rootDir):
subFolders = sorted(subFolders)
files = sorted(files)
cmakelists = open(folderName + "/CMakeLists.txt", "w")
for subFolder in subFolders:
cmakelists.write("add_subdirectory(\"%s\")\n" % subFolder)
with open(folderName + "/CMakeLists.txt", "w") as cmakelists:
headersExist = False
for fileName in files:
if fileName != "CMakeLists.txt":
headersExist = True
break
if headersExist:
if subFolders:
cmakelists.write("\n")
cmakelists.write("install(FILES\n")
for subFolder in subFolders:
cmakelists.write("add_subdirectory({})\n".format(subFolder))
headersExist = False
for fileName in files:
if fileName != "CMakeLists.txt":
cmakelists.write("%s\n" % fileName)
headersExist = True
break
if headersExist:
if subFolders:
cmakelists.write("\n")
cmakelists.write("install(FILES\n")
cmakelists.write("DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dumux/%s)\n" % folderName[2:])
for fileName in files:
if fileName != "CMakeLists.txt":
cmakelists.write("{}\n".format(fileName))
cmakelists.close()
cmakelists.write("DESTINATION ${{CMAKE_INSTALL_INCLUDEDIR}}/dumux/{})\n".format(folderName.replace(rootDir + '/', '')))
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