ModuleNoticesTest.cmake.in 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # Regex to match copyright/license notices.
  2. # We require the Kitware copyright on the first line, but this can
  3. # match any additional copyright holder notices.
  4. set(notice_regex "
  5. #=============================================================================
  6. # Copyright (20[0-9][0-9]-)?20[0-9][0-9] Kitware[^\n]+(
  7. # Copyright (20[0-9][0-9]-)?20[0-9][0-9] [^\n]+)*
  8. #
  9. # Distributed under the OSI-approved BSD License \\(the \"License\"\\);
  10. # see accompanying file Copyright\\.txt for details\\.
  11. #
  12. # This software is distributed WITHOUT ANY WARRANTY; without even the
  13. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE\\.
  14. # See the License for more information\\.
  15. #=============================================================================
  16. # \\(To distributed this file outside of CMake, substitute the full
  17. # License text for the above reference.\\)
  18. ")
  19. string(REPLACE "\n" "\r?\n" notice_regex "${notice_regex}")
  20. string(REPLACE "\r\r" "\r" notice_regex "${notice_regex}")
  21. # Modules that do not require our notice.
  22. set(notice_exceptions
  23. FindCUDA.cmake # MIT License, distributed here from upstream project
  24. )
  25. # Load the list of modules to check.
  26. set(dir "@CMake_SOURCE_DIR@/Modules")
  27. file(GLOB all_modules RELATIVE "${dir}" "${dir}/*.cmake")
  28. list(REMOVE_ITEM all_modules ${notice_exceptions})
  29. # Check each module.
  30. set(notice_missing)
  31. foreach(module ${all_modules})
  32. message(STATUS "module: ${module}")
  33. file(READ "${dir}/${module}" module_content)
  34. if(NOT "${module_content}" MATCHES "${notice_regex}")
  35. set(notice_missing "${notice_missing} ${module}\n")
  36. endif()
  37. endforeach()
  38. # Report the list of bad modules.
  39. if(notice_missing)
  40. message(FATAL_ERROR
  41. "Some modules do not have a valid copyright notice:\n${notice_missing}")
  42. endif()