1 if (NOT EXISTS "${CL_DIR}")
2 message(FATAL_ERROR "Specified wrong OpenCL kernels directory: ${CL_DIR}")
5 file(GLOB cl_list "${CL_DIR}/*.cl" )
9 message(FATAL_ERROR "Can't find OpenCL kernels in directory: ${CL_DIR}")
12 string(REPLACE ".cpp" ".hpp" OUTPUT_HPP "${OUTPUT}")
13 get_filename_component(OUTPUT_HPP_NAME "${OUTPUT_HPP}" NAME)
15 if("${MODULE_NAME}" STREQUAL "ocl")
16 set(nested_namespace_start "")
17 set(nested_namespace_end "")
20 set(nested_namespace_start "namespace ${MODULE_NAME}\n{")
21 set(nested_namespace_end "}")
24 set(STR_CPP "// This file is auto-generated. Do not edit!
26 #include \"precomp.hpp\"
27 #include \"${OUTPUT_HPP_NAME}\"
33 ${nested_namespace_start}
37 set(STR_HPP "// This file is auto-generated. Do not edit!
39 #include \"opencv2/core/ocl.hpp\"
40 #include \"opencv2/core/ocl_genbase.hpp\"
41 #include \"opencv2/core/opencl/ocl_defs.hpp\"
47 ${nested_namespace_start}
51 foreach(cl ${cl_list})
52 get_filename_component(cl_filename "${cl}" NAME_WE)
53 #message("${cl_filename}")
55 file(READ "${cl}" lines)
57 string(REPLACE "\r" "" lines "${lines}\n")
58 string(REPLACE "\t" " " lines "${lines}")
60 string(REGEX REPLACE "/\\*([^*]/|\\*[^/]|[^*/])*\\*/" "" lines "${lines}") # multiline comments
61 string(REGEX REPLACE "/\\*([^\n])*\\*/" "" lines "${lines}") # single-line comments
62 string(REGEX REPLACE "[ ]*//[^\n]*\n" "\n" lines "${lines}") # single-line comments
63 string(REGEX REPLACE "\n[ ]*(\n[ ]*)*" "\n" lines "${lines}") # empty lines & leading whitespace
64 string(REGEX REPLACE "^\n" "" lines "${lines}") # leading new line
66 string(REPLACE "\\" "\\\\" lines "${lines}")
67 string(REPLACE "\"" "\\\"" lines "${lines}")
68 string(REPLACE "\n" "\\n\"\n\"" lines "${lines}")
70 string(REGEX REPLACE "\"$" "" lines "${lines}") # unneeded " at the eof
72 string(MD5 hash "${lines}")
74 set(STR_CPP_DECL "const struct ProgramEntry ${cl_filename}={\"${cl_filename}\",\n\"${lines}, \"${hash}\"};\n")
75 set(STR_HPP_DECL "extern const struct ProgramEntry ${cl_filename};\n")
77 set(STR_CPP_DECL "${STR_CPP_DECL}ProgramSource ${cl_filename}_oclsrc(${cl_filename}.programStr);\n")
78 set(STR_HPP_DECL "${STR_HPP_DECL}extern ProgramSource ${cl_filename}_oclsrc;\n")
81 set(STR_CPP "${STR_CPP}${STR_CPP_DECL}")
82 set(STR_HPP "${STR_HPP}${STR_HPP_DECL}")
85 set(STR_CPP "${STR_CPP}}\n${nested_namespace_end}}\n")
86 set(STR_HPP "${STR_HPP}}\n${nested_namespace_end}}\n")
88 file(WRITE "${OUTPUT}" "${STR_CPP}")
90 if(EXISTS "${OUTPUT_HPP}")
91 file(READ "${OUTPUT_HPP}" hpp_lines)
93 if("${hpp_lines}" STREQUAL "${STR_HPP}")
94 message(STATUS "${OUTPUT_HPP} contains same content")
96 file(WRITE "${OUTPUT_HPP}" "${STR_HPP}")