Skip to content

Instantly share code, notes, and snippets.

@donkaban
Created May 10, 2016 13:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save donkaban/27d88b09c240dca4c9a35b14cf44b5e8 to your computer and use it in GitHub Desktop.
Save donkaban/27d88b09c240dca4c9a35b14cf44b5e8 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import sys
import os
import re
include_dirs = set()
source_files = set()
def _search(path):
# print(path)
for file in os.listdir(path):
if (file == ".") or (file == ".."):
continue
full_name = os.path.join(path, file)
if os.path.isdir(full_name) and not os.path.islink(path):
_search(full_name)
if re.search("\\.(c|cpp|cxx)$", file) is not None:
source_files.add(full_name)
elif re.search("\\.(h|hpp)$", file) is not None:
include_dirs.add(path)
if len(sys.argv) < 2:
print("Usage " + sys.argv[0] + " <path>")
sys.exit(1)
start_path = sys.argv[1]
_search(start_path)
print("cmake_minimum_required(VERSION 2.8)")
print("project(z_project)")
skip_chars = len(start_path) + 1
for dir in sorted(include_dirs):
print("include_directories(" + dir[skip_chars:] + ")")
print("add_executable(z_executable")
for file in sorted(source_files):
print(" " + file[skip_chars:])
print(")")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment