blob: 16c65f632bc6dcdf1e02fa3dddee85357d01fd63 [file] [log] [blame]
Michael Gottesmanca589cc2016-07-09 21:58:40 +00001function(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")
Justin Bogner66b326b2016-11-07 23:46:05 +000092
93 if(${name} IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR
94 NOT LLVM_DISTRIBUTION_COMPONENTS)
95 set(export_to_clangtargets EXPORT ClangTargets)
96 endif()
97
Michael Gottesmanca589cc2016-07-09 21:58:40 +000098 install(TARGETS ${name}
99 COMPONENT ${name}
Justin Bogner66b326b2016-11-07 23:46:05 +0000100 ${export_to_clangtargets}
Michael Gottesmanca589cc2016-07-09 21:58:40 +0000101 LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
102 ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}
103 RUNTIME DESTINATION bin)
104
105 if (${ARG_SHARED} AND NOT CMAKE_CONFIGURATION_TYPES)
106 add_custom_target(install-${name}
107 DEPENDS ${name}
108 COMMAND "${CMAKE_COMMAND}"
109 -DCMAKE_INSTALL_COMPONENT=${name}
110 -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
111 endif()
112 endif()
113 set_property(GLOBAL APPEND PROPERTY CLANG_EXPORTS ${name})
114 else()
115 # Add empty "phony" target
116 add_custom_target(${name})
117 endif()
118
119 set_target_properties(${name} PROPERTIES FOLDER "Clang libraries")
120 set_clang_windows_version_resource_properties(${name})
121endmacro(add_clang_library)
122
123macro(add_clang_executable name)
124 add_llvm_executable( ${name} ${ARGN} )
125 set_target_properties(${name} PROPERTIES FOLDER "Clang executables")
126 set_clang_windows_version_resource_properties(${name})
127endmacro(add_clang_executable)
128
129macro(add_clang_tool name)
Michael Gottesmaneb396a62016-07-10 01:44:00 +0000130 if (NOT CLANG_BUILD_TOOLS)
131 set(EXCLUDE_FROM_ALL ON)
132 endif()
Michael Gottesmanca589cc2016-07-09 21:58:40 +0000133
Michael Gottesmaneb396a62016-07-10 01:44:00 +0000134 add_clang_executable(${name} ${ARGN})
135
136 if (CLANG_BUILD_TOOLS)
Justin Bogner66b326b2016-11-07 23:46:05 +0000137 if(${name} IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR
138 NOT LLVM_DISTRIBUTION_COMPONENTS)
139 set(export_to_clangtargets EXPORT ClangTargets)
140 endif()
141
Michael Gottesmaneb396a62016-07-10 01:44:00 +0000142 install(TARGETS ${name}
Justin Bogner66b326b2016-11-07 23:46:05 +0000143 ${export_to_clangtargets}
Michael Gottesmaneb396a62016-07-10 01:44:00 +0000144 RUNTIME DESTINATION bin
145 COMPONENT ${name})
146
147 if(NOT CMAKE_CONFIGURATION_TYPES)
148 add_custom_target(install-${name}
149 DEPENDS ${name}
150 COMMAND "${CMAKE_COMMAND}"
151 -DCMAKE_INSTALL_COMPONENT=${name}
152 -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
153 endif()
Michael Gottesman66cc2d52016-10-19 22:46:06 +0000154 set_property(GLOBAL APPEND PROPERTY CLANG_EXPORTS ${name})
Michael Gottesmanca589cc2016-07-09 21:58:40 +0000155 endif()
156endmacro()
157
158macro(add_clang_symlink name dest)
159 add_llvm_tool_symlink(${name} ${dest} ALWAYS_GENERATE)
160 # Always generate install targets
161 llvm_install_symlink(${name} ${dest} ALWAYS_GENERATE)
162endmacro()