OCV option ENABLE_DYNAMIC_CUDA mistake fix.
[profile/ivi/opencv.git] / cmake / cl2cpp.cmake
1 file(GLOB cl_list "${CL_DIR}/*.cl" )
2 list(SORT cl_list)
3
4 string(REPLACE ".cpp" ".hpp" OUTPUT_HPP "${OUTPUT}")
5 get_filename_component(OUTPUT_HPP_NAME "${OUTPUT_HPP}" NAME)
6
7 set(STR_CPP "// This file is auto-generated. Do not edit!
8
9 #include \"precomp.hpp\"
10 #include \"${OUTPUT_HPP_NAME}\"
11
12 namespace cv
13 {
14 namespace ocl
15 {
16 ")
17
18 set(STR_HPP "// This file is auto-generated. Do not edit!
19
20 #include \"opencv2/ocl/private/util.hpp\"
21
22 namespace cv
23 {
24 namespace ocl
25 {
26
27 ")
28
29 foreach(cl ${cl_list})
30   get_filename_component(cl_filename "${cl}" NAME_WE)
31   #message("${cl_filename}")
32
33   file(READ "${cl}" lines)
34
35   string(REPLACE "\r" "" lines "${lines}\n")
36   string(REPLACE "\t" "  " lines "${lines}")
37
38   string(REGEX REPLACE "/\\*([^*]/|\\*[^/]|[^*/])*\\*/" ""   lines "${lines}") # multiline comments
39   string(REGEX REPLACE "/\\*([^\n])*\\*/"               ""   lines "${lines}") # single-line comments
40   string(REGEX REPLACE "[ ]*//[^\n]*\n"                 "\n" lines "${lines}") # single-line comments
41   string(REGEX REPLACE "\n[ ]*(\n[ ]*)*"                "\n" lines "${lines}") # empty lines & leading whitespace
42   string(REGEX REPLACE "^\n"                            ""   lines "${lines}") # leading new line
43
44   string(REPLACE "\\" "\\\\" lines "${lines}")
45   string(REPLACE "\"" "\\\"" lines "${lines}")
46   string(REPLACE "\n" "\\n\"\n\"" lines "${lines}")
47
48   string(REGEX REPLACE "\"$" "" lines "${lines}") # unneeded " at the eof
49
50   string(MD5 hash "${lines}")
51
52   set(STR_CPP "${STR_CPP}const struct ProgramEntry ${cl_filename}={\"${cl_filename}\",\n\"${lines}, \"${hash}\"};\n")
53   set(STR_HPP "${STR_HPP}extern const struct ProgramEntry ${cl_filename};\n")
54 endforeach()
55
56 set(STR_CPP "${STR_CPP}}\n}\n")
57 set(STR_HPP "${STR_HPP}}\n}\n")
58
59 file(WRITE "${OUTPUT}" "${STR_CPP}")
60
61 if(EXISTS "${OUTPUT_HPP}")
62   file(READ "${OUTPUT_HPP}" hpp_lines)
63 endif()
64 if("${hpp_lines}" STREQUAL "${STR_HPP}")
65   message(STATUS "${OUTPUT_HPP} contains same content")
66 else()
67   file(WRITE "${OUTPUT_HPP}" "${STR_HPP}")
68 endif()