2@file vtkHashSource.cmake
 
    4This 
module contains the @ref vtk_hash_source function which may be used to
 
    5generate a hash from a file and place that in a generated header.
 
    8set(_vtkHashSource_script_file "${CMAKE_CURRENT_LIST_FILE}")
 
   11@brief Generate a header containing the hash of a file
 
   13Add a rule to turn a file into a MD5 hash and place that in a C string.
 
   19  [ALGORITHM     <algorithm>]
 
   20  [HEADER_OUTPUT <header>])
 
   23The only required variable is `INPUT`.
 
   25  * `INPUT`: (Required) The path to the file to process. If a relative path
 
   26    is given, it will be interpreted as being relative to
 
   27    `CMAKE_CURRENT_SOURCE_DIR`.
 
   28  * `NAME`: This is the base name of the header file that will be generated as
 
   29    well as the variable name for the C string. It defaults to basename of the
 
   30    input suffixed with `Hash`.
 
   31  * `ALGORITHM`: This is the hashing algorithm to use. Supported values are
 
   32    MD5, SHA1, SHA224, SHA256, SHA384, and SHA512. If not specified, MD5 is assumed.
 
   33  * `HEADER_OUTPUT`: the variable to store the generated header path.
 
   35function (vtk_hash_source)
 
   36  cmake_parse_arguments(PARSE_ARGV 0 _vtk_hash_source
 
   38    "INPUT;NAME;ALGORITHM;HEADER_OUTPUT
" 
   41  if (_vtk_hash_source_UNPARSED_ARGUMENTS) 
   44      "${_vtk_hash_source_UNPARSED_ARGUMENTS}
") 
   47  if (NOT DEFINED _vtk_hash_source_INPUT) 
   52  if (NOT DEFINED _vtk_hash_source_NAME) 
   53    get_filename_component(_vtk_hash_source_NAME 
   54      "${_vtk_hash_source_INPUT}
" NAME_WE) 
   55    set(_vtk_hash_source_NAME "${_vtk_hash_source_NAME}Hash
") 
   58  if (NOT DEFINED _vtk_hash_source_ALGORITHM) 
   59    set(_vtk_hash_source_ALGORITHM MD5) 
   62  if (IS_ABSOLUTE "${_vtk_hash_source_INPUT}
") 
   63    set(_vtk_hash_source_input 
   64      "${_vtk_hash_source_INPUT}
") 
   66    set(_vtk_hash_source_input 
   67      "${CMAKE_CURRENT_SOURCE_DIR}/${_vtk_hash_source_INPUT}
") 
   70  set(_vtk_hash_source_header 
   71    "${CMAKE_CURRENT_BINARY_DIR}/${_vtk_hash_source_NAME}.h
") 
   74    OUTPUT  "${_vtk_hash_source_header}
" 
   75    DEPENDS "${_vtkHashSource_script_file}
" 
   76            "${_vtk_hash_source_input}
" 
   77    COMMAND "${CMAKE_COMMAND}
" 
   78            "-Dinput_file=${_vtk_hash_source_input}
" 
   79            "-Doutput_file=${_vtk_hash_source_header}
" 
   80            "-Doutput_name=${_vtk_hash_source_NAME}
" 
   81            "-Dalgorithm=${_vtk_hash_source_ALGORITHM}
" 
   82            "-D_vtk_hash_source_run=ON
" 
   83            -P "${_vtkHashSource_script_file}
") 
   85  if (DEFINED _vtk_hash_source_HEADER_OUTPUT) 
   86    set("${_vtk_hash_source_HEADER_OUTPUT}
" 
   87      "${_vtk_hash_source_header}
" 
   92if (_vtk_hash_source_run AND CMAKE_SCRIPT_MODE_FILE) 
   93  file(${algorithm} "${input_file}
" file_hash) 
   94  file(WRITE "${output_file}
" 
   95    "#ifndef ${output_name}\n #define ${output_name} \
"${file_hash}\"\n#endif\n")
 
function vtk_hash_source()
Generate a header containing the hash of a file.