Skip to content

Commit

Permalink
Merge pull request #30 from AbigailBuccaneer/AbigailBuccaneer-patch-1
Browse files Browse the repository at this point in the history
 Give targets smarter names
  • Loading branch information
AbigailBuccaneer authored Jul 24, 2018
2 parents 5a89401 + 5d0e59b commit 1652245
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 15 additions & 2 deletions json2cmake/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import argparse
import json
import os.path
import re
import shlex
import subprocess
import sys
import uuid

try:
basestring
Expand Down Expand Up @@ -114,9 +114,22 @@ def write(self, output, directory=None, name='autogenerated'):
output.write('cmake_minimum_required(VERSION 2.8.8)\n')
output.write('project({})\n\n'.format(name))

used_names = {""}
disallowed_characters = re.compile("[^A-Za-z0-9_.+\-]")

for (config, files) in self.targets.items():
config = {k: v for (k, v) in config}
name = uuid.uuid4()
name = os.path.basename(os.path.commonprefix(files).rstrip("/_"))
name = re.sub(disallowed_characters, "", name)
if name in used_names:
index = 2
while True:
candidate = '{}_{}'.format(name, index)
if candidate not in used_names:
name = candidate
break
index = index + 1
used_names.add(name)

output.write('add_library(%s OBJECT\n' % name)
for file in files:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

setup(
name='json2cmake',
version='0.6.2',
version='0.6.3',
description='Generate CMakeLists.txt from a compile_commands.json',
long_description=long_description,
url='https://github.com/AbigailBuccaneer/json2cmake',
Expand Down

0 comments on commit 1652245

Please sign in to comment.