From f840c93c543b38c24d4ebea3ecf59d2872d3db08 Mon Sep 17 00:00:00 2001 From: "Jonathan B. Coe" Date: Mon, 26 Sep 2016 23:31:06 +0100 Subject: [PATCH] Build with cmake using Python build script --- .gitmodules | 4 ++-- CMakeLists.txt | 14 ++++++++++++++ scripts/build.py | 26 ++++++++++++++++++++++++++ submodules/{GSL => gsl} | 0 test_graph.cpp | 2 +- 5 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 CMakeLists.txt create mode 100755 scripts/build.py rename submodules/{GSL => gsl} (100%) diff --git a/.gitmodules b/.gitmodules index 6ad6636..81f8d6f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ -[submodule "submodules/GSL"] - path = submodules/GSL +[submodule "submodules/gsl"] + path = submodules/gsl url = https://github.com/Microsoft/GSL.git diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..674396d --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.1) + +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED on) + +include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/submodules/gsl) + +add_executable(test_basic test.cpp) +add_executable(test_graph test_graph.cpp) + +enable_testing() + +add_test(test_basic ${CMAKE_BINARY_DIR}/test_basic -s) +add_test(test_graph ${CMAKE_BINARY_DIR}/test_graph -s) diff --git a/scripts/build.py b/scripts/build.py new file mode 100755 index 0000000..712edb0 --- /dev/null +++ b/scripts/build.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python +import sys +import os +import subprocess + +def main(): + import argparse + parser = argparse.ArgumentParser() + parser.add_argument("--tests", help="run tests", action="store_true", dest="run_tests") + parser.add_argument("--output", help="output dir (relative to source dir)", default="build", dest="out_dir") + parser.add_argument("--config", help="build config", default="Debug", dest="config") + args = parser.parse_args() + + src_dir = os.path.dirname(os.path.dirname(__file__)) + + subprocess.check_call("cmake . -B{} -DCMAKE_BUILD_TYPE={}".format(args.out_dir, args.config).split(), cwd=src_dir) + subprocess.check_call("cmake --build ./{}".format(args.out_dir).split(), cwd=src_dir) + + if args.run_tests: + rc = subprocess.call("ctest . --output-on-failure".split(), cwd=os.path.join(src_dir,args.out_dir)) + if rc != 0: + sys.exit(1) + +if __name__ == "__main__": + main() + diff --git a/submodules/GSL b/submodules/gsl similarity index 100% rename from submodules/GSL rename to submodules/gsl diff --git a/test_graph.cpp b/test_graph.cpp index 4e9b80a..57e6753 100644 --- a/test_graph.cpp +++ b/test_graph.cpp @@ -141,7 +141,7 @@ bool TestCase3() { return Counter::count() == 4; } -int _main() { +int main() { cout.setf(ios::boolalpha); bool passed1 = TestCase1();