opencv/modules/ocl/cl2cpp.cmake
Andrey Kamaev ecb707ca7b Convert cl2cpp.py script to cmake
New version removes inner comments and empty lines
2012-10-22 17:19:55 +04:00

34 lines
1.1 KiB
CMake

file(GLOB cl_list "${CL_DIR}/*.cl" )
file(WRITE ${OUTPUT} "// This file is auto-generated. Do not edit!
namespace cv
{
namespace ocl
{
")
foreach(cl ${cl_list})
get_filename_component(cl_filename "${cl}" NAME_WE)
#message("${cl_filename}")
file(READ "${cl}" lines)
string(REPLACE "\r" "" lines "${lines}\n")
string(REPLACE "\t" " " lines "${lines}")
string(REGEX REPLACE "/\\*([^*]/|\\*[^/]|[^*/])*\\*/" "" lines "${lines}") # multiline comments
string(REGEX REPLACE "[ ]*//[^\n]*\n" "\n" lines "${lines}") # single-line comments
string(REGEX REPLACE "\n[ ]*(\n[ ]*)*" "\n" lines "${lines}") # empty lines & leading whitespace
string(REGEX REPLACE "^\n" "" lines "${lines}") # leading new line
string(REPLACE "\\" "\\\\" lines "${lines}")
string(REPLACE "\"" "\\\"" lines "${lines}")
string(REPLACE "\n" "\\n\"\n\"" lines "${lines}")
string(REGEX REPLACE "\"$" "" lines "${lines}") # unneeded " at the eof
file(APPEND ${OUTPUT} "const char* ${cl_filename}=\"${lines};\n")
endforeach()
file(APPEND ${OUTPUT} "}\n}\n")