2012-10-20 20:17:41 +08:00
|
|
|
file(GLOB cl_list "${CL_DIR}/*.cl" )
|
2013-09-27 20:41:25 +08:00
|
|
|
list(SORT cl_list)
|
2012-10-20 20:17:41 +08:00
|
|
|
|
2013-09-27 20:41:25 +08:00
|
|
|
string(REPLACE ".cpp" ".hpp" OUTPUT_HPP "${OUTPUT}")
|
|
|
|
get_filename_component(OUTPUT_HPP_NAME "${OUTPUT_HPP}" NAME)
|
|
|
|
|
2013-11-19 00:48:00 +08:00
|
|
|
if("${MODULE_NAME}" STREQUAL "ocl")
|
|
|
|
set(nested_namespace_start "")
|
|
|
|
set(nested_namespace_end "")
|
|
|
|
else()
|
|
|
|
set(new_mode ON)
|
|
|
|
set(nested_namespace_start "namespace ${MODULE_NAME}\n{")
|
2013-11-19 02:48:04 +08:00
|
|
|
set(nested_namespace_end "}")
|
2013-11-19 00:48:00 +08:00
|
|
|
endif()
|
|
|
|
|
2013-09-27 20:41:25 +08:00
|
|
|
set(STR_CPP "// This file is auto-generated. Do not edit!
|
|
|
|
|
2013-10-09 20:57:52 +08:00
|
|
|
#include \"precomp.hpp\"
|
2013-09-27 20:41:25 +08:00
|
|
|
#include \"${OUTPUT_HPP_NAME}\"
|
|
|
|
|
|
|
|
namespace cv
|
|
|
|
{
|
|
|
|
namespace ocl
|
|
|
|
{
|
2013-11-19 00:48:00 +08:00
|
|
|
${nested_namespace_start}
|
|
|
|
|
2013-09-27 20:41:25 +08:00
|
|
|
")
|
|
|
|
|
|
|
|
set(STR_HPP "// This file is auto-generated. Do not edit!
|
2012-10-20 20:17:41 +08:00
|
|
|
|
2013-11-19 00:48:00 +08:00
|
|
|
#include \"opencv2/core/ocl_genbase.hpp\"
|
2013-10-09 20:57:52 +08:00
|
|
|
|
2012-10-20 20:17:41 +08:00
|
|
|
namespace cv
|
|
|
|
{
|
|
|
|
namespace ocl
|
|
|
|
{
|
2013-11-19 00:48:00 +08:00
|
|
|
${nested_namespace_start}
|
2013-09-25 23:07:14 +08:00
|
|
|
|
2012-10-20 20:17:41 +08:00
|
|
|
")
|
|
|
|
|
|
|
|
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
|
2013-03-26 12:01:01 +08:00
|
|
|
string(REGEX REPLACE "/\\*([^\n])*\\*/" "" lines "${lines}") # single-line comments
|
2012-10-20 20:17:41 +08:00
|
|
|
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
|
|
|
|
|
2013-09-25 23:07:14 +08:00
|
|
|
string(MD5 hash "${lines}")
|
|
|
|
|
2013-11-19 00:48:00 +08:00
|
|
|
set(STR_CPP_DECL "const struct ProgramEntry ${cl_filename}={\"${cl_filename}\",\n\"${lines}, \"${hash}\"};\n")
|
|
|
|
set(STR_HPP_DECL "extern const struct ProgramEntry ${cl_filename};\n")
|
|
|
|
if(new_mode)
|
|
|
|
set(STR_CPP_DECL "${STR_CPP_DECL}ProgramSource2 ${cl_filename}_oclsrc(${cl_filename}.programStr);\n")
|
|
|
|
set(STR_HPP_DECL "${STR_HPP_DECL}extern ProgramSource2 ${cl_filename}_oclsrc;\n")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(STR_CPP "${STR_CPP}${STR_CPP_DECL}")
|
|
|
|
set(STR_HPP "${STR_HPP}${STR_HPP_DECL}")
|
2012-10-20 20:17:41 +08:00
|
|
|
endforeach()
|
|
|
|
|
2013-11-19 00:48:00 +08:00
|
|
|
set(STR_CPP "${STR_CPP}}\n${nested_namespace_end}}\n")
|
|
|
|
set(STR_HPP "${STR_HPP}}\n${nested_namespace_end}}\n")
|
2013-09-27 20:41:25 +08:00
|
|
|
|
2013-09-25 23:07:14 +08:00
|
|
|
file(WRITE "${OUTPUT}" "${STR_CPP}")
|
|
|
|
|
|
|
|
if(EXISTS "${OUTPUT_HPP}")
|
|
|
|
file(READ "${OUTPUT_HPP}" hpp_lines)
|
|
|
|
endif()
|
|
|
|
if("${hpp_lines}" STREQUAL "${STR_HPP}")
|
|
|
|
message(STATUS "${OUTPUT_HPP} contains same content")
|
|
|
|
else()
|
|
|
|
file(WRITE "${OUTPUT_HPP}" "${STR_HPP}")
|
|
|
|
endif()
|