Skip to content

Instantly share code, notes, and snippets.

@donkaban donkaban/CMake gen
Created May 10, 2016

Embed
What would you like to do?
#!/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
You can’t perform that action at this time.