• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1function(clang_tablegen)
2  # Syntax:
3  # clang_tablegen output-file [tablegen-arg ...] SOURCE source-file
4  # [[TARGET cmake-target-name] [DEPENDS extra-dependency ...]]
5  #
6  # Generates a custom command for invoking tblgen as
7  #
8  # tblgen source-file -o=output-file tablegen-arg ...
9  #
10  # and, if cmake-target-name is provided, creates a custom target for
11  # executing the custom command depending on output-file. It is
12  # possible to list more files to depend after DEPENDS.
13
14  cmake_parse_arguments(CTG "" "SOURCE;TARGET" "" ${ARGN})
15
16  if( NOT CTG_SOURCE )
17    message(FATAL_ERROR "SOURCE source-file required by clang_tablegen")
18  endif()
19
20  set( LLVM_TARGET_DEFINITIONS ${CTG_SOURCE} )
21  tablegen(CLANG ${CTG_UNPARSED_ARGUMENTS})
22
23  if(CTG_TARGET)
24    add_public_tablegen_target(${CTG_TARGET})
25    set_target_properties( ${CTG_TARGET} PROPERTIES FOLDER "Clang tablegenning")
26    set_property(GLOBAL APPEND PROPERTY CLANG_TABLEGEN_TARGETS ${CTG_TARGET})
27  endif()
28endfunction(clang_tablegen)
29
30macro(set_clang_windows_version_resource_properties name)
31  if(DEFINED windows_resource_file)
32    set_windows_version_resource_properties(${name} ${windows_resource_file}
33      VERSION_MAJOR ${CLANG_VERSION_MAJOR}
34      VERSION_MINOR ${CLANG_VERSION_MINOR}
35      VERSION_PATCHLEVEL ${CLANG_VERSION_PATCHLEVEL}
36      VERSION_STRING "${CLANG_VERSION} (${BACKEND_PACKAGE_STRING})"
37      PRODUCT_NAME "clang")
38  endif()
39endmacro()
40
41macro(add_clang_subdirectory name)
42  add_llvm_subdirectory(CLANG TOOL ${name})
43endmacro()
44
45macro(add_clang_library name)
46  cmake_parse_arguments(ARG
47    "SHARED"
48    ""
49    "ADDITIONAL_HEADERS"
50    ${ARGN})
51  set(srcs)
52  if(MSVC_IDE OR XCODE)
53    # Add public headers
54    file(RELATIVE_PATH lib_path
55      ${CLANG_SOURCE_DIR}/lib/
56      ${CMAKE_CURRENT_SOURCE_DIR}
57    )
58    if(NOT lib_path MATCHES "^[.][.]")
59      file( GLOB_RECURSE headers
60        ${CLANG_SOURCE_DIR}/include/clang/${lib_path}/*.h
61        ${CLANG_SOURCE_DIR}/include/clang/${lib_path}/*.def
62      )
63      set_source_files_properties(${headers} PROPERTIES HEADER_FILE_ONLY ON)
64
65      file( GLOB_RECURSE tds
66        ${CLANG_SOURCE_DIR}/include/clang/${lib_path}/*.td
67      )
68      source_group("TableGen descriptions" FILES ${tds})
69      set_source_files_properties(${tds}} PROPERTIES HEADER_FILE_ONLY ON)
70
71      if(headers OR tds)
72        set(srcs ${headers} ${tds})
73      endif()
74    endif()
75  endif(MSVC_IDE OR XCODE)
76  if(srcs OR ARG_ADDITIONAL_HEADERS)
77    set(srcs
78      ADDITIONAL_HEADERS
79      ${srcs}
80      ${ARG_ADDITIONAL_HEADERS} # It may contain unparsed unknown args.
81      )
82  endif()
83  if(ARG_SHARED)
84    set(ARG_ENABLE_SHARED SHARED)
85  endif()
86  llvm_add_library(${name} ${ARG_ENABLE_SHARED} ${ARG_UNPARSED_ARGUMENTS} ${srcs})
87
88  if(TARGET ${name})
89    target_link_libraries(${name} INTERFACE ${LLVM_COMMON_LIBS})
90
91    if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "libclang")
92      install(TARGETS ${name}
93        COMPONENT ${name}
94        EXPORT ClangTargets
95        LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
96        ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}
97        RUNTIME DESTINATION bin)
98
99      if (${ARG_SHARED} AND NOT CMAKE_CONFIGURATION_TYPES)
100        add_custom_target(install-${name}
101                          DEPENDS ${name}
102                          COMMAND "${CMAKE_COMMAND}"
103                                  -DCMAKE_INSTALL_COMPONENT=${name}
104                                  -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
105      endif()
106    endif()
107    set_property(GLOBAL APPEND PROPERTY CLANG_EXPORTS ${name})
108  else()
109    # Add empty "phony" target
110    add_custom_target(${name})
111  endif()
112
113  set_target_properties(${name} PROPERTIES FOLDER "Clang libraries")
114  set_clang_windows_version_resource_properties(${name})
115endmacro(add_clang_library)
116
117macro(add_clang_executable name)
118  add_llvm_executable( ${name} ${ARGN} )
119  set_target_properties(${name} PROPERTIES FOLDER "Clang executables")
120  set_clang_windows_version_resource_properties(${name})
121endmacro(add_clang_executable)
122
123macro(add_clang_tool name)
124  if (NOT CLANG_BUILD_TOOLS)
125    set(EXCLUDE_FROM_ALL ON)
126  endif()
127
128  add_clang_executable(${name} ${ARGN})
129
130  if (CLANG_BUILD_TOOLS)
131    install(TARGETS ${name}
132      RUNTIME DESTINATION bin
133      COMPONENT ${name})
134
135    if(NOT CMAKE_CONFIGURATION_TYPES)
136      add_custom_target(install-${name}
137        DEPENDS ${name}
138        COMMAND "${CMAKE_COMMAND}"
139        -DCMAKE_INSTALL_COMPONENT=${name}
140        -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
141    endif()
142  endif()
143endmacro()
144
145macro(add_clang_symlink name dest)
146  add_llvm_tool_symlink(${name} ${dest} ALWAYS_GENERATE)
147  # Always generate install targets
148  llvm_install_symlink(${name} ${dest} ALWAYS_GENERATE)
149endmacro()
150