2015-06-11 20:36:29 +08:00
|
|
|
if (NOT EXISTS "${CL_DIR}")
|
|
|
|
message(FATAL_ERROR "Specified wrong OpenCL kernels directory: ${CL_DIR}")
|
|
|
|
endif()
|
|
|
|
|
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
|
|
|
|
2015-06-11 20:36:29 +08:00
|
|
|
if (NOT cl_list)
|
|
|
|
message(FATAL_ERROR "Can't find OpenCL kernels in directory: ${CL_DIR}")
|
|
|
|
endif()
|
|
|
|
|
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
|
|
|
|
2014-12-05 22:48:28 +08:00
|
|
|
#include \"opencv2/core/ocl.hpp\"
|
2013-11-19 00:48:00 +08:00
|
|
|
#include \"opencv2/core/ocl_genbase.hpp\"
|
2014-01-22 19:51:28 +08:00
|
|
|
#include \"opencv2/core/opencl/ocl_defs.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)
|
2014-02-01 00:23:01 +08:00
|
|
|
set(STR_CPP_DECL "${STR_CPP_DECL}ProgramSource ${cl_filename}_oclsrc(${cl_filename}.programStr);\n")
|
|
|
|
set(STR_HPP_DECL "${STR_HPP_DECL}extern ProgramSource ${cl_filename}_oclsrc;\n")
|
2013-11-19 00:48:00 +08:00
|
|
|
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()
|