CacheLog.cmake 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # Functions for keeping track of set cache variables and clearing them.
  2. #
  3. # get_cachelog_var
  4. #
  5. # add_to_cachelog
  6. #
  7. # unset_cachelog_entries
  8. #
  9. # reset_cachelog
  10. #
  11. # Get name of variable that cachelog will be stored in for this file.
  12. #
  13. # Name the cachelog variable after the Find* file that called this function.
  14. # This prevents collisions if multiple find modules use these functions.
  15. function(get_cachelog_var _cachelog_var_outname)
  16. get_filename_component(_log_var "${CMAKE_CURRENT_LIST_FILE}" NAME)
  17. string(MAKE_C_IDENTIFIER "${_log_var}" _log_var)
  18. set(${_cachelog_var_outname} "${_log_var}_cachelog" PARENT_SCOPE)
  19. endfunction()
  20. # Add the given cache variable name to the cache log, and mark it as advanced.
  21. function(add_to_cachelog _name)
  22. get_cachelog_var(_log_var)
  23. set(${_log_var} ${${_log_var}} ${_name} CACHE INTERNAL "" FORCE)
  24. mark_as_advanced(FORCE ${_name})
  25. endfunction()
  26. # Unset all cache variables that are listed in the cache log.
  27. function(unset_cachelog_entries)
  28. get_cachelog_var(_log_var)
  29. foreach (_cachevar ${${_log_var}})
  30. unset(${_cachevar} CACHE)
  31. endforeach ()
  32. endfunction()
  33. # Remove all cache variable names from the cache log.
  34. function(reset_cachelog)
  35. get_cachelog_var(_log_var)
  36. set(${_log_var} "" CACHE INTERNAL "" FORCE)
  37. endfunction()
  38. # From https://github.com/Monetra/mstdlib/blob/master/CMakeModules
  39. # The MIT License (MIT)
  40. # Copyright (c) 2015-2017 Main Street Softworks, Inc.
  41. # Permission is hereby granted, free of charge, to any person obtaining a copy
  42. # of this software and associated documentation files (the "Software"), to deal
  43. # in the Software without restriction, including without limitation the rights
  44. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  45. # copies of the Software, and to permit persons to whom the Software is
  46. # furnished to do so, subject to the following conditions:
  47. # The above copyright notice and this permission notice shall be included in
  48. # all copies or substantial portions of the Software.
  49. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  50. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  51. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  52. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  53. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  54. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  55. # THE SOFTWARE.