hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 1 | #!/usr/bin/python2.7 |
| 2 | |
onqtam | 5456545 | 2016-05-19 18:09:20 +0300 | [diff] [blame^] | 3 | with_gcc = 0 |
| 4 | is_debug = 1 |
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 5 | |
onqtam | 5456545 | 2016-05-19 18:09:20 +0300 | [diff] [blame^] | 6 | numFiles = 500 |
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 7 | |
onqtam | 5456545 | 2016-05-19 18:09:20 +0300 | [diff] [blame^] | 8 | with_doctest = 1 |
| 9 | with_header = 1 |
| 10 | with_a_test = 1 |
| 11 | with_implement = 1 |
| 12 | doctest_disable = 0 |
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 13 | |
onqtam | 5456545 | 2016-05-19 18:09:20 +0300 | [diff] [blame^] | 14 | the_folder = "project" |
| 15 | |
| 16 | GCC_cmake_generator = '"MinGW Makefiles"' |
| 17 | MSVC_cmake_generator = '"Visual Studio 14 Win64"' # MSVC 2015 |
| 18 | |
| 19 | # ============================================================================== |
| 20 | # ============================================================================== |
| 21 | # ============================================================================== |
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 22 | |
| 23 | import os |
| 24 | import sys |
| 25 | import random |
| 26 | import string |
| 27 | import multiprocessing |
| 28 | from datetime import datetime |
onqtam | 5456545 | 2016-05-19 18:09:20 +0300 | [diff] [blame^] | 29 | import shutil |
| 30 | from time import sleep |
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 31 | |
onqtam | 5456545 | 2016-05-19 18:09:20 +0300 | [diff] [blame^] | 32 | # clean and make the folder |
| 33 | if os.path.exists(the_folder): |
| 34 | shutil.rmtree(the_folder) |
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 35 | |
onqtam | 5456545 | 2016-05-19 18:09:20 +0300 | [diff] [blame^] | 36 | sleep(1) # or the script might fail... |
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 37 | |
onqtam | 5456545 | 2016-05-19 18:09:20 +0300 | [diff] [blame^] | 38 | if not os.path.exists(the_folder): |
| 39 | os.makedirs(the_folder) |
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 40 | |
onqtam | 5456545 | 2016-05-19 18:09:20 +0300 | [diff] [blame^] | 41 | # make the source files |
| 42 | for 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() |
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 57 | |
onqtam | 5456545 | 2016-05-19 18:09:20 +0300 | [diff] [blame^] | 58 | # the main file |
| 59 | f = open(the_folder + '/main.cpp', 'w') |
| 60 | if 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') |
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 66 | else: |
onqtam | 5456545 | 2016-05-19 18:09:20 +0300 | [diff] [blame^] | 67 | f.write('#define CATCH_CONFIG_RUNNER\n') |
| 68 | f.write('#include "catch.hpp"\n\n') |
| 69 | f.write('int main(int argc, char** argv) {\n') |
| 70 | if 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') |
| 73 | else: |
| 74 | f.write(' int res = 0;\n') |
| 75 | for i in range(0, numFiles): |
| 76 | f.write(' int f' + str(i) + '(); res += f' + str(i) + '();\n') |
| 77 | f.write(' return res;\n}\n') |
| 78 | f.close() |
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 79 | |
onqtam | 5456545 | 2016-05-19 18:09:20 +0300 | [diff] [blame^] | 80 | # the cmake file |
| 81 | f = open(the_folder + '/CMakeLists.txt', 'w') |
| 82 | f.write('cmake_minimum_required(VERSION 2.8)\n\n') |
| 83 | f.write('project(test)\n\n') |
| 84 | if with_doctest: f.write('include_directories("../../../doctest/")\n\n') |
| 85 | else: f.write('include_directories("../catch/single_include/")\n\n') |
| 86 | f.write('add_executable(test main.cpp\n') |
| 87 | for i in range(0, numFiles): |
| 88 | f.write(' ' + str(i) + '.cpp\n') |
| 89 | f.write(')\n') |
| 90 | f.close() |
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 91 | |
onqtam | 5456545 | 2016-05-19 18:09:20 +0300 | [diff] [blame^] | 92 | # invoke cmake |
| 93 | os.chdir(the_folder); |
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 94 | |
onqtam | 5456545 | 2016-05-19 18:09:20 +0300 | [diff] [blame^] | 95 | if 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); |
| 104 | else: |
| 105 | os.system('cmake . -G ' + MSVC_cmake_generator); |
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 106 | |
onqtam | 5456545 | 2016-05-19 18:09:20 +0300 | [diff] [blame^] | 107 | # build it |
| 108 | start = datetime.now() |
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 109 | |
onqtam | 5456545 | 2016-05-19 18:09:20 +0300 | [diff] [blame^] | 110 | the_config = '' |
| 111 | if with_gcc == False: |
| 112 | if is_debug: |
| 113 | the_config = ' --config Debug' |
| 114 | else: |
| 115 | the_config = ' --config Release' |
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 116 | |
onqtam | 5456545 | 2016-05-19 18:09:20 +0300 | [diff] [blame^] | 117 | os.system('cmake --build .' + the_config) |
| 118 | end = datetime.now() |
| 119 | print("Time for compiling (+ linking): " + str(end - start)) |
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 120 | |
| 121 | os.chdir("../"); |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |