-
Notifications
You must be signed in to change notification settings - Fork 5
/
compile.py
executable file
·123 lines (102 loc) · 3.83 KB
/
compile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/env python3
import os
import sys
import subprocess
CMAKELISTS_STR = """cmake_minimum_required (VERSION 2.6)
project (facedetect)
find_package(OpenCV REQUIRED)
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules/)
set(CMAKE_CXX_COMPILER "g++")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -std=c++14 -Wall -W -pedantic -g")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -W -pedantic -g")
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED on)
include_directories(include)
find_package(OpenMP)
if (OPENMP_FOUND)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif()"""
DETECTION_STR = """# detection
add_executable(detect entry_point/detect.cc
src/window.cc
src/mblbp.cc
src/classifier.cc
src/detect.cc)
target_link_libraries(detect ${OpenCV_LIBS})"""
TRAINING_STR = """# training
add_executable(train entry_point/train.cc
src/train.cc
src/classifier.cc
src/mblbp.cc
src/window.cc)
target_link_libraries(train ${OpenCV_LIBS})
target_link_libraries(train stdc++fs)"""
PREPROCESSING_STR = """# dataset preprocessing
add_executable(preprocess entry_point/preprocess.cc)
target_link_libraries(preprocess ${OpenCV_LIBS})
target_link_libraries(preprocess stdc++fs)"""
TESTS_STR = """# tests
add_executable(test_io test/test_io.cc
src/mblbp.cc
src/classifier.cc
src/window.cc)"""
def main():
output_str = CMAKELISTS_STR
build_options = []
if len(sys.argv) == 1:
output_str = add_all(output_str, build_options)
else:
for arg in sys.argv[1:]:
if arg not in ["detection", "training", "preprocessing", "tests"]:
print("Error : unknown argument " + str(arg))
sys.exit(1)
if "detection" in sys.argv:
output_str = add_detection(output_str, build_options)
if "training" in sys.argv:
output_str = add_training(output_str, build_options)
if "preprocessing" in sys.argv:
output_str = add_preprocessing(output_str, build_options)
if "tests" in sys.argv:
output_str = add_tests(output_str, build_options)
output_str += "\n"
cmakelists_file = open('CMakeLists.txt', 'w+')
cmakelists_file.write(output_str)
cmakelists_file.close()
subprocess.check_call(["rm", "-rf", "build"])
subprocess.check_call(["mkdir", "build"])
os.chdir("build")
subprocess.check_call(["cmake", ".."])
subprocess.check_call(["make", "-j8"])
build_options_file = open('build_options.txt', 'w+')
for opt in build_options:
build_options_file.write(opt + "\n")
build_options_file.close()
def add_detection(output_str, build_options):
output_str += "\n\n"
output_str += DETECTION_STR
build_options.append("detection")
return output_str
def add_training(output_str, build_options):
output_str += "\n\n"
output_str += TRAINING_STR
build_options.append("training")
return output_str
def add_preprocessing(output_str, build_options):
output_str += "\n\n"
output_str += PREPROCESSING_STR
build_options.append("preprocessing")
return output_str
def add_tests(output_str, build_options):
output_str += "\n\n"
output_str += TESTS_STR
build_options.append("tests")
return output_str
def add_all(output_str, build_options):
output_str = add_detection(output_str, build_options)
output_str = add_training(output_str, build_options)
output_str = add_preprocessing(output_str, build_options)
#output_str = add_tests(output_str, build_options)
return output_str
if __name__ == '__main__':
main()