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(dest_file ${CMAKE_CURRENT_BINARY_DIR}/${ADD_HEADER_HDR})
22 set(src_file ${CMAKE_CURRENT_SOURCE_DIR}/${ADD_HEADER_HDR})
26 COMMAND cp ${src_file} ${dest_file}
30 get_fq_target_name(${target_name} fq_target_name)
36 if(ADD_HEADER_DEPENDS)
37 get_fq_deps_list(fq_deps_list ${ADD_HEADER_DEPENDS})
39 ${fq_target_name} ${fq_deps_list}
42 endfunction(add_header)
44 # A rule for generated header file targets.
48 # DEF_FILE <.h.def file>
49 # GEN_HDR <generated header file name>
50 # PARAMS <list of name=value pairs>
51 # DATA_FILES <list input data files>
53 function(add_gen_header target_name)
54 cmake_parse_arguments(
56 "" # No optional arguments
57 "DEF_FILE;GEN_HDR" # Single value arguments
58 "PARAMS;DATA_FILES;DEPENDS" # Multi value arguments
61 if(NOT ADD_GEN_HDR_DEF_FILE)
62 message(FATAL_ERROR "`add_gen_hdr` rule requires DEF_FILE to be specified.")
64 if(NOT ADD_GEN_HDR_GEN_HDR)
65 message(FATAL_ERROR "`add_gen_hdr` rule requires GEN_HDR to be specified.")
68 set(out_file ${CMAKE_CURRENT_BINARY_DIR}/${ADD_GEN_HDR_GEN_HDR})
69 set(in_file ${CMAKE_CURRENT_SOURCE_DIR}/${ADD_GEN_HDR_DEF_FILE})
72 if(ADD_GEN_HDR_DATA_FILES)
73 foreach(data_file IN LISTS ADD_GEN_HDR_DATA_FILES)
74 list(APPEND fq_data_files "${CMAKE_CURRENT_SOURCE_DIR}/${data_file}")
78 set(replacement_params "")
79 if(ADD_GEN_HDR_PARAMS)
80 list(APPEND replacement_params "--args" ${ADD_GEN_HDR_PARAMS})
83 set(gen_hdr_script "${LIBC_BUILD_SCRIPTS_DIR}/gen_hdr.py")
85 file(GLOB td_includes ${LIBC_SOURCE_DIR}/spec/*.td)
89 COMMAND $<TARGET_FILE:libc-hdrgen> -o ${out_file} --header ${ADD_GEN_HDR_GEN_HDR}
90 --def ${in_file} ${replacement_params} -I ${LIBC_SOURCE_DIR}
91 ${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/api.td
93 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
94 DEPENDS ${in_file} ${fq_data_files} ${td_includes}
95 ${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/api.td libc-hdrgen
98 get_fq_target_name(${target_name} fq_target_name)
99 if(ADD_GEN_HDR_DEPENDS)
100 get_fq_deps_list(fq_deps_list ${ADD_GEN_HDR_DEPENDS})
104 DEPENDS ${out_file} ${fq_deps_list}
106 endfunction(add_gen_header)