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()
|
|
|
|
|
2017-03-23 19:42:23 +08:00
|
|
|
string(REGEX REPLACE "\\.cpp$" ".hpp" OUTPUT_HPP "${OUTPUT}")
|
2013-09-27 20:41:25 +08:00
|
|
|
get_filename_component(OUTPUT_HPP_NAME "${OUTPUT_HPP}" NAME)
|
|
|
|
|
2016-12-19 05:38:33 +08:00
|
|
|
set(nested_namespace_start "namespace ${MODULE_NAME}\n{")
|
|
|
|
set(nested_namespace_end "}")
|
2013-11-19 00:48:00 +08:00
|
|
|
|
2013-09-27 20:41:25 +08:00
|
|
|
set(STR_CPP "// This file is auto-generated. Do not edit!
|
|
|
|
|
2018-03-16 21:36:11 +08:00
|
|
|
#include \"opencv2/core.hpp\"
|
2015-12-14 18:52:02 +08:00
|
|
|
#include \"cvconfig.h\"
|
2013-09-27 20:41:25 +08:00
|
|
|
#include \"${OUTPUT_HPP_NAME}\"
|
|
|
|
|
2015-06-20 01:52:14 +08:00
|
|
|
#ifdef HAVE_OPENCL
|
|
|
|
|
2013-09-27 20:41:25 +08:00
|
|
|
namespace cv
|
|
|
|
{
|
|
|
|
namespace ocl
|
|
|
|
{
|
2013-11-19 00:48:00 +08:00
|
|
|
${nested_namespace_start}
|
|
|
|
|
2016-12-19 05:38:33 +08:00
|
|
|
static const char* const moduleName = \"${MODULE_NAME}\";
|
|
|
|
|
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
|
|
|
|
2015-06-20 01:52:14 +08:00
|
|
|
#ifdef HAVE_OPENCL
|
|
|
|
|
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}")
|
|
|
|
|
2016-12-19 05:38:33 +08:00
|
|
|
set(STR_CPP_DECL "struct cv::ocl::internal::ProgramEntry ${cl_filename}_oclsrc={moduleName, \"${cl_filename}\",\n\"${lines}, \"${hash}\", NULL};\n")
|
|
|
|
set(STR_HPP_DECL "extern struct cv::ocl::internal::ProgramEntry ${cl_filename}_oclsrc;\n")
|
2013-11-19 00:48:00 +08:00
|
|
|
|
|
|
|
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()
|
|
|
|
|
2016-12-19 05:38:33 +08:00
|
|
|
set(STR_CPP "${STR_CPP}\n${nested_namespace_end}}}\n#endif\n")
|
|
|
|
set(STR_HPP "${STR_HPP}\n${nested_namespace_end}}}\n#endif\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}")
|
2016-12-19 05:38:33 +08:00
|
|
|
message(STATUS "${OUTPUT_HPP} contains the same content")
|
2013-09-25 23:07:14 +08:00
|
|
|
else()
|
|
|
|
file(WRITE "${OUTPUT_HPP}" "${STR_HPP}")
|
|
|
|
endif()
|