CreateTempFile.cmake 655 B

12345678910111213141516171819202122
  1. function(CreateTempFilePath)
  2. set(options CONFIG_SUFFIX)
  3. set(oneValueArgs OUTPUT_VAR TAG)
  4. set(multiValueArgs CONTENT)
  5. cmake_parse_arguments(TEMP "${options}" "${oneValueArgs}"
  6. "${multiValueArgs}" ${ARGN} )
  7. # Use hash to create a unique identifier
  8. # for this file.
  9. string(SHA1 hashed_content "${TEMP_CONTENT}")
  10. set(file_name "${CMAKE_BINARY_DIR}/${TEMP_TAG}_${hashed_content}")
  11. set(${TEMP_OUTPUT_VAR} "${file_name}" PARENT_SCOPE)
  12. if(CONFIG_SUFFIX)
  13. set(file_name "${file_name}_$<CONFIG>")
  14. endif()
  15. file(GENERATE OUTPUT "${file_name}"
  16. CONTENT "${TEMP_CONTENT}")
  17. endfunction()