blob: 21f77ede370cd3725d5a09b09f407e676e681f18 [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')
onqtam54565452016-05-19 18:09:20 +030059 f.write('}\n\n')
60 f.write('int f' + str(i) + '() { return ' + str(i) + '; }\n\n')
61 f.close()
hardlyb1e7e142014-08-06 00:43:51 +030062
onqtam54565452016-05-19 18:09:20 +030063# the main file
64f = open(the_folder + '/main.cpp', 'w')
65if with_implement:
66 if with_doctest:
67 if doctest_disable:
68 f.write('#define DOCTEST_CONFIG_DISABLE\n')
69 f.write('#define DOCTEST_CONFIG_IMPLEMENT\n')
70 f.write('#include "doctest.h"\n\n')
hardlyb1e7e142014-08-06 00:43:51 +030071 else:
onqtam54565452016-05-19 18:09:20 +030072 f.write('#define CATCH_CONFIG_RUNNER\n')
73 f.write('#include "catch.hpp"\n\n')
74f.write('int main(int argc, char** argv) {\n')
75if with_implement:
76 if with_doctest: f.write(' int res = doctest::Context(argc, argv).run();\n')
77 else: f.write(' int res = Catch::Session().run(argc, argv);\n')
78else:
79 f.write(' int res = 0;\n')
80for i in range(0, numFiles):
81 f.write(' int f' + str(i) + '(); res += f' + str(i) + '();\n')
82f.write(' return res;\n}\n')
83f.close()
hardlyb1e7e142014-08-06 00:43:51 +030084
onqtam54565452016-05-19 18:09:20 +030085# the cmake file
86f = open(the_folder + '/CMakeLists.txt', 'w')
87f.write('cmake_minimum_required(VERSION 2.8)\n\n')
onqtam94978212016-05-22 00:07:30 +030088f.write('project(bench)\n\n')
onqtam54565452016-05-19 18:09:20 +030089if with_doctest: f.write('include_directories("../../../doctest/")\n\n')
90else: f.write('include_directories("../catch/single_include/")\n\n')
onqtam94978212016-05-22 00:07:30 +030091f.write('add_executable(bench main.cpp\n')
onqtam54565452016-05-19 18:09:20 +030092for i in range(0, numFiles):
93 f.write(' ' + str(i) + '.cpp\n')
94f.write(')\n')
95f.close()
hardlyb1e7e142014-08-06 00:43:51 +030096
onqtam54565452016-05-19 18:09:20 +030097# invoke cmake
98os.chdir(the_folder);
hardlyb1e7e142014-08-06 00:43:51 +030099
onqtam54565452016-05-19 18:09:20 +0300100if with_gcc:
onqtam54565452016-05-19 18:09:20 +0300101 cmake_build_type = 'Release'
102 if is_debug:
103 cmake_build_type = 'Debug'
onqtam94978212016-05-22 00:07:30 +0300104 # twice because MinGW-w64 fails the first time - don't know why
onqtam54565452016-05-19 18:09:20 +0300105 os.system('cmake . -G ' + GCC_cmake_generator + ' -DCMAKE_BUILD_TYPE=' + cmake_build_type);
106 os.system('cmake . -G ' + GCC_cmake_generator + ' -DCMAKE_BUILD_TYPE=' + cmake_build_type);
107else:
108 os.system('cmake . -G ' + MSVC_cmake_generator);
hardlyb1e7e142014-08-06 00:43:51 +0300109
onqtam54565452016-05-19 18:09:20 +0300110the_config = ''
111if with_gcc == False:
112 if is_debug:
113 the_config = ' --config Debug'
114 else:
115 the_config = ' --config Release'
hardlyb1e7e142014-08-06 00:43:51 +0300116
onqtamd4669c12016-05-22 00:24:44 +0300117# build it
118start = datetime.now()
onqtam54565452016-05-19 18:09:20 +0300119os.system('cmake --build .' + the_config)
120end = datetime.now()
onqtamd4669c12016-05-22 00:24:44 +0300121
onqtam54565452016-05-19 18:09:20 +0300122print("Time for compiling (+ linking): " + str(end - start))
hardlyb1e7e142014-08-06 00:43:51 +0300123
124os.chdir("../");
125
126
127
128
129
130
131
132
133
134
135
136
137
138