1option(CLANG_INSTALL_SCANBUILD "Install the scan-build tool" ON)
2
3include(GNUInstallDirs)
4
5if (WIN32 AND NOT CYGWIN)
6  set(BinFiles
7        scan-build
8        scan-build.bat
9	)
10  set(LibexecFiles
11        ccc-analyzer
12        c++-analyzer
13        ccc-analyzer.bat
14        c++-analyzer.bat
15	)
16else()
17  set(BinFiles
18        scan-build
19	)
20  set(LibexecFiles
21        ccc-analyzer
22        c++-analyzer
23	)
24  if (APPLE)
25    list(APPEND BinFiles
26           set-xcode-analyzer
27	   )
28  endif()
29endif()
30
31set(ManPages
32      scan-build.1)
33
34set(ShareFiles
35      scanview.css
36      sorttable.js)
37
38
39if(CLANG_INSTALL_SCANBUILD)
40  foreach(BinFile ${BinFiles})
41    add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/bin/${BinFile}
42                       COMMAND ${CMAKE_COMMAND} -E make_directory
43                         ${CMAKE_BINARY_DIR}/bin
44                       COMMAND ${CMAKE_COMMAND} -E copy
45                         ${CMAKE_CURRENT_SOURCE_DIR}/bin/${BinFile}
46                         ${CMAKE_BINARY_DIR}/bin/
47                       DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/bin/${BinFile})
48    list(APPEND Depends ${CMAKE_BINARY_DIR}/bin/${BinFile})
49    install(PROGRAMS bin/${BinFile}
50            DESTINATION bin
51            COMPONENT scan-build)
52  endforeach()
53
54  foreach(LibexecFile ${LibexecFiles})
55    add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/libexec/${LibexecFile}
56                       COMMAND ${CMAKE_COMMAND} -E make_directory
57                         ${CMAKE_BINARY_DIR}/libexec
58                       COMMAND ${CMAKE_COMMAND} -E copy
59                         ${CMAKE_CURRENT_SOURCE_DIR}/libexec/${LibexecFile}
60                         ${CMAKE_BINARY_DIR}/libexec/
61                       DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/libexec/${LibexecFile})
62    list(APPEND Depends ${CMAKE_BINARY_DIR}/libexec/${LibexecFile})
63    install(PROGRAMS libexec/${LibexecFile}
64            DESTINATION libexec
65            COMPONENT scan-build)
66  endforeach()
67
68  foreach(ManPage ${ManPages})
69    add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_MANDIR}/man1/${ManPage}
70                       COMMAND ${CMAKE_COMMAND} -E make_directory
71                         ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_MANDIR}/man1
72                       COMMAND ${CMAKE_COMMAND} -E copy
73                         ${CMAKE_CURRENT_SOURCE_DIR}/man/${ManPage}
74                         ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_MANDIR}/man1/
75                       DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/man/${ManPage})
76    list(APPEND Depends ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_MANDIR}/man1/${ManPage})
77    install(PROGRAMS man/${ManPage}
78            DESTINATION ${CMAKE_INSTALL_MANDIR}/man1
79            COMPONENT scan-build)
80  endforeach()
81
82  foreach(ShareFile ${ShareFiles})
83    add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/share/scan-build/${ShareFile}
84                       COMMAND ${CMAKE_COMMAND} -E make_directory
85                         ${CMAKE_BINARY_DIR}/share/scan-build
86                       COMMAND ${CMAKE_COMMAND} -E copy
87                         ${CMAKE_CURRENT_SOURCE_DIR}/share/scan-build/${ShareFile}
88                         ${CMAKE_BINARY_DIR}/share/scan-build/
89                       DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/share/scan-build/${ShareFile})
90    list(APPEND Depends ${CMAKE_BINARY_DIR}/share/scan-build/${ShareFile})
91    install(FILES share/scan-build/${ShareFile}
92            DESTINATION share/scan-build
93            COMPONENT scan-build)
94  endforeach()
95
96  add_custom_target(scan-build ALL DEPENDS ${Depends})
97  set_target_properties(scan-build PROPERTIES FOLDER "Misc")
98
99  if(NOT LLVM_ENABLE_IDE)
100    add_llvm_install_targets("install-scan-build"
101                             DEPENDS scan-build
102                             COMPONENT scan-build)
103  endif()
104endif()
105