CMakeClDeps.cmake 1.6 KB

12345678910111213141516171819202122232425262728293031323334
  1. #=============================================================================
  2. # Copyright 2012 Kitware, Inc.
  3. #
  4. # Distributed under the OSI-approved BSD License (the "License");
  5. # see accompanying file Copyright.txt for details.
  6. #
  7. # This software is distributed WITHOUT ANY WARRANTY; without even the
  8. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. # See the License for more information.
  10. #=============================================================================
  11. # (To distribute this file outside of CMake, substitute the full
  12. # License text for the above reference.)
  13. #
  14. # When using Ninja cl.exe is wrapped by cmcldeps to extract the included
  15. # headers for dependency tracking.
  16. #
  17. # cmcldeps path is set, and cmcldeps needs to know the localized string
  18. # in front of each include path, so it can remove it.
  19. #
  20. if(CMAKE_GENERATOR MATCHES "Ninja" AND CMAKE_C_COMPILER AND CMAKE_COMMAND)
  21. string(REPLACE "cmake.exe" "cmcldeps.exe" CMAKE_CMCLDEPS_EXECUTABLE ${CMAKE_COMMAND})
  22. set(showdir ${CMAKE_BINARY_DIR}/CMakeFiles/ShowIncludes)
  23. file(WRITE ${showdir}/foo.h "\n")
  24. file(WRITE ${showdir}/main.c "#include \"foo.h\" \nint main(){}\n")
  25. execute_process(COMMAND ${CMAKE_C_COMPILER} /nologo /showIncludes ${showdir}/main.c
  26. WORKING_DIRECTORY ${showdir} OUTPUT_VARIABLE outLine)
  27. string(REGEX MATCH "\n([^:]*:[^:]*:[ \t]*)" tmp "${outLine}")
  28. set(localizedPrefix "${CMAKE_MATCH_1}")
  29. set(SET_CMAKE_CMCLDEPS_EXECUTABLE "set(CMAKE_CMCLDEPS_EXECUTABLE \"${CMAKE_CMCLDEPS_EXECUTABLE}\")")
  30. set(SET_CMAKE_CL_SHOWINCLUDES_PREFIX "set(CMAKE_CL_SHOWINCLUDES_PREFIX \"${localizedPrefix}\")")
  31. endif()