blob: 409ce60c7d07c79d35a7a53aef4ccfb77c7bf799 [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
onqtam54565452016-05-19 18:09:20 +03006numFiles = 500
hardlyb1e7e142014-08-06 00:43:51 +03007
onqtamcef61492016-05-22 00:56:21 +03008with_doctest = 1
onqtam94978212016-05-22 00:07:30 +03009
10with_implement = 1
onqtam54565452016-05-19 18:09:20 +030011with_header = 1
onqtam67c8b3e2016-05-22 00:38:44 +030012with_a_test = 1
onqtamd4669c12016-05-22 00:24:44 +030013doctest_disable = 0
hardlyb1e7e142014-08-06 00:43:51 +030014
onqtam54565452016-05-19 18:09:20 +030015the_folder = "project"
16
17GCC_cmake_generator = '"MinGW Makefiles"'
18MSVC_cmake_generator = '"Visual Studio 14 Win64"' # MSVC 2015
19
20# ==============================================================================
21# ==============================================================================
22# ==============================================================================
hardlyb1e7e142014-08-06 00:43:51 +030023
24import os
25import sys
26import random
27import string
28import multiprocessing
29from datetime import datetime
onqtam54565452016-05-19 18:09:20 +030030import shutil
31from time import sleep
hardlyb1e7e142014-08-06 00:43:51 +030032
onqtam54565452016-05-19 18:09:20 +030033# clean and make the folder
34if os.path.exists(the_folder):
35 shutil.rmtree(the_folder)
hardlyb1e7e142014-08-06 00:43:51 +030036
onqtamd4669c12016-05-22 00:24:44 +030037sleep(2) # or the script might fail...
hardlyb1e7e142014-08-06 00:43:51 +030038
onqtam54565452016-05-19 18:09:20 +030039if not os.path.exists(the_folder):
40 os.makedirs(the_folder)
hardlyb1e7e142014-08-06 00:43:51 +030041
onqtam54565452016-05-19 18:09:20 +030042# make the source files
43for i in range(0, numFiles):
44 f = open(the_folder + '/' + str(i) + '.cpp', 'w')
45 if with_header:
46 if with_doctest:
47 if doctest_disable:
48 f.write('#define DOCTEST_CONFIG_DISABLE\n')
49 f.write('#include "doctest.h"\n\n')
50 else:
51 f.write('#include "catch.hpp"\n\n')
52 if with_a_test:
53 f.write('TEST_CASE("") {\n')
54 f.write(' CHECK(true == false);\n')
55 f.write('}\n\n')
56 f.write('int f' + str(i) + '() { return ' + str(i) + '; }\n\n')
57 f.close()
hardlyb1e7e142014-08-06 00:43:51 +030058
onqtam54565452016-05-19 18:09:20 +030059# the main file
60f = open(the_folder + '/main.cpp', 'w')
61if with_implement:
62 if with_doctest:
63 if doctest_disable:
64 f.write('#define DOCTEST_CONFIG_DISABLE\n')
65 f.write('#define DOCTEST_CONFIG_IMPLEMENT\n')
66 f.write('#include "doctest.h"\n\n')
hardlyb1e7e142014-08-06 00:43:51 +030067 else:
onqtam54565452016-05-19 18:09:20 +030068 f.write('#define CATCH_CONFIG_RUNNER\n')
69 f.write('#include "catch.hpp"\n\n')
70f.write('int main(int argc, char** argv) {\n')
71if with_implement:
72 if with_doctest: f.write(' int res = doctest::Context(argc, argv).run();\n')
73 else: f.write(' int res = Catch::Session().run(argc, argv);\n')
74else:
75 f.write(' int res = 0;\n')
76for i in range(0, numFiles):
77 f.write(' int f' + str(i) + '(); res += f' + str(i) + '();\n')
78f.write(' return res;\n}\n')
79f.close()
hardlyb1e7e142014-08-06 00:43:51 +030080
onqtam54565452016-05-19 18:09:20 +030081# the cmake file
82f = open(the_folder + '/CMakeLists.txt', 'w')
83f.write('cmake_minimum_required(VERSION 2.8)\n\n')
onqtam94978212016-05-22 00:07:30 +030084f.write('project(bench)\n\n')
onqtam54565452016-05-19 18:09:20 +030085if with_doctest: f.write('include_directories("../../../doctest/")\n\n')
86else: f.write('include_directories("../catch/single_include/")\n\n')
onqtam94978212016-05-22 00:07:30 +030087f.write('add_executable(bench main.cpp\n')
onqtam54565452016-05-19 18:09:20 +030088for i in range(0, numFiles):
89 f.write(' ' + str(i) + '.cpp\n')
90f.write(')\n')
91f.close()
hardlyb1e7e142014-08-06 00:43:51 +030092
onqtam54565452016-05-19 18:09:20 +030093# invoke cmake
94os.chdir(the_folder);
hardlyb1e7e142014-08-06 00:43:51 +030095
onqtam54565452016-05-19 18:09:20 +030096if with_gcc:
onqtam54565452016-05-19 18:09:20 +030097 cmake_build_type = 'Release'
98 if is_debug:
99 cmake_build_type = 'Debug'
onqtam94978212016-05-22 00:07:30 +0300100 # twice because MinGW-w64 fails the first time - don't know why
onqtam54565452016-05-19 18:09:20 +0300101 os.system('cmake . -G ' + GCC_cmake_generator + ' -DCMAKE_BUILD_TYPE=' + cmake_build_type);
102 os.system('cmake . -G ' + GCC_cmake_generator + ' -DCMAKE_BUILD_TYPE=' + cmake_build_type);
103else:
104 os.system('cmake . -G ' + MSVC_cmake_generator);
hardlyb1e7e142014-08-06 00:43:51 +0300105
onqtam54565452016-05-19 18:09:20 +0300106the_config = ''
107if with_gcc == False:
108 if is_debug:
109 the_config = ' --config Debug'
110 else:
111 the_config = ' --config Release'
hardlyb1e7e142014-08-06 00:43:51 +0300112
onqtamd4669c12016-05-22 00:24:44 +0300113# build it
114start = datetime.now()
onqtam54565452016-05-19 18:09:20 +0300115os.system('cmake --build .' + the_config)
116end = datetime.now()
onqtamd4669c12016-05-22 00:24:44 +0300117
onqtam54565452016-05-19 18:09:20 +0300118print("Time for compiling (+ linking): " + str(end - start))
hardlyb1e7e142014-08-06 00:43:51 +0300119
120os.chdir("../");
121
122
123
124
125
126
127
128
129
130
131
132
133
134