ModuleNoticesTest.cmake.in 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. # Regex to match license notices at the top of module files.
  2. set(notice_regex [[^# Distributed under the OSI-approved BSD 3-Clause License\. See accompanying
  3. # file Copyright\.txt or https://cmake\.org/licensing for details\.
  4. ]])
  5. string(REPLACE "\n" "\r?\n" notice_regex "${notice_regex}")
  6. string(REPLACE "\r\r" "\r" notice_regex "${notice_regex}")
  7. # Modules that do not require our notice.
  8. set(notice_exceptions
  9. FindCUDA.cmake # MIT License, distributed here from upstream project
  10. )
  11. # Load the list of modules to check.
  12. set(dir "@CMake_SOURCE_DIR@/Modules")
  13. file(GLOB all_modules RELATIVE "${dir}" "${dir}/*.cmake")
  14. list(REMOVE_ITEM all_modules ${notice_exceptions})
  15. # Check each module.
  16. set(notice_missing)
  17. foreach(module ${all_modules})
  18. message(STATUS "module: ${module}")
  19. file(READ "${dir}/${module}" module_content)
  20. if(NOT "${module_content}" MATCHES "${notice_regex}")
  21. string(APPEND notice_missing " ${module}\n")
  22. endif()
  23. endforeach()
  24. # Report the list of bad modules.
  25. if(notice_missing)
  26. message(FATAL_ERROR
  27. "Some modules do not have a valid copyright notice:\n${notice_missing}")
  28. endif()