blob: d9467e7af25cfa3e0999d4ba396cb354bc0fbf86 [file] [log] [blame]
hardlyb1e7e142014-08-06 00:43:51 +03001#!/usr/bin/python2.7
2
onqtam54565452016-05-19 18:09:20 +03003with_gcc = 0
4is_debug = 1
hardlyb1e7e142014-08-06 00:43:51 +03005
onqtam54565452016-05-19 18:09:20 +03006numFiles = 500
hardlyb1e7e142014-08-06 00:43:51 +03007
onqtam54565452016-05-19 18:09:20 +03008with_doctest = 1
9with_header = 1
10with_a_test = 1
11with_implement = 1
12doctest_disable = 0
hardlyb1e7e142014-08-06 00:43:51 +030013
onqtam54565452016-05-19 18:09:20 +030014the_folder = "project"
15
16GCC_cmake_generator = '"MinGW Makefiles"'
17MSVC_cmake_generator = '"Visual Studio 14 Win64"' # MSVC 2015
18
19# ==============================================================================
20# ==============================================================================
21# ==============================================================================
hardlyb1e7e142014-08-06 00:43:51 +030022
23import os
24import sys
25import random
26import string
27import multiprocessing
28from datetime import datetime
onqtam54565452016-05-19 18:09:20 +030029import shutil
30from time import sleep
hardlyb1e7e142014-08-06 00:43:51 +030031
onqtam54565452016-05-19 18:09:20 +030032# clean and make the folder
33if os.path.exists(the_folder):
34 shutil.rmtree(the_folder)
hardlyb1e7e142014-08-06 00:43:51 +030035
onqtam54565452016-05-19 18:09:20 +030036sleep(1) # or the script might fail...
hardlyb1e7e142014-08-06 00:43:51 +030037
onqtam54565452016-05-19 18:09:20 +030038if not os.path.exists(the_folder):
39 os.makedirs(the_folder)
hardlyb1e7e142014-08-06 00:43:51 +030040
onqtam54565452016-05-19 18:09:20 +030041# make the source files
42for i in range(0, numFiles):
43 f = open(the_folder + '/' + str(i) + '.cpp', 'w')
44 if with_header:
45 if with_doctest:
46 if doctest_disable:
47 f.write('#define DOCTEST_CONFIG_DISABLE\n')
48 f.write('#include "doctest.h"\n\n')
49 else:
50 f.write('#include "catch.hpp"\n\n')
51 if with_a_test:
52 f.write('TEST_CASE("") {\n')
53 f.write(' CHECK(true == false);\n')
54 f.write('}\n\n')
55 f.write('int f' + str(i) + '() { return ' + str(i) + '; }\n\n')
56 f.close()
hardlyb1e7e142014-08-06 00:43:51 +030057
onqtam54565452016-05-19 18:09:20 +030058# the main file
59f = open(the_folder + '/main.cpp', 'w')
60if with_implement:
61 if with_doctest:
62 if doctest_disable:
63 f.write('#define DOCTEST_CONFIG_DISABLE\n')
64 f.write('#define DOCTEST_CONFIG_IMPLEMENT\n')
65 f.write('#include "doctest.h"\n\n')
hardlyb1e7e142014-08-06 00:43:51 +030066 else:
onqtam54565452016-05-19 18:09:20 +030067 f.write('#define CATCH_CONFIG_RUNNER\n')
68 f.write('#include "catch.hpp"\n\n')
69f.write('int main(int argc, char** argv) {\n')
70if with_implement:
71 if with_doctest: f.write(' int res = doctest::Context(argc, argv).run();\n')
72 else: f.write(' int res = Catch::Session().run(argc, argv);\n')
73else:
74 f.write(' int res = 0;\n')
75for i in range(0, numFiles):
76 f.write(' int f' + str(i) + '(); res += f' + str(i) + '();\n')
77f.write(' return res;\n}\n')
78f.close()
hardlyb1e7e142014-08-06 00:43:51 +030079
onqtam54565452016-05-19 18:09:20 +030080# the cmake file
81f = open(the_folder + '/CMakeLists.txt', 'w')
82f.write('cmake_minimum_required(VERSION 2.8)\n\n')
83f.write('project(test)\n\n')
84if with_doctest: f.write('include_directories("../../../doctest/")\n\n')
85else: f.write('include_directories("../catch/single_include/")\n\n')
86f.write('add_executable(test main.cpp\n')
87for i in range(0, numFiles):
88 f.write(' ' + str(i) + '.cpp\n')
89f.write(')\n')
90f.close()
hardlyb1e7e142014-08-06 00:43:51 +030091
onqtam54565452016-05-19 18:09:20 +030092# invoke cmake
93os.chdir(the_folder);
hardlyb1e7e142014-08-06 00:43:51 +030094
onqtam54565452016-05-19 18:09:20 +030095if with_gcc:
96 # twice because MinGW-w64 fails the first time - dunno why
97 cmake_build_type = 'Release'
98 if is_debug:
99 cmake_build_type = 'Debug'
100
101
102 os.system('cmake . -G ' + GCC_cmake_generator + ' -DCMAKE_BUILD_TYPE=' + cmake_build_type);
103 os.system('cmake . -G ' + GCC_cmake_generator + ' -DCMAKE_BUILD_TYPE=' + cmake_build_type);
104else:
105 os.system('cmake . -G ' + MSVC_cmake_generator);
hardlyb1e7e142014-08-06 00:43:51 +0300106
onqtam54565452016-05-19 18:09:20 +0300107# build it
108start = datetime.now()
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
onqtam54565452016-05-19 18:09:20 +0300117os.system('cmake --build .' + the_config)
118end = datetime.now()
119print("Time for compiling (+ linking): " + str(end - start))
hardlyb1e7e142014-08-06 00:43:51 +0300120
121os.chdir("../");
122
123
124
125
126
127
128
129
130
131
132
133
134
135