Home | History | Annotate | Download | only in 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 if("${MODULE_NAME}" STREQUAL "ocl")
      8     set(nested_namespace_start "")
      9     set(nested_namespace_end "")
     10 else()
     11     set(new_mode ON)
     12     set(nested_namespace_start "namespace ${MODULE_NAME}\n{")
     13     set(nested_namespace_end "}")
     14 endif()
     15 
     16 set(STR_CPP "// This file is auto-generated. Do not edit!
     17 
     18 #include \"precomp.hpp\"
     19 #include \"${OUTPUT_HPP_NAME}\"
     20 
     21 namespace cv
     22 {
     23 namespace ocl
     24 {
     25 ${nested_namespace_start}
     26 
     27 ")
     28 
     29 set(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 
     35 namespace cv
     36 {
     37 namespace ocl
     38 {
     39 ${nested_namespace_start}
     40 
     41 ")
     42 
     43 foreach(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}")
     75 endforeach()
     76 
     77 set(STR_CPP "${STR_CPP}}\n${nested_namespace_end}}\n")
     78 set(STR_HPP "${STR_HPP}}\n${nested_namespace_end}}\n")
     79 
     80 file(WRITE "${OUTPUT}" "${STR_CPP}")
     81 
     82 if(EXISTS "${OUTPUT_HPP}")
     83   file(READ "${OUTPUT_HPP}" hpp_lines)
     84 endif()
     85 if("${hpp_lines}" STREQUAL "${STR_HPP}")
     86   message(STATUS "${OUTPUT_HPP} contains same content")
     87 else()
     88   file(WRITE "${OUTPUT_HPP}" "${STR_HPP}")
     89 endif()
     90