update_cmakelists.py now support running over multiple directories. (#65)

master
Holger Rapp 2016-10-14 13:43:09 +02:00 committed by GitHub
parent 098349f67e
commit b81e855a8d
1 changed files with 13 additions and 7 deletions

View File

@ -14,6 +14,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
"""A dumb CMakeLists.txt generator that relies on source name conventions.""" """A dumb CMakeLists.txt generator that relies on source name conventions."""
from os import path from os import path
@ -161,20 +162,26 @@ def GetNonGoogleTargetLines(filename):
def ParseArgs(): def ParseArgs():
p = argparse.ArgumentParser( p = argparse.ArgumentParser(
description="Automatically update cMakeFiles using build conventions.") description="Automatically update cMakeFiles using build conventions.")
p.add_argument("root", type=str, help="Source directory.") p.add_argument("root", type=str, nargs="*", help="Source directory.")
args = p.parse_args() args = p.parse_args()
args.root = args.root.rstrip("/")
return args return args
def main(): def main():
args = ParseArgs() args = ParseArgs()
for root in args.root:
RunOnDirectory(root)
def RunOnDirectory(root):
root = root.rstrip("/")
targets_by_src = {} targets_by_src = {}
targets = [] targets = []
project_name = os.path.basename(args.root) project_name = os.path.basename(root)
base_directory = path.realpath(path.join(args.root, path.pardir)) base_directory = path.realpath(path.join(root, path.pardir))
directories = set() directories = set()
def AddTarget(target_type, name, directory, srcs, hdrs): def AddTarget(target_type, name, directory, srcs, hdrs):
@ -190,9 +197,8 @@ def main():
targets_by_src[proto_stem + ".pb.cc"] = target targets_by_src[proto_stem + ".pb.cc"] = target
directories.add(directory) directories.add(directory)
for (directory, sources) in FindSourceFiles(args.root): for (directory, sources) in FindSourceFiles(root):
module_name = path.relpath(directory, module_name = path.relpath(directory, path.realpath(root)).replace("/", "_")
path.realpath(args.root)).replace("/", "_")
prepend_module_name = lambda s: (module_name + "_" + s) if module_name != "." else s prepend_module_name = lambda s: (module_name + "_" + s) if module_name != "." else s
headers = set(fn for fn in sources if fn.endswith(".h")) headers = set(fn for fn in sources if fn.endswith(".h"))