From ccb0306506bf5bf400ddbb60a9ddc7bd507e8d1e Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Fri, 22 Feb 2019 12:46:26 +1100 Subject: [PATCH] initial import --- .gitignore | 2 ++ init.py | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 .gitignore create mode 100755 init.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..70a618f --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/debug +/release diff --git a/init.py b/init.py new file mode 100755 index 0000000..31b9f9a --- /dev/null +++ b/init.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python3 + +import sys +import os +import itertools + + +OPTIONS = { + # compiler + 'gcc': {'vars': {'CMAKE_CXX_COMPILER': 'g++', 'CMAKE_C_COMPILER': 'gcc'}}, + 'clang': {'vars': {'CMAKE_CXX_COMPILER': 'clang++', 'CMAKE_C_COMPILER': 'clang'}}, + + # profile + 'debug': {'vars': {'CMAKE_BUILD_TYPE': 'Debug', 'LTO': 'OFF'}, 'args': ['-G', '"Unix Makefiles"']}, + 'release': {'vars': {'CMAKE_BUILD_TYPE': 'Release', 'LTO': 'ON'}}, + + # sanitizer + 'sanitizer': {'vars': {'SANITIZER': 'ON'}, 'require': {'PROFILE': 'release'}}, + + # Default parameters + '': { + 'vars': { + "CMAKE_EXPORT_COMPILE_COMMANDS": "ON", + "TESTS": "ON", + }, + + 'args': ['-G', 'Ninja'], + }, +} + + +def split_all_path(path): + parts = [] + + while len(path) > 1: + head,tail = os.path.split(path) + yield tail + path = head + + +if __name__ == '__main__': + accumulated = [] + + components = [''] + components += sys.argv[1:] + components += itertools.takewhile(lambda x: x in OPTIONS, split_all_path(os.getcwd())) + + for key in components: + obj = OPTIONS[key] + + vars = obj.get('vars', {}) + args = obj.get('args', []) + + accumulated += [f"-D{key}={val}" for key, val in vars.items()] + accumulated += args + + print("cmake ../../../ " + " ".join(accumulated))