MakeComposite.cmake 972 B

123456789101112131415161718192021222324252627282930
  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. #cmake_minimum_required(VERSION 2.8.4)
  13. if(NOT DEFINED COMPOSITE_FILE)
  14. message(FATAL_ERROR "COMPOSITE_FILE should be defined when running MakeComposite.cmake!")
  15. return()
  16. endif()
  17. file(WRITE "${COMPOSITE_FILE}" "/* Generated by CMake. DO NOT EDIT. */\n")
  18. separate_arguments(COMPOSITE_SOURCES)
  19. foreach(source ${COMPOSITE_SOURCES})
  20. file(APPEND "${COMPOSITE_FILE}" "#include \"${source}\"\n")
  21. endforeach()
  22. else()
  23. message(SEND_ERROR "MakeComposite.cmake should not be included but run in script mode.")
  24. endif()