blob: 39afb1575b2a2a91e2652db711dfbd3831bf7c2d [file] [log] [blame]
hardlyb1e7e142014-08-06 00:43:51 +03001#!/usr/bin/python2.7
2
onqtamc6555cf2016-09-20 15:07:28 +03003# to change compilers under linux use 'export CXX=clang++' or 'export CXX=g++' before running this script
4
5with_gcc = 0
6is_debug = 1
hardlyb1e7e142014-08-06 00:43:51 +03007
onqtam200e8882016-09-20 11:01:02 +03008numFiles = 10
hardlyb1e7e142014-08-06 00:43:51 +03009
onqtameae70c72016-06-07 22:36:24 +030010with_doctest = 1
onqtam94978212016-05-22 00:07:30 +030011
onqtameae70c72016-06-07 22:36:24 +030012with_implement = 1
13with_header = 1
onqtam200e8882016-09-20 11:01:02 +030014with_num_tests = 50
onqtamdf09f512016-09-15 13:43:50 +030015with_num_assertions = 100
onqtamc6555cf2016-09-20 15:07:28 +030016
onqtameae70c72016-06-07 22:36:24 +030017doctest_disable = 0
onqtamc6555cf2016-09-20 15:07:28 +030018doctest_super_fast = 0
hardlyb1e7e142014-08-06 00:43:51 +030019
onqtamdf09f512016-09-15 13:43:50 +030020the_folder = 'project'
21
onqtam7ff1dc12016-09-18 12:59:51 +030022#macro = "FAST_CHECK_EQ"
onqtam11210ce2016-09-19 13:24:23 +030023#macro = "CHECK_EQ"
onqtam7ff1dc12016-09-18 12:59:51 +030024macro = "CHECK"
onqtam956d4ec2016-09-18 13:42:33 +030025
onqtam54565452016-05-19 18:09:20 +030026# ==============================================================================
27# ==============================================================================
28# ==============================================================================
hardlyb1e7e142014-08-06 00:43:51 +030029
30import os
31import sys
32import random
33import string
34import multiprocessing
35from datetime import datetime
onqtam54565452016-05-19 18:09:20 +030036import shutil
37from time import sleep
hardlyb1e7e142014-08-06 00:43:51 +030038
onqtamc6555cf2016-09-20 15:07:28 +030039operator = " == "
40if macro != "CHECK":
41 operator = ", "
42
43doctest_configs = ''
44if doctest_super_fast:
45 doctest_configs = '#define DOCTEST_CONFIG_SUPER_FAST_ASSERTS'
46
onqtam956d4ec2016-09-18 13:42:33 +030047GCC_cmake_generator = '"MinGW Makefiles"'
48MSVC_cmake_generator = '"Visual Studio 14 Win64"' # MSVC 2015
49
onqtamdf09f512016-09-15 13:43:50 +030050if os.name != "nt":
onqtam83372782016-09-19 23:19:49 +030051 GCC_cmake_generator = '"Unix Makefiles"'
onqtamdf09f512016-09-15 13:43:50 +030052
onqtam54565452016-05-19 18:09:20 +030053# clean and make the folder
54if os.path.exists(the_folder):
55 shutil.rmtree(the_folder)
hardlyb1e7e142014-08-06 00:43:51 +030056
onqtamd4669c12016-05-22 00:24:44 +030057sleep(2) # or the script might fail...
hardlyb1e7e142014-08-06 00:43:51 +030058
onqtam54565452016-05-19 18:09:20 +030059if not os.path.exists(the_folder):
60 os.makedirs(the_folder)
hardlyb1e7e142014-08-06 00:43:51 +030061
onqtam54565452016-05-19 18:09:20 +030062# make the source files
63for i in range(0, numFiles):
64 f = open(the_folder + '/' + str(i) + '.cpp', 'w')
65 if with_header:
66 if with_doctest:
67 if doctest_disable:
68 f.write('#define DOCTEST_CONFIG_DISABLE\n')
onqtam956d4ec2016-09-18 13:42:33 +030069 f.write(doctest_configs + '\n')
onqtamc6555cf2016-09-20 15:07:28 +030070 f.write('#include "doctest.h"\n\n')
onqtam54565452016-05-19 18:09:20 +030071 else:
72 f.write('#include "catch.hpp"\n\n')
onqtameae70c72016-06-07 22:36:24 +030073 for t in range(0, with_num_tests):
onqtam200e8882016-09-20 11:01:02 +030074 f.write('TEST_CASE("") {\n')
75 f.write(' int a = 5;\n int b = 6;\n')
onqtameae70c72016-06-07 22:36:24 +030076 for a in range(0, with_num_assertions):
onqtam200e8882016-09-20 11:01:02 +030077 #f.write(' int a' + str(a) + ' = 5;\n')
78 #f.write(' int b' + str(a) + ' = 6;\n')
79 #f.write(' ' + macro + '(a' + str(a) + operator + 'b' + str(a) + ');\n')
onqtam19b21e92016-09-19 23:08:37 +030080 f.write(' ' + macro + '(a' + operator + 'b);\n')
onqtam54565452016-05-19 18:09:20 +030081 f.write('}\n\n')
82 f.write('int f' + str(i) + '() { return ' + str(i) + '; }\n\n')
83 f.close()
hardlyb1e7e142014-08-06 00:43:51 +030084
onqtam54565452016-05-19 18:09:20 +030085# the main file
86f = open(the_folder + '/main.cpp', 'w')
87if with_implement:
88 if with_doctest:
89 if doctest_disable:
90 f.write('#define DOCTEST_CONFIG_DISABLE\n')
onqtam956d4ec2016-09-18 13:42:33 +030091 f.write(doctest_configs + '\n')
onqtam54565452016-05-19 18:09:20 +030092 f.write('#define DOCTEST_CONFIG_IMPLEMENT\n')
onqtamc6555cf2016-09-20 15:07:28 +030093 f.write('#include "doctest.h"\n\n')
hardlyb1e7e142014-08-06 00:43:51 +030094 else:
onqtam54565452016-05-19 18:09:20 +030095 f.write('#define CATCH_CONFIG_RUNNER\n')
96 f.write('#include "catch.hpp"\n\n')
97f.write('int main(int argc, char** argv) {\n')
98if with_implement:
99 if with_doctest: f.write(' int res = doctest::Context(argc, argv).run();\n')
100 else: f.write(' int res = Catch::Session().run(argc, argv);\n')
101else:
102 f.write(' int res = 0;\n')
103for i in range(0, numFiles):
104 f.write(' int f' + str(i) + '(); res += f' + str(i) + '();\n')
105f.write(' return res;\n}\n')
106f.close()
hardlyb1e7e142014-08-06 00:43:51 +0300107
onqtam54565452016-05-19 18:09:20 +0300108# the cmake file
109f = open(the_folder + '/CMakeLists.txt', 'w')
110f.write('cmake_minimum_required(VERSION 2.8)\n\n')
onqtam94978212016-05-22 00:07:30 +0300111f.write('project(bench)\n\n')
onqtam54565452016-05-19 18:09:20 +0300112if with_doctest: f.write('include_directories("../../../doctest/")\n\n')
113else: f.write('include_directories("../catch/single_include/")\n\n')
onqtam94978212016-05-22 00:07:30 +0300114f.write('add_executable(bench main.cpp\n')
onqtam54565452016-05-19 18:09:20 +0300115for i in range(0, numFiles):
116 f.write(' ' + str(i) + '.cpp\n')
117f.write(')\n')
118f.close()
hardlyb1e7e142014-08-06 00:43:51 +0300119
onqtam54565452016-05-19 18:09:20 +0300120# invoke cmake
121os.chdir(the_folder);
hardlyb1e7e142014-08-06 00:43:51 +0300122
onqtam54565452016-05-19 18:09:20 +0300123if with_gcc:
onqtam54565452016-05-19 18:09:20 +0300124 cmake_build_type = 'Release'
125 if is_debug:
126 cmake_build_type = 'Debug'
onqtam54565452016-05-19 18:09:20 +0300127 os.system('cmake . -G ' + GCC_cmake_generator + ' -DCMAKE_BUILD_TYPE=' + cmake_build_type);
128else:
129 os.system('cmake . -G ' + MSVC_cmake_generator);
hardlyb1e7e142014-08-06 00:43:51 +0300130
onqtam54565452016-05-19 18:09:20 +0300131the_config = ''
132if with_gcc == False:
133 if is_debug:
134 the_config = ' --config Debug'
135 else:
136 the_config = ' --config Release'
hardlyb1e7e142014-08-06 00:43:51 +0300137
onqtamd4669c12016-05-22 00:24:44 +0300138# build it
139start = datetime.now()
onqtam54565452016-05-19 18:09:20 +0300140os.system('cmake --build .' + the_config)
141end = datetime.now()
onqtamd4669c12016-05-22 00:24:44 +0300142
onqtam54565452016-05-19 18:09:20 +0300143print("Time for compiling (+ linking): " + str(end - start))
hardlyb1e7e142014-08-06 00:43:51 +0300144
145os.chdir("../");
146
147
148
149
150
151
152
153
154
155
156
157
158
159