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(REGEX REPLACE "\\.cpp$" ".hpp" OUTPUT_HPP "${OUTPUT}")
13 get_filename_component(OUTPUT_HPP_NAME "${OUTPUT_HPP}" NAME)
15 set(nested_namespace_start "namespace ${MODULE_NAME}\n{")
16 set(nested_namespace_end "}")
18 set(STR_CPP "// This file is auto-generated. Do not edit!
20 #include \"opencv2/core.hpp\"
21 #include \"cvconfig.h\"
22 #include \"${OUTPUT_HPP_NAME}\"
30 ${nested_namespace_start}
32 static const char* const moduleName = \"${MODULE_NAME}\";
36 set(STR_HPP "// This file is auto-generated. Do not edit!
38 #include \"opencv2/core/ocl.hpp\"
39 #include \"opencv2/core/ocl_genbase.hpp\"
40 #include \"opencv2/core/opencl/ocl_defs.hpp\"
48 ${nested_namespace_start}
52 foreach(cl ${cl_list})
53 get_filename_component(cl_filename "${cl}" NAME_WE)
54 #message("${cl_filename}")
56 file(READ "${cl}" lines)
58 string(REPLACE "\r" "" lines "${lines}\n")
59 string(REPLACE "\t" " " lines "${lines}")
61 string(REGEX REPLACE "/\\*([^*]/|\\*[^/]|[^*/])*\\*/" "" lines "${lines}") # multiline comments
62 string(REGEX REPLACE "/\\*([^\n])*\\*/" "" lines "${lines}") # single-line comments
63 string(REGEX REPLACE "[ ]*//[^\n]*\n" "\n" lines "${lines}") # single-line comments
64 string(REGEX REPLACE "\n[ ]*(\n[ ]*)*" "\n" lines "${lines}") # empty lines & leading whitespace
65 string(REGEX REPLACE "^\n" "" lines "${lines}") # leading new line
67 string(REPLACE "\\" "\\\\" lines "${lines}")
68 string(REPLACE "\"" "\\\"" lines "${lines}")
69 string(REPLACE "\n" "\\n\"\n\"" lines "${lines}")
71 string(REGEX REPLACE "\"$" "" lines "${lines}") # unneeded " at the eof
73 string(MD5 hash "${lines}")
75 set(STR_CPP_DECL "struct cv::ocl::internal::ProgramEntry ${cl_filename}_oclsrc={moduleName, \"${cl_filename}\",\n\"${lines}, \"${hash}\", NULL};\n")
76 set(STR_HPP_DECL "extern struct cv::ocl::internal::ProgramEntry ${cl_filename}_oclsrc;\n")
78 set(STR_CPP "${STR_CPP}${STR_CPP_DECL}")
79 set(STR_HPP "${STR_HPP}${STR_HPP_DECL}")
82 set(STR_CPP "${STR_CPP}\n${nested_namespace_end}}}\n#endif\n")
83 set(STR_HPP "${STR_HPP}\n${nested_namespace_end}}}\n#endif\n")
85 file(WRITE "${OUTPUT}" "${STR_CPP}")
87 if(EXISTS "${OUTPUT_HPP}")
88 file(READ "${OUTPUT_HPP}" hpp_lines)
90 if("${hpp_lines}" STREQUAL "${STR_HPP}")
91 message(STATUS "${OUTPUT_HPP} contains the same content")
93 file(WRITE "${OUTPUT_HPP}" "${STR_HPP}")