1 # A rule for self contained header file targets.
2 # This rule merely copies the header file from the current source directory to
3 # the current binary directory.
9 function(add_header target_name)
10 cmake_parse_arguments(
12 "" # No optional arguments
13 "HDR" # Single value arguments
17 if(NOT ADD_HEADER_HDR)
18 message(FATAL_ERROR "'add_header' rules requires the HDR argument specifying a headef file.")
21 set(absolute_path ${CMAKE_CURRENT_SOURCE_DIR}/${ADD_HEADER_HDR})
22 file(RELATIVE_PATH relative_path ${LIBC_INCLUDE_SOURCE_DIR} ${absolute_path})
23 set(dest_file ${LIBC_INCLUDE_DIR}/${relative_path})
24 set(src_file ${CMAKE_CURRENT_SOURCE_DIR}/${ADD_HEADER_HDR})
28 COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src_file} ${dest_file}
32 get_fq_target_name(${target_name} fq_target_name)
38 if(ADD_HEADER_DEPENDS)
39 get_fq_deps_list(fq_deps_list ${ADD_HEADER_DEPENDS})
40 # Dependencies of a add_header target can only be another add_header target
41 # or an add_gen_header target.
42 foreach(dep IN LISTS fq_deps_list)
43 get_target_property(header_file ${dep} HEADER_FILE_PATH)
45 message(FATAL_ERROR "Invalid dependency '${dep}' for '${fq_target_name}'.")
49 ${fq_target_name} ${fq_deps_list}
53 set_target_properties(
56 HEADER_FILE_PATH ${dest_file}
57 DEPS "${fq_deps_list}"
59 endfunction(add_header)
61 # A rule for generated header file targets.
65 # DEF_FILE <.h.def file>
66 # GEN_HDR <generated header file name>
67 # PARAMS <list of name=value pairs>
68 # DATA_FILES <list input data files>
70 function(add_gen_header target_name)
71 cmake_parse_arguments(
73 "PUBLIC" # No optional arguments
74 "DEF_FILE;GEN_HDR" # Single value arguments
75 "PARAMS;DATA_FILES;DEPENDS" # Multi value arguments
78 get_fq_target_name(${target_name} fq_target_name)
79 if(NOT LLVM_LIBC_FULL_BUILD)
80 # We don't want to use generated headers if we are doing a non-full-build.
81 add_custom_target(${fq_target_name})
84 if(NOT ADD_GEN_HDR_DEF_FILE)
85 message(FATAL_ERROR "`add_gen_hdr` rule requires DEF_FILE to be specified.")
87 if(NOT ADD_GEN_HDR_GEN_HDR)
88 message(FATAL_ERROR "`add_gen_hdr` rule requires GEN_HDR to be specified.")
91 set(absolute_path ${CMAKE_CURRENT_SOURCE_DIR}/${ADD_GEN_HDR_GEN_HDR})
92 file(RELATIVE_PATH relative_path ${LIBC_INCLUDE_SOURCE_DIR} ${absolute_path})
93 set(out_file ${LIBC_INCLUDE_DIR}/${relative_path})
94 set(in_file ${CMAKE_CURRENT_SOURCE_DIR}/${ADD_GEN_HDR_DEF_FILE})
97 if(ADD_GEN_HDR_DATA_FILES)
98 foreach(data_file IN LISTS ADD_GEN_HDR_DATA_FILES)
99 list(APPEND fq_data_files "${CMAKE_CURRENT_SOURCE_DIR}/${data_file}")
100 endforeach(data_file)
103 set(replacement_params "")
104 if(ADD_GEN_HDR_PARAMS)
105 list(APPEND replacement_params "--args" ${ADD_GEN_HDR_PARAMS})
108 set(gen_hdr_script "${LIBC_BUILD_SCRIPTS_DIR}/gen_hdr.py")
110 file(GLOB td_includes ${LIBC_SOURCE_DIR}/spec/*.td)
112 set(ENTRYPOINT_NAME_LIST_ARG ${TARGET_ENTRYPOINT_NAME_LIST})
113 list(TRANSFORM ENTRYPOINT_NAME_LIST_ARG PREPEND "--e=")
116 set(hdrgen_exe ${LIBC_HDRGEN_EXE})
118 set(hdrgen_exe ${LIBC_TABLEGEN_EXE})
119 set(hdrgen_deps "${LIBC_TABLEGEN_EXE};${LIBC_TABLEGEN_TARGET}")
123 COMMAND ${hdrgen_exe} -o ${out_file} --header ${ADD_GEN_HDR_GEN_HDR}
124 --def ${in_file} ${replacement_params} -I ${LIBC_SOURCE_DIR}
125 ${ENTRYPOINT_NAME_LIST_ARG}
126 ${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/api.td
128 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
129 DEPENDS ${in_file} ${fq_data_files} ${td_includes}
130 ${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/api.td
134 if(LIBC_TARGET_ARCHITECTURE_IS_GPU)
135 file(MAKE_DIRECTORY ${LIBC_INCLUDE_DIR}/llvm-libc-decls)
136 set(decl_out_file ${LIBC_INCLUDE_DIR}/llvm-libc-decls/${relative_path})
138 OUTPUT ${decl_out_file}
139 COMMAND ${hdrgen_exe} -o ${decl_out_file}
140 --header ${ADD_GEN_HDR_GEN_HDR} --def ${in_file} --export-decls
141 ${replacement_params} -I ${LIBC_SOURCE_DIR} ${ENTRYPOINT_NAME_LIST_ARG}
142 ${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/api.td
144 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
145 DEPENDS ${in_file} ${fq_data_files} ${td_includes}
146 ${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/api.td
151 if(ADD_GEN_HDR_DEPENDS)
152 get_fq_deps_list(fq_deps_list ${ADD_GEN_HDR_DEPENDS})
153 # Dependencies of a add_header target can only be another add_gen_header target
154 # or an add_header target.
155 foreach(dep IN LISTS fq_deps_list)
156 get_target_property(header_file ${dep} HEADER_FILE_PATH)
158 message(FATAL_ERROR "Invalid dependency '${dep}' for '${fq_target_name}'.")
164 DEPENDS ${out_file} ${fq_deps_list} ${decl_out_file}
167 set_target_properties(
170 HEADER_FILE_PATH ${out_file}
171 DECLS_FILE_PATH "${decl_out_file}"
172 DEPS "${fq_deps_list}"
174 endfunction(add_gen_header)