blob: c2334f0271752a5c1b7c6159506317acea58eb18 [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'
onqtam7ff1dc12016-09-18 12:59:51 +030019#doctest_header = 'doctest_1_0.h'
20#macro = "FAST_CHECK_EQ"
21macro = "CHECK"
22operator = " == "
23#operator = ", "
onqtam54565452016-05-19 18:09:20 +030024
25GCC_cmake_generator = '"MinGW Makefiles"'
26MSVC_cmake_generator = '"Visual Studio 14 Win64"' # MSVC 2015
27
28# ==============================================================================
29# ==============================================================================
30# ==============================================================================
hardlyb1e7e142014-08-06 00:43:51 +030031
32import os
33import sys
34import random
35import string
36import multiprocessing
37from datetime import datetime
onqtam54565452016-05-19 18:09:20 +030038import shutil
39from time import sleep
hardlyb1e7e142014-08-06 00:43:51 +030040
onqtamdf09f512016-09-15 13:43:50 +030041if os.name != "nt":
42 GCC_cmake_generator = "Makefiles"
43
onqtam54565452016-05-19 18:09:20 +030044# clean and make the folder
45if os.path.exists(the_folder):
46 shutil.rmtree(the_folder)
hardlyb1e7e142014-08-06 00:43:51 +030047
onqtamd4669c12016-05-22 00:24:44 +030048sleep(2) # or the script might fail...
hardlyb1e7e142014-08-06 00:43:51 +030049
onqtam54565452016-05-19 18:09:20 +030050if not os.path.exists(the_folder):
51 os.makedirs(the_folder)
hardlyb1e7e142014-08-06 00:43:51 +030052
onqtam54565452016-05-19 18:09:20 +030053# make the source files
54for i in range(0, numFiles):
55 f = open(the_folder + '/' + str(i) + '.cpp', 'w')
56 if with_header:
57 if with_doctest:
58 if doctest_disable:
59 f.write('#define DOCTEST_CONFIG_DISABLE\n')
onqtamdf09f512016-09-15 13:43:50 +030060 f.write('#include "' + doctest_header + '"\n\n')
onqtam54565452016-05-19 18:09:20 +030061 else:
62 f.write('#include "catch.hpp"\n\n')
onqtameae70c72016-06-07 22:36:24 +030063 for t in range(0, with_num_tests):
onqtam54565452016-05-19 18:09:20 +030064 f.write('TEST_CASE("") {\n')
onqtameae70c72016-06-07 22:36:24 +030065 for a in range(0, with_num_assertions):
66 f.write(' int a' + str(a) + ' = 5;\n')
67 f.write(' int b' + str(a) + ' = 6;\n')
onqtam7ff1dc12016-09-18 12:59:51 +030068 f.write(' ' + macro + '(a' + str(a) + operator + 'b' + str(a) + ');\n')
onqtam54565452016-05-19 18:09:20 +030069 f.write('}\n\n')
70 f.write('int f' + str(i) + '() { return ' + str(i) + '; }\n\n')
71 f.close()
hardlyb1e7e142014-08-06 00:43:51 +030072
onqtam54565452016-05-19 18:09:20 +030073# the main file
74f = open(the_folder + '/main.cpp', 'w')
75if with_implement:
76 if with_doctest:
77 if doctest_disable:
78 f.write('#define DOCTEST_CONFIG_DISABLE\n')
79 f.write('#define DOCTEST_CONFIG_IMPLEMENT\n')
onqtamdf09f512016-09-15 13:43:50 +030080 f.write('#include "' + doctest_header + '"\n\n')
hardlyb1e7e142014-08-06 00:43:51 +030081 else:
onqtam54565452016-05-19 18:09:20 +030082 f.write('#define CATCH_CONFIG_RUNNER\n')
83 f.write('#include "catch.hpp"\n\n')
84f.write('int main(int argc, char** argv) {\n')
85if with_implement:
86 if with_doctest: f.write(' int res = doctest::Context(argc, argv).run();\n')
87 else: f.write(' int res = Catch::Session().run(argc, argv);\n')
88else:
89 f.write(' int res = 0;\n')
90for i in range(0, numFiles):
91 f.write(' int f' + str(i) + '(); res += f' + str(i) + '();\n')
92f.write(' return res;\n}\n')
93f.close()
hardlyb1e7e142014-08-06 00:43:51 +030094
onqtam54565452016-05-19 18:09:20 +030095# the cmake file
96f = open(the_folder + '/CMakeLists.txt', 'w')
97f.write('cmake_minimum_required(VERSION 2.8)\n\n')
onqtam94978212016-05-22 00:07:30 +030098f.write('project(bench)\n\n')
onqtam54565452016-05-19 18:09:20 +030099if with_doctest: f.write('include_directories("../../../doctest/")\n\n')
100else: f.write('include_directories("../catch/single_include/")\n\n')
onqtam94978212016-05-22 00:07:30 +0300101f.write('add_executable(bench main.cpp\n')
onqtam54565452016-05-19 18:09:20 +0300102for i in range(0, numFiles):
103 f.write(' ' + str(i) + '.cpp\n')
104f.write(')\n')
105f.close()
hardlyb1e7e142014-08-06 00:43:51 +0300106
onqtam54565452016-05-19 18:09:20 +0300107# invoke cmake
108os.chdir(the_folder);
hardlyb1e7e142014-08-06 00:43:51 +0300109
onqtam54565452016-05-19 18:09:20 +0300110if with_gcc:
onqtam54565452016-05-19 18:09:20 +0300111 cmake_build_type = 'Release'
112 if is_debug:
113 cmake_build_type = 'Debug'
onqtam54565452016-05-19 18:09:20 +0300114 os.system('cmake . -G ' + GCC_cmake_generator + ' -DCMAKE_BUILD_TYPE=' + cmake_build_type);
115else:
116 os.system('cmake . -G ' + MSVC_cmake_generator);
hardlyb1e7e142014-08-06 00:43:51 +0300117
onqtam54565452016-05-19 18:09:20 +0300118the_config = ''
119if with_gcc == False:
120 if is_debug:
121 the_config = ' --config Debug'
122 else:
123 the_config = ' --config Release'
hardlyb1e7e142014-08-06 00:43:51 +0300124
onqtamd4669c12016-05-22 00:24:44 +0300125# build it
126start = datetime.now()
onqtam54565452016-05-19 18:09:20 +0300127os.system('cmake --build .' + the_config)
128end = datetime.now()
onqtamd4669c12016-05-22 00:24:44 +0300129
onqtam54565452016-05-19 18:09:20 +0300130print("Time for compiling (+ linking): " + str(end - start))
hardlyb1e7e142014-08-06 00:43:51 +0300131
132os.chdir("../");
133
134
135
136
137
138
139
140
141
142
143
144
145
146