You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 5.3 KiB

12 years ago
12 years ago
12 years ago
12 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. cotire
  2. ======
  3. Cotire (compile time reducer) is a CMake module that speeds up the build process of CMake based
  4. build systems by fully automating techniques as [precompiled header][pch] usage and
  5. [single compilation unit][scu] builds for C and C++.
  6. features
  7. --------
  8. * Non-intrusive. Requires no source code modification and only minimal changes to CMake list files.
  9. * Automatically generates a single compilation unit (aka unity source file) for a CMake target.
  10. * Automatically generates a [prefix header][pfh] by tracking includes used by a CMake target.
  11. * Automatically precompiles prefix header and applies resulting precompiled header to a CMake target.
  12. * Supports C/C++ compilers Clang, GCC and Visual Studio C++.
  13. * Supports mixed language CMake targets.
  14. * Supports console (Makefile generator) and IDE (Visual Studio and Xcode) based builds.
  15. * Compatible with CMake single build type and CMake multi-configuration builds.
  16. * Compatible with most CMake generators.
  17. * Compatible with parallel builds (make -j, Visual Studio, Xcode).
  18. * Leverages native precompiled header generation features of IDEs (Visual Studio and Xcode).
  19. * Compatible with CMake's [cross-compiling][ccrc] support.
  20. * Tested with Windows, Linux and OS X.
  21. * MIT licensed.
  22. requirements
  23. ------------
  24. * [CMake 2.8.6][cmk] or newer. The executable `cmake` should be on the system path.
  25. * [Visual Studio C++][vslstd], [MinGW][mingw] or [Cygwin][cgwn] under Windows.
  26. * [GCC][gcc] under Linux.
  27. * [Xcode][xcdt] developer tools package under OS X. This includes [Clang][clang].
  28. installation
  29. ------------
  30. Copy the file `CMake/cotire.cmake` to the module directory of your CMake project. In the
  31. top-level `CMakeList.txt` file, add the module directory to the CMake module search path:
  32. set (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMake")
  33. usage
  34. -----
  35. To use cotire in your CMake project, add the following include directive to the beginning of the
  36. top-level `CMakeList.txt`:
  37. include(cotire)
  38. To speed the build process of a CMake library or executable target, just apply the `cotire`
  39. function to the target:
  40. add_executable(MyExecutable ${MyExecutableSources})
  41. target_link_libraries(MyExecutable ${MyExecutableLibraries})
  42. cotire(MyExecutable)
  43. Cotire looks at the properties of the target provided by CMake (e.g., target type, source files,
  44. compile flags, preprocessor defines, include directories, ...) and sets up custom commands that
  45. will generate a unity source file, a prefix header and a precompiled header at build time
  46. specially tailored to the target.
  47. For the generation of the prefix header, cotire will automatically choose headers used by the
  48. target that are outside of the project directory and thus are likely to change infrequently.
  49. The precompiled prefix header is then applied to the target to speed up the compilation process.
  50. As a side effect, cotire generates a new target named `MyExecutable_unity`, which lets you perform
  51. a unity build for the original target. The unity target inherits all build settings from the
  52. original target except for linked libraries and target dependencies. To get a workable unity
  53. target, add another `target_link_libraries` call:
  54. cotire(MyExecutable)
  55. target_link_libraries(MyExecutable_unity ${MyExecutableLibraries})
  56. For Makefile based generators you can then invoke a unity build that produces the same output as
  57. the original target, but does so much faster by entering:
  58. $ make MyExecutable_unity
  59. See the advanced usage section of the [cotire manual][manual] for information on how to
  60. configure the cotire process (e.g., how to apply cotire to a certain build configuration only).
  61. The directory `Patches` contains patch files to enable cotire for some popular open sources
  62. packages that use CMake as a build system.
  63. speedup
  64. -------
  65. Depending on factors like hardware, compiler, the number of files in the target and the complexity
  66. of the C/C++ code, the build process of targets that use a cotire generated precompiled header
  67. will be sped up from 10 to 40 percent. Using precompiled headers however is not without
  68. [issues][PCHH] and may not work for some programs.
  69. A unity build may be up to 90 percent faster than the one file at a time build of the original
  70. target. Single compilation unit builds however are very unlikely to work without source code
  71. modifications, because they [break][EoUB] the use of some C and C++ language features.
  72. Generally, modern C++ code which makes heavy use of header-only libraries will profit the most from
  73. cotiring.
  74. limitations
  75. -----------
  76. * CMake configure time will increase for cotired targets.
  77. * The size of the CMake build folder will increase, because precompiled headers are large binaries.
  78. * It is not possible to share precompiled headers generated by cotire between CMake targets.
  79. [ccrc]:http://www.cmake.org/Wiki/CMake_Cross_Compiling
  80. [cgwn]:http://www.cygwin.com/
  81. [clang]:http://clang.llvm.org/
  82. [cmk]:http://www.cmake.org/cmake/resources/software.html
  83. [gcc]:http://gcc.gnu.org/
  84. [manual]:https://github.com/sakra/cotire/blob/master/MANUAL.md
  85. [mingw]:http://www.mingw.org/
  86. [pch]:http://en.wikipedia.org/wiki/Precompiled_header
  87. [pfh]:http://en.wikipedia.org/wiki/Prefix_header
  88. [scu]:http://en.wikipedia.org/wiki/Single_Compilation_Unit
  89. [vslstd]:http://msdn.microsoft.com/vstudio/
  90. [xcdt]:http://developer.apple.com/tools/xcode/
  91. [PCHH]:http://gcc.gnu.org/wiki/PCHHaters
  92. [EoUB]:http://leewinder.co.uk/blog/?p=394