MakeComposite.cmake 930 B

12345678910111213141516171819202122232425262728
  1. # Filename: MakeComposite.cmake
  2. #
  3. # Description: When run, creates a single C++ file which includes multiple
  4. # other C++ files, to help facilitate unity builds.
  5. # Unity builds provide significantly increased compile speed.
  6. #
  7. # Usage:
  8. # This script is invoked via add_custom_target, like this:
  9. # cmake -P MakeComposite.cmake -D COMPOSITE_FILE="x_composite1.cxx" -D COMPOSITE_SOURCES="a.cxx b.cxx"
  10. #
  11. if(CMAKE_SCRIPT_MODE_FILE)
  12. if(NOT DEFINED COMPOSITE_FILE)
  13. message(FATAL_ERROR "COMPOSITE_FILE should be defined when running MakeComposite.cmake!")
  14. return()
  15. endif()
  16. file(WRITE "${COMPOSITE_FILE}" "/* Generated by CMake. DO NOT EDIT. */\n")
  17. separate_arguments(COMPOSITE_SOURCES)
  18. foreach(source ${COMPOSITE_SOURCES})
  19. file(APPEND "${COMPOSITE_FILE}" "#include \"${source}\"\n")
  20. endforeach()
  21. else()
  22. message(SEND_ERROR "MakeComposite.cmake should not be included but run in script mode.")
  23. endif()