1option(BUILD_CLANG_FORMAT_VS_PLUGIN "Build clang-format VS plugin" OFF)
2if (BUILD_CLANG_FORMAT_VS_PLUGIN)
3  add_custom_target(clang_format_exe_for_vsix
4      ${CMAKE_COMMAND} -E copy_if_different
5      "${LLVM_TOOLS_BINARY_DIR}/clang-format.exe"
6      "${CMAKE_CURRENT_SOURCE_DIR}/ClangFormat/clang-format.exe"
7      DEPENDS clang-format)
8
9  # Build number added to Clang version to ensure that new VSIX can be upgraded
10  string(TIMESTAMP CLANG_FORMAT_VSIX_BUILD %y%m%d%H%M UTC)
11
12  if (NOT CLANG_FORMAT_VS_VERSION)
13    set(CLANG_FORMAT_VS_VERSION "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}.${CLANG_FORMAT_VSIX_BUILD}")
14  endif()
15
16  configure_file("source.extension.vsixmanifest.in"
17      "${CMAKE_CURRENT_SOURCE_DIR}/ClangFormat/source.extension.vsixmanifest")
18
19  find_program(NUGET_EXE nuget PATHS ${NUGET_EXE_DIR})
20  if (NOT NUGET_EXE)
21    message(FATAL_ERROR "Could not find nuget.exe. Download from https://www.nuget.org/nuget.exe"
22                        " and add parent directory to PATH or pass it via NUGET_EXE_DIR var.")
23  endif()
24
25  add_custom_target(clang_format_vsix ALL
26      COMMAND ${NUGET_EXE} restore "${CMAKE_CURRENT_SOURCE_DIR}/ClangFormat.sln"
27      COMMAND devenv "${CMAKE_CURRENT_SOURCE_DIR}/ClangFormat.sln" /Build Release
28      DEPENDS clang_format_exe_for_vsix "${CMAKE_CURRENT_SOURCE_DIR}/ClangFormat/source.extension.vsixmanifest"
29      COMMAND ${CMAKE_COMMAND} -E copy_if_different
30      "${CMAKE_CURRENT_SOURCE_DIR}/ClangFormat/bin/Release/ClangFormat.vsix"
31      "${LLVM_TOOLS_BINARY_DIR}/ClangFormat.vsix"
32      DEPENDS clang_format_exe_for_vsix)
33endif()
34