1file(GLOB cl_list "${CL_DIR}/*.cl" ) 2list(SORT cl_list) 3 4string(REPLACE ".cpp" ".hpp" OUTPUT_HPP "${OUTPUT}") 5get_filename_component(OUTPUT_HPP_NAME "${OUTPUT_HPP}" NAME) 6 7if("${MODULE_NAME}" STREQUAL "ocl") 8 set(nested_namespace_start "") 9 set(nested_namespace_end "") 10else() 11 set(new_mode ON) 12 set(nested_namespace_start "namespace ${MODULE_NAME}\n{") 13 set(nested_namespace_end "}") 14endif() 15 16set(STR_CPP "// This file is auto-generated. Do not edit! 17 18#include \"precomp.hpp\" 19#include \"${OUTPUT_HPP_NAME}\" 20 21namespace cv 22{ 23namespace ocl 24{ 25${nested_namespace_start} 26 27") 28 29set(STR_HPP "// This file is auto-generated. Do not edit! 30 31#include \"opencv2/core/ocl.hpp\" 32#include \"opencv2/core/ocl_genbase.hpp\" 33#include \"opencv2/core/opencl/ocl_defs.hpp\" 34 35namespace cv 36{ 37namespace ocl 38{ 39${nested_namespace_start} 40 41") 42 43foreach(cl ${cl_list}) 44 get_filename_component(cl_filename "${cl}" NAME_WE) 45 #message("${cl_filename}") 46 47 file(READ "${cl}" lines) 48 49 string(REPLACE "\r" "" lines "${lines}\n") 50 string(REPLACE "\t" " " lines "${lines}") 51 52 string(REGEX REPLACE "/\\*([^*]/|\\*[^/]|[^*/])*\\*/" "" lines "${lines}") # multiline comments 53 string(REGEX REPLACE "/\\*([^\n])*\\*/" "" lines "${lines}") # single-line comments 54 string(REGEX REPLACE "[ ]*//[^\n]*\n" "\n" lines "${lines}") # single-line comments 55 string(REGEX REPLACE "\n[ ]*(\n[ ]*)*" "\n" lines "${lines}") # empty lines & leading whitespace 56 string(REGEX REPLACE "^\n" "" lines "${lines}") # leading new line 57 58 string(REPLACE "\\" "\\\\" lines "${lines}") 59 string(REPLACE "\"" "\\\"" lines "${lines}") 60 string(REPLACE "\n" "\\n\"\n\"" lines "${lines}") 61 62 string(REGEX REPLACE "\"$" "" lines "${lines}") # unneeded " at the eof 63 64 string(MD5 hash "${lines}") 65 66 set(STR_CPP_DECL "const struct ProgramEntry ${cl_filename}={\"${cl_filename}\",\n\"${lines}, \"${hash}\"};\n") 67 set(STR_HPP_DECL "extern const struct ProgramEntry ${cl_filename};\n") 68 if(new_mode) 69 set(STR_CPP_DECL "${STR_CPP_DECL}ProgramSource ${cl_filename}_oclsrc(${cl_filename}.programStr);\n") 70 set(STR_HPP_DECL "${STR_HPP_DECL}extern ProgramSource ${cl_filename}_oclsrc;\n") 71 endif() 72 73 set(STR_CPP "${STR_CPP}${STR_CPP_DECL}") 74 set(STR_HPP "${STR_HPP}${STR_HPP_DECL}") 75endforeach() 76 77set(STR_CPP "${STR_CPP}}\n${nested_namespace_end}}\n") 78set(STR_HPP "${STR_HPP}}\n${nested_namespace_end}}\n") 79 80file(WRITE "${OUTPUT}" "${STR_CPP}") 81 82if(EXISTS "${OUTPUT_HPP}") 83 file(READ "${OUTPUT_HPP}" hpp_lines) 84endif() 85if("${hpp_lines}" STREQUAL "${STR_HPP}") 86 message(STATUS "${OUTPUT_HPP} contains same content") 87else() 88 file(WRITE "${OUTPUT_HPP}" "${STR_HPP}") 89endif() 90