blob: b84852bfced33b2a1606a4142e125819573bcec1 [file] [log] [blame]
hardlyb1e7e142014-08-06 00:43:51 +03001#!/usr/bin/python2.7
2
onqtamd4669c12016-05-22 00:24:44 +03003with_gcc = 0
onqtamcef61492016-05-22 00:56:21 +03004is_debug = 1
hardlyb1e7e142014-08-06 00:43:51 +03005
onqtamdf09f512016-09-15 13:43:50 +03006numFiles = 10
hardlyb1e7e142014-08-06 00:43:51 +03007
onqtameae70c72016-06-07 22:36:24 +03008with_doctest = 1
onqtam94978212016-05-22 00:07:30 +03009
onqtameae70c72016-06-07 22:36:24 +030010with_implement = 1
11with_header = 1
12with_num_tests = 25
onqtamdf09f512016-09-15 13:43:50 +030013with_num_assertions = 100
onqtameae70c72016-06-07 22:36:24 +030014doctest_disable = 0
hardlyb1e7e142014-08-06 00:43:51 +030015
onqtamdf09f512016-09-15 13:43:50 +030016the_folder = 'project'
17
18doctest_header = 'doctest.h'
onqtam54565452016-05-19 18:09:20 +030019
20GCC_cmake_generator = '"MinGW Makefiles"'
21MSVC_cmake_generator = '"Visual Studio 14 Win64"' # MSVC 2015
22
23# ==============================================================================
24# ==============================================================================
25# ==============================================================================
hardlyb1e7e142014-08-06 00:43:51 +030026
27import os
28import sys
29import random
30import string
31import multiprocessing
32from datetime import datetime
onqtam54565452016-05-19 18:09:20 +030033import shutil
34from time import sleep
hardlyb1e7e142014-08-06 00:43:51 +030035
onqtamdf09f512016-09-15 13:43:50 +030036if os.name != "nt":
37 GCC_cmake_generator = "Makefiles"
38
onqtam54565452016-05-19 18:09:20 +030039# clean and make the folder
40if os.path.exists(the_folder):
41 shutil.rmtree(the_folder)
hardlyb1e7e142014-08-06 00:43:51 +030042
onqtamd4669c12016-05-22 00:24:44 +030043sleep(2) # or the script might fail...
hardlyb1e7e142014-08-06 00:43:51 +030044
onqtam54565452016-05-19 18:09:20 +030045if not os.path.exists(the_folder):
46 os.makedirs(the_folder)
hardlyb1e7e142014-08-06 00:43:51 +030047
onqtam54565452016-05-19 18:09:20 +030048# make the source files
49for i in range(0, numFiles):
50 f = open(the_folder + '/' + str(i) + '.cpp', 'w')
51 if with_header:
52 if with_doctest:
53 if doctest_disable:
54 f.write('#define DOCTEST_CONFIG_DISABLE\n')
onqtamdf09f512016-09-15 13:43:50 +030055 f.write('#include "' + doctest_header + '"\n\n')
onqtam54565452016-05-19 18:09:20 +030056 else:
57 f.write('#include "catch.hpp"\n\n')
onqtameae70c72016-06-07 22:36:24 +030058 for t in range(0, with_num_tests):
onqtam54565452016-05-19 18:09:20 +030059 f.write('TEST_CASE("") {\n')
onqtameae70c72016-06-07 22:36:24 +030060 for a in range(0, with_num_assertions):
61 f.write(' int a' + str(a) + ' = 5;\n')
62 f.write(' int b' + str(a) + ' = 6;\n')
63 f.write(' CHECK(a' + str(a) + ' == b' + str(a) + ');\n')
onqtam8deb0922016-06-08 21:40:54 +030064 #f.write(' CHECK_EQ(a' + str(a) + ', b' + str(a) + ');\n')
onqtam54565452016-05-19 18:09:20 +030065 f.write('}\n\n')
66 f.write('int f' + str(i) + '() { return ' + str(i) + '; }\n\n')
67 f.close()
hardlyb1e7e142014-08-06 00:43:51 +030068
onqtam54565452016-05-19 18:09:20 +030069# the main file
70f = open(the_folder + '/main.cpp', 'w')
71if with_implement:
72 if with_doctest:
73 if doctest_disable:
74 f.write('#define DOCTEST_CONFIG_DISABLE\n')
75 f.write('#define DOCTEST_CONFIG_IMPLEMENT\n')
onqtamdf09f512016-09-15 13:43:50 +030076 f.write('#include "' + doctest_header + '"\n\n')
hardlyb1e7e142014-08-06 00:43:51 +030077 else:
onqtam54565452016-05-19 18:09:20 +030078 f.write('#define CATCH_CONFIG_RUNNER\n')
79 f.write('#include "catch.hpp"\n\n')
80f.write('int main(int argc, char** argv) {\n')
81if with_implement:
82 if with_doctest: f.write(' int res = doctest::Context(argc, argv).run();\n')
83 else: f.write(' int res = Catch::Session().run(argc, argv);\n')
84else:
85 f.write(' int res = 0;\n')
86for i in range(0, numFiles):
87 f.write(' int f' + str(i) + '(); res += f' + str(i) + '();\n')
88f.write(' return res;\n}\n')
89f.close()
hardlyb1e7e142014-08-06 00:43:51 +030090
onqtam54565452016-05-19 18:09:20 +030091# the cmake file
92f = open(the_folder + '/CMakeLists.txt', 'w')
93f.write('cmake_minimum_required(VERSION 2.8)\n\n')
onqtam94978212016-05-22 00:07:30 +030094f.write('project(bench)\n\n')
onqtam54565452016-05-19 18:09:20 +030095if with_doctest: f.write('include_directories("../../../doctest/")\n\n')
96else: f.write('include_directories("../catch/single_include/")\n\n')
onqtam94978212016-05-22 00:07:30 +030097f.write('add_executable(bench main.cpp\n')
onqtam54565452016-05-19 18:09:20 +030098for i in range(0, numFiles):
99 f.write(' ' + str(i) + '.cpp\n')
100f.write(')\n')
101f.close()
hardlyb1e7e142014-08-06 00:43:51 +0300102
onqtam54565452016-05-19 18:09:20 +0300103# invoke cmake
104os.chdir(the_folder);
hardlyb1e7e142014-08-06 00:43:51 +0300105
onqtam54565452016-05-19 18:09:20 +0300106if with_gcc:
onqtam54565452016-05-19 18:09:20 +0300107 cmake_build_type = 'Release'
108 if is_debug:
109 cmake_build_type = 'Debug'
onqtam54565452016-05-19 18:09:20 +0300110 os.system('cmake . -G ' + GCC_cmake_generator + ' -DCMAKE_BUILD_TYPE=' + cmake_build_type);
111else:
112 os.system('cmake . -G ' + MSVC_cmake_generator);
hardlyb1e7e142014-08-06 00:43:51 +0300113
onqtam54565452016-05-19 18:09:20 +0300114the_config = ''
115if with_gcc == False:
116 if is_debug:
117 the_config = ' --config Debug'
118 else:
119 the_config = ' --config Release'
hardlyb1e7e142014-08-06 00:43:51 +0300120
onqtamd4669c12016-05-22 00:24:44 +0300121# build it
122start = datetime.now()
onqtam54565452016-05-19 18:09:20 +0300123os.system('cmake --build .' + the_config)
124end = datetime.now()
onqtamd4669c12016-05-22 00:24:44 +0300125
onqtam54565452016-05-19 18:09:20 +0300126print("Time for compiling (+ linking): " + str(end - start))
hardlyb1e7e142014-08-06 00:43:51 +0300127
128os.chdir("../");
129
130
131
132
133
134
135
136
137
138
139
140
141
142