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