blob: afab5ad8d8a6c913edf88b711e95e82435b42da3 [file] [log] [blame]
hardlyb1e7e142014-08-06 00:43:51 +03001#!/usr/bin/python2.7
2
onqtam11210ce2016-09-19 13:24:23 +03003with_gcc = 1
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
onqtam956d4ec2016-09-18 13:42:33 +030018#doctest_configs = ''
19doctest_configs = '#define DOCTEST_CONFIG_SUPER_FAST_ASSERTS'
20
onqtam11210ce2016-09-19 13:24:23 +030021#doctest_header = 'doctest.h'
22doctest_header = 'doctest_1_0.h'
onqtam956d4ec2016-09-18 13:42:33 +030023
onqtam7ff1dc12016-09-18 12:59:51 +030024#macro = "FAST_CHECK_EQ"
onqtam11210ce2016-09-19 13:24:23 +030025#macro = "CHECK_EQ"
onqtam7ff1dc12016-09-18 12:59:51 +030026macro = "CHECK"
onqtam956d4ec2016-09-18 13:42:33 +030027
onqtam7ff1dc12016-09-18 12:59:51 +030028operator = " == "
29#operator = ", "
onqtam54565452016-05-19 18:09:20 +030030
onqtam54565452016-05-19 18:09:20 +030031# ==============================================================================
32# ==============================================================================
33# ==============================================================================
hardlyb1e7e142014-08-06 00:43:51 +030034
35import os
36import sys
37import random
38import string
39import multiprocessing
40from datetime import datetime
onqtam54565452016-05-19 18:09:20 +030041import shutil
42from time import sleep
hardlyb1e7e142014-08-06 00:43:51 +030043
onqtam956d4ec2016-09-18 13:42:33 +030044GCC_cmake_generator = '"MinGW Makefiles"'
45MSVC_cmake_generator = '"Visual Studio 14 Win64"' # MSVC 2015
46
onqtamdf09f512016-09-15 13:43:50 +030047if os.name != "nt":
48 GCC_cmake_generator = "Makefiles"
49
onqtam54565452016-05-19 18:09:20 +030050# clean and make the folder
51if os.path.exists(the_folder):
52 shutil.rmtree(the_folder)
hardlyb1e7e142014-08-06 00:43:51 +030053
onqtamd4669c12016-05-22 00:24:44 +030054sleep(2) # or the script might fail...
hardlyb1e7e142014-08-06 00:43:51 +030055
onqtam54565452016-05-19 18:09:20 +030056if not os.path.exists(the_folder):
57 os.makedirs(the_folder)
hardlyb1e7e142014-08-06 00:43:51 +030058
onqtam54565452016-05-19 18:09:20 +030059# make the source files
60for i in range(0, numFiles):
61 f = open(the_folder + '/' + str(i) + '.cpp', 'w')
62 if with_header:
63 if with_doctest:
64 if doctest_disable:
65 f.write('#define DOCTEST_CONFIG_DISABLE\n')
onqtam956d4ec2016-09-18 13:42:33 +030066 f.write(doctest_configs + '\n')
onqtamdf09f512016-09-15 13:43:50 +030067 f.write('#include "' + doctest_header + '"\n\n')
onqtam54565452016-05-19 18:09:20 +030068 else:
69 f.write('#include "catch.hpp"\n\n')
onqtameae70c72016-06-07 22:36:24 +030070 for t in range(0, with_num_tests):
onqtam54565452016-05-19 18:09:20 +030071 f.write('TEST_CASE("") {\n')
onqtameae70c72016-06-07 22:36:24 +030072 for a in range(0, with_num_assertions):
73 f.write(' int a' + str(a) + ' = 5;\n')
74 f.write(' int b' + str(a) + ' = 6;\n')
onqtam7ff1dc12016-09-18 12:59:51 +030075 f.write(' ' + macro + '(a' + str(a) + operator + 'b' + str(a) + ');\n')
onqtam54565452016-05-19 18:09:20 +030076 f.write('}\n\n')
77 f.write('int f' + str(i) + '() { return ' + str(i) + '; }\n\n')
78 f.close()
hardlyb1e7e142014-08-06 00:43:51 +030079
onqtam54565452016-05-19 18:09:20 +030080# the main file
81f = open(the_folder + '/main.cpp', 'w')
82if with_implement:
83 if with_doctest:
84 if doctest_disable:
85 f.write('#define DOCTEST_CONFIG_DISABLE\n')
onqtam956d4ec2016-09-18 13:42:33 +030086 f.write(doctest_configs + '\n')
onqtam54565452016-05-19 18:09:20 +030087 f.write('#define DOCTEST_CONFIG_IMPLEMENT\n')
onqtamdf09f512016-09-15 13:43:50 +030088 f.write('#include "' + doctest_header + '"\n\n')
hardlyb1e7e142014-08-06 00:43:51 +030089 else:
onqtam54565452016-05-19 18:09:20 +030090 f.write('#define CATCH_CONFIG_RUNNER\n')
91 f.write('#include "catch.hpp"\n\n')
92f.write('int main(int argc, char** argv) {\n')
93if with_implement:
94 if with_doctest: f.write(' int res = doctest::Context(argc, argv).run();\n')
95 else: f.write(' int res = Catch::Session().run(argc, argv);\n')
96else:
97 f.write(' int res = 0;\n')
98for i in range(0, numFiles):
99 f.write(' int f' + str(i) + '(); res += f' + str(i) + '();\n')
100f.write(' return res;\n}\n')
101f.close()
hardlyb1e7e142014-08-06 00:43:51 +0300102
onqtam54565452016-05-19 18:09:20 +0300103# the cmake file
104f = open(the_folder + '/CMakeLists.txt', 'w')
105f.write('cmake_minimum_required(VERSION 2.8)\n\n')
onqtam94978212016-05-22 00:07:30 +0300106f.write('project(bench)\n\n')
onqtam54565452016-05-19 18:09:20 +0300107if with_doctest: f.write('include_directories("../../../doctest/")\n\n')
108else: f.write('include_directories("../catch/single_include/")\n\n')
onqtam94978212016-05-22 00:07:30 +0300109f.write('add_executable(bench main.cpp\n')
onqtam54565452016-05-19 18:09:20 +0300110for i in range(0, numFiles):
111 f.write(' ' + str(i) + '.cpp\n')
112f.write(')\n')
113f.close()
hardlyb1e7e142014-08-06 00:43:51 +0300114
onqtam54565452016-05-19 18:09:20 +0300115# invoke cmake
116os.chdir(the_folder);
hardlyb1e7e142014-08-06 00:43:51 +0300117
onqtam54565452016-05-19 18:09:20 +0300118if with_gcc:
onqtam54565452016-05-19 18:09:20 +0300119 cmake_build_type = 'Release'
120 if is_debug:
121 cmake_build_type = 'Debug'
onqtam54565452016-05-19 18:09:20 +0300122 os.system('cmake . -G ' + GCC_cmake_generator + ' -DCMAKE_BUILD_TYPE=' + cmake_build_type);
123else:
124 os.system('cmake . -G ' + MSVC_cmake_generator);
hardlyb1e7e142014-08-06 00:43:51 +0300125
onqtam54565452016-05-19 18:09:20 +0300126the_config = ''
127if with_gcc == False:
128 if is_debug:
129 the_config = ' --config Debug'
130 else:
131 the_config = ' --config Release'
hardlyb1e7e142014-08-06 00:43:51 +0300132
onqtamd4669c12016-05-22 00:24:44 +0300133# build it
134start = datetime.now()
onqtam54565452016-05-19 18:09:20 +0300135os.system('cmake --build .' + the_config)
136end = datetime.now()
onqtamd4669c12016-05-22 00:24:44 +0300137
onqtam54565452016-05-19 18:09:20 +0300138print("Time for compiling (+ linking): " + str(end - start))
hardlyb1e7e142014-08-06 00:43:51 +0300139
140os.chdir("../");
141
142
143
144
145
146
147
148
149
150
151
152
153
154