blob: 50ecd5a8c636fe3c5852b827367234c79812346e [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
onqtameae70c72016-06-07 22:36:24 +03006numFiles = 100
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
13with_num_assertions = 10
14doctest_disable = 0
hardlyb1e7e142014-08-06 00:43:51 +030015
onqtam54565452016-05-19 18:09:20 +030016the_folder = "project"
17
18GCC_cmake_generator = '"MinGW Makefiles"'
19MSVC_cmake_generator = '"Visual Studio 14 Win64"' # MSVC 2015
20
21# ==============================================================================
22# ==============================================================================
23# ==============================================================================
hardlyb1e7e142014-08-06 00:43:51 +030024
25import os
26import sys
27import random
28import string
29import multiprocessing
30from datetime import datetime
onqtam54565452016-05-19 18:09:20 +030031import shutil
32from time import sleep
hardlyb1e7e142014-08-06 00:43:51 +030033
onqtam54565452016-05-19 18:09:20 +030034# clean and make the folder
35if os.path.exists(the_folder):
36 shutil.rmtree(the_folder)
hardlyb1e7e142014-08-06 00:43:51 +030037
onqtamd4669c12016-05-22 00:24:44 +030038sleep(2) # or the script might fail...
hardlyb1e7e142014-08-06 00:43:51 +030039
onqtam54565452016-05-19 18:09:20 +030040if not os.path.exists(the_folder):
41 os.makedirs(the_folder)
hardlyb1e7e142014-08-06 00:43:51 +030042
onqtam54565452016-05-19 18:09:20 +030043# make the source files
44for i in range(0, numFiles):
45 f = open(the_folder + '/' + str(i) + '.cpp', 'w')
46 if with_header:
47 if with_doctest:
48 if doctest_disable:
49 f.write('#define DOCTEST_CONFIG_DISABLE\n')
50 f.write('#include "doctest.h"\n\n')
51 else:
52 f.write('#include "catch.hpp"\n\n')
onqtameae70c72016-06-07 22:36:24 +030053 for t in range(0, with_num_tests):
onqtam54565452016-05-19 18:09:20 +030054 f.write('TEST_CASE("") {\n')
onqtameae70c72016-06-07 22:36:24 +030055 for a in range(0, with_num_assertions):
56 f.write(' int a' + str(a) + ' = 5;\n')
57 f.write(' int b' + str(a) + ' = 6;\n')
58 f.write(' CHECK(a' + str(a) + ' == b' + str(a) + ');\n')
onqtam8deb0922016-06-08 21:40:54 +030059 #f.write(' CHECK_EQ(a' + str(a) + ', b' + str(a) + ');\n')
onqtam54565452016-05-19 18:09:20 +030060 f.write('}\n\n')
61 f.write('int f' + str(i) + '() { return ' + str(i) + '; }\n\n')
62 f.close()
hardlyb1e7e142014-08-06 00:43:51 +030063
onqtam54565452016-05-19 18:09:20 +030064# the main file
65f = open(the_folder + '/main.cpp', 'w')
66if with_implement:
67 if with_doctest:
68 if doctest_disable:
69 f.write('#define DOCTEST_CONFIG_DISABLE\n')
70 f.write('#define DOCTEST_CONFIG_IMPLEMENT\n')
71 f.write('#include "doctest.h"\n\n')
hardlyb1e7e142014-08-06 00:43:51 +030072 else:
onqtam54565452016-05-19 18:09:20 +030073 f.write('#define CATCH_CONFIG_RUNNER\n')
74 f.write('#include "catch.hpp"\n\n')
75f.write('int main(int argc, char** argv) {\n')
76if with_implement:
77 if with_doctest: f.write(' int res = doctest::Context(argc, argv).run();\n')
78 else: f.write(' int res = Catch::Session().run(argc, argv);\n')
79else:
80 f.write(' int res = 0;\n')
81for i in range(0, numFiles):
82 f.write(' int f' + str(i) + '(); res += f' + str(i) + '();\n')
83f.write(' return res;\n}\n')
84f.close()
hardlyb1e7e142014-08-06 00:43:51 +030085
onqtam54565452016-05-19 18:09:20 +030086# the cmake file
87f = open(the_folder + '/CMakeLists.txt', 'w')
88f.write('cmake_minimum_required(VERSION 2.8)\n\n')
onqtam94978212016-05-22 00:07:30 +030089f.write('project(bench)\n\n')
onqtam54565452016-05-19 18:09:20 +030090if with_doctest: f.write('include_directories("../../../doctest/")\n\n')
91else: f.write('include_directories("../catch/single_include/")\n\n')
onqtam94978212016-05-22 00:07:30 +030092f.write('add_executable(bench main.cpp\n')
onqtam54565452016-05-19 18:09:20 +030093for i in range(0, numFiles):
94 f.write(' ' + str(i) + '.cpp\n')
95f.write(')\n')
96f.close()
hardlyb1e7e142014-08-06 00:43:51 +030097
onqtam54565452016-05-19 18:09:20 +030098# invoke cmake
99os.chdir(the_folder);
hardlyb1e7e142014-08-06 00:43:51 +0300100
onqtam54565452016-05-19 18:09:20 +0300101if with_gcc:
onqtam54565452016-05-19 18:09:20 +0300102 cmake_build_type = 'Release'
103 if is_debug:
104 cmake_build_type = 'Debug'
onqtam94978212016-05-22 00:07:30 +0300105 # twice because MinGW-w64 fails the first time - don't know why
onqtam54565452016-05-19 18:09:20 +0300106 os.system('cmake . -G ' + GCC_cmake_generator + ' -DCMAKE_BUILD_TYPE=' + cmake_build_type);
107 os.system('cmake . -G ' + GCC_cmake_generator + ' -DCMAKE_BUILD_TYPE=' + cmake_build_type);
108else:
109 os.system('cmake . -G ' + MSVC_cmake_generator);
hardlyb1e7e142014-08-06 00:43:51 +0300110
onqtam54565452016-05-19 18:09:20 +0300111the_config = ''
112if with_gcc == False:
113 if is_debug:
114 the_config = ' --config Debug'
115 else:
116 the_config = ' --config Release'
hardlyb1e7e142014-08-06 00:43:51 +0300117
onqtamd4669c12016-05-22 00:24:44 +0300118# build it
119start = datetime.now()
onqtam54565452016-05-19 18:09:20 +0300120os.system('cmake --build .' + the_config)
121end = datetime.now()
onqtamd4669c12016-05-22 00:24:44 +0300122
onqtam54565452016-05-19 18:09:20 +0300123print("Time for compiling (+ linking): " + str(end - start))
hardlyb1e7e142014-08-06 00:43:51 +0300124
125os.chdir("../");
126
127
128
129
130
131
132
133
134
135
136
137
138
139