blob: e657059744a4ffa77115275f74ee298b6487d891 [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)
Justin Bogner5ca4d5f2016-11-08 05:02:33 +000096 set_property(GLOBAL PROPERTY CLANG_HAS_EXPORTS True)
Justin Bogner66b326b2016-11-07 23:46:05 +000097 endif()
98
Michael Gottesmanca589cc2016-07-09 21:58:40 +000099 install(TARGETS ${name}
100 COMPONENT ${name}
Justin Bogner66b326b2016-11-07 23:46:05 +0000101 ${export_to_clangtargets}
Michael Gottesmanca589cc2016-07-09 21:58:40 +0000102 LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
103 ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}
104 RUNTIME DESTINATION bin)
105
106 if (${ARG_SHARED} AND NOT CMAKE_CONFIGURATION_TYPES)
107 add_custom_target(install-${name}
108 DEPENDS ${name}
109 COMMAND "${CMAKE_COMMAND}"
110 -DCMAKE_INSTALL_COMPONENT=${name}
111 -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
112 endif()
113 endif()
114 set_property(GLOBAL APPEND PROPERTY CLANG_EXPORTS ${name})
115 else()
116 # Add empty "phony" target
117 add_custom_target(${name})
118 endif()
119
120 set_target_properties(${name} PROPERTIES FOLDER "Clang libraries")
121 set_clang_windows_version_resource_properties(${name})
122endmacro(add_clang_library)
123
124macro(add_clang_executable name)
125 add_llvm_executable( ${name} ${ARGN} )
126 set_target_properties(${name} PROPERTIES FOLDER "Clang executables")
127 set_clang_windows_version_resource_properties(${name})
128endmacro(add_clang_executable)
129
130macro(add_clang_tool name)
Michael Gottesmaneb396a62016-07-10 01:44:00 +0000131 if (NOT CLANG_BUILD_TOOLS)
132 set(EXCLUDE_FROM_ALL ON)
133 endif()
Michael Gottesmanca589cc2016-07-09 21:58:40 +0000134
Michael Gottesmaneb396a62016-07-10 01:44:00 +0000135 add_clang_executable(${name} ${ARGN})
136
137 if (CLANG_BUILD_TOOLS)
Justin Bogner66b326b2016-11-07 23:46:05 +0000138 if(${name} IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR
139 NOT LLVM_DISTRIBUTION_COMPONENTS)
140 set(export_to_clangtargets EXPORT ClangTargets)
Justin Bogner5ca4d5f2016-11-08 05:02:33 +0000141 set_property(GLOBAL PROPERTY CLANG_HAS_EXPORTS True)
Justin Bogner66b326b2016-11-07 23:46:05 +0000142 endif()
143
Michael Gottesmaneb396a62016-07-10 01:44:00 +0000144 install(TARGETS ${name}
Justin Bogner66b326b2016-11-07 23:46:05 +0000145 ${export_to_clangtargets}
Michael Gottesmaneb396a62016-07-10 01:44:00 +0000146 RUNTIME DESTINATION bin
147 COMPONENT ${name})
148
149 if(NOT CMAKE_CONFIGURATION_TYPES)
150 add_custom_target(install-${name}
151 DEPENDS ${name}
152 COMMAND "${CMAKE_COMMAND}"
153 -DCMAKE_INSTALL_COMPONENT=${name}
154 -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
155 endif()
Michael Gottesman66cc2d52016-10-19 22:46:06 +0000156 set_property(GLOBAL APPEND PROPERTY CLANG_EXPORTS ${name})
Michael Gottesmanca589cc2016-07-09 21:58:40 +0000157 endif()
158endmacro()
159
160macro(add_clang_symlink name dest)
161 add_llvm_tool_symlink(${name} ${dest} ALWAYS_GENERATE)
162 # Always generate install targets
163 llvm_install_symlink(${name} ${dest} ALWAYS_GENERATE)
164endmacro()