Skip to content

Commit

Permalink
Build with cmake using Python build script
Browse files Browse the repository at this point in the history
  • Loading branch information
jbcoe committed Sep 27, 2016
1 parent a3e26ee commit f840c93
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "submodules/GSL"]
path = submodules/GSL
[submodule "submodules/gsl"]
path = submodules/gsl
url = https://github.com/Microsoft/GSL.git
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
26 changes: 26 additions & 0 deletions scripts/build.py
Original file line number Diff line number Diff line change
@@ -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()

2 changes: 1 addition & 1 deletion test_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ bool TestCase3() {
return Counter::count() == 4;
}

int _main() {
int main() {
cout.setf(ios::boolalpha);

bool passed1 = TestCase1();
Expand Down

0 comments on commit f840c93

Please sign in to comment.