2 @file vtkHashSource.cmake
 
    4 This module contains the @ref 
vtk_hash_source function which may be used to
 
    5 generate a hash from a file and place that in a generated header.
 
    8 set(_vtkHashSource_script_file 
"${CMAKE_CURRENT_LIST_FILE}")
 
   10 include(CMakeParseArguments)
 
   13 @brief Generate a header containing the hash of a file
 
   15 Add a rule to turn a file into a MD5 hash and place that in a C 
string.
 
   21   [ALGORITHM     <algorithm>]
 
   22   [HEADER_OUTPUT <header>])
 
   25 The only required variable is `INPUT`.
 
   27   * `INPUT`: (Required) The path to the file to process. If a relative path
 
   28     is given, it will be interpreted as being relative to
 
   29     `CMAKE_CURRENT_SOURCE_DIR`.
 
   30   * `NAME`: This is the base 
name of the header file that will be generated as
 
   31     well as the variable 
name for the C 
string. It defaults to basename of the
 
   32     input suffixed with `Hash`.
 
   33   * `ALGORITHM`: This is the hashing algorithm to use. Supported values are
 
   34     MD5, SHA1, SHA224, SHA256, SHA384, and SHA512. If not specified, MD5 is assumed.
 
   35   * `HEADER_OUTPUT`: the variable to store the generated header path.
 
   38   cmake_parse_arguments(_vtk_hash_source
 
   40     "INPUT;NAME;ALGORITHM;HEADER_OUTPUT" 
   44   if (_vtk_hash_source_UNPARSED_ARGUMENTS)
 
   46       "Unrecognized arguments to vtk_hash_source: " 
   47       "${_vtk_hash_source_UNPARSED_ARGUMENTS}")
 
   50   if (NOT DEFINED _vtk_hash_source_INPUT)
 
   55   if (NOT DEFINED _vtk_hash_source_NAME)
 
   56     get_filename_component(_vtk_hash_source_NAME
 
   57       "${_vtk_hash_source_INPUT}
" NAME_WE) 
   58     set(_vtk_hash_source_NAME "${_vtk_hash_source_NAME}Hash
") 
   61   if (NOT DEFINED _vtk_hash_source_ALGORITHM) 
   62     set(_vtk_hash_source_ALGORITHM MD5) 
   65   if (IS_ABSOLUTE "${_vtk_hash_source_INPUT}
") 
   66     set(_vtk_hash_source_input 
   67       "${_vtk_hash_source_INPUT}
") 
   69     set(_vtk_hash_source_input 
   70       "${CMAKE_CURRENT_SOURCE_DIR}/${_vtk_hash_source_INPUT}
") 
   73   set(_vtk_hash_source_header 
   74     "${CMAKE_CURRENT_BINARY_DIR}/${_vtk_hash_source_NAME}.h
") 
   77     OUTPUT  "${_vtk_hash_source_header}
" 
   78     DEPENDS "${_vtkHashSource_script_file}
" 
   79             "${_vtk_hash_source_input}
" 
   80     COMMAND "${CMAKE_COMMAND}
" 
   81             "-Dinput_file=${_vtk_hash_source_input}
" 
   82             "-Doutput_file=${_vtk_hash_source_header}
" 
   83             "-Doutput_name=${_vtk_hash_source_NAME}
" 
   84             "-Dalgorithm=${_vtk_hash_source_ALGORITHM}
" 
   85             "-D_vtk_hash_source_run=ON
" 
   86             -P "${_vtkHashSource_script_file}
") 
   88   if (DEFINED _vtk_hash_source_HEADER_OUTPUT) 
   89     set("${_vtk_hash_source_HEADER_OUTPUT}
" 
   90       "${_vtk_hash_source_header}
" 
   95 if (_vtk_hash_source_run AND CMAKE_SCRIPT_MODE_FILE) 
   96   file(${algorithm} "${input_file}
" file_hash) 
   97   file(WRITE "${output_file}
" 
   98     "#ifndef ${output_name}\n #define ${output_name} \
"${file_hash}\"\n#endif\n")