Created
March 31, 2013 13:12
-
-
Save yocchi/5280556 to your computer and use it in GitHub Desktop.
emacs flymake helper script for cmake & ninja
usage: SOURCE_DIR$ GenerateFlyMakefilesNinja.py BUILD_DIR
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# emacs flymake helper script for cmake & ninja | |
import os | |
import sys | |
def is_build_dir(build_dir): | |
cmakecache = os.path.join(build_dir, 'CMakeCache.txt') | |
if os.path.exists(cmakecache): | |
return True | |
return False | |
def create_flymakefile(source_dir, build_ninja_path): | |
f = open(os.path.join(source_dir, 'Makefile'), 'w') | |
f.write('# Generated by GenerateFlyMakefilesNinja.py\n') | |
f.write('CXX_DEFINES=$(shell grep -m1 -A1 ${CHK_SOURCES} %s | grep DEFINES | sed "s/.\+DEFINES = //g")\n' % build_ninja_path) | |
f.write('CXX_FLAGS=$(shell grep -m1 -A3 ${CHK_SOURCES} %s | grep FLAGS | sed "s/.\+FLAGS = //g")\n' % build_ninja_path) | |
f.write('check-syntax:\n') | |
f.write('\tc++ -o /dev/null ${CXX_FLAGS} ${CXX_DEFINES} -S ${CHK_SOURCES}\n') | |
f.write('.PHONY: check-syntax\n') | |
f.close() | |
if __name__ == '__main__': | |
if len(sys.argv) != 2: | |
print '''usage: | |
GenerateFlyMakefilesNinja.py BUILD_DIR''' | |
sys.exit(-1) | |
SOURCE_DIR = '.' | |
BUILD_DIR = os.path.abspath(sys.argv[1]) | |
if not is_build_dir(BUILD_DIR): | |
print '%s does not include CMakeCache.txt' % BUILD_DIR | |
sys.exit(-1) | |
build_ninja_path = BUILD_DIR + '/build.ninja' | |
for root, dirs, files in os.walk(SOURCE_DIR): | |
if not "CMakeLists.txt" in files: | |
continue | |
create_flymakefile(root, build_ninja_path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment