TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags
[wireshark-sm.git] / cmake / modules / UseAsn2Wrs.cmake
blobad65a9d92bdab969c73ed1006db4fdc3f59daf1d
1 # - Convert ASN.1 file into C source and header files that can be used to create a wireshark dissector
3 #  A2W_OUTPUT_DIR   - directory where the generated packet-${PROTOCOL_NAME}.c is
4 #                     saved. The default location is meant for the Wireshark
5 #                     source tree. For external dissectors, set it to the
6 #                     absolute path (e.g. "${CMAKE_CURRENT_SOURCE_DIR}").
8 function(ASN2WRS)
9         if(NOT PROTO_OPT)
10                 set(PROTO_OPT -p ${PROTOCOL_NAME})
11         elseif(PROTO_OPT STREQUAL "_EMPTY_")
12                 set(PROTO_OPT)
13         endif()
15         if(NOT A2W_OUTPUT_DIR)
16                 set(A2W_OUTPUT_DIR "${CMAKE_SOURCE_DIR}/epan/dissectors")
17         endif()
19         set(DISSECTOR "${A2W_OUTPUT_DIR}/packet-${PROTOCOL_NAME}.c")
21         # Besides the file dependency (for timestamp comparison), add a target such
22         # that other directories can request it to be built (ordering dependency).
23         foreach(_v EXTRA_CNF EXPORT_DEPENDS)
24                 set(${_v}_targets)
25                 foreach(entry IN LISTS ${_v})
26                         string(REGEX MATCH "[^/]+-exp\\.cnf$" _exp_cnf_filename "${entry}")
27                         if(_exp_cnf_filename)
28                                 list(APPEND ${_v}_targets generate-${_exp_cnf_filename})
29                         endif()
30                 endforeach()
31         endforeach()
33         if(NOT ENABLE_DEBUG_A2W)
34                 set(A2W_FLAGS ${A2W_FLAGS} -q -L)
35         endif()
37         # Creates a dissector in the source directory and store the timestamp.
38         add_custom_command(
39                 OUTPUT packet-${PROTOCOL_NAME}-stamp
40                 COMMAND "${Python3_EXECUTABLE}"
41                         ${CMAKE_SOURCE_DIR}/tools/asn2wrs.py
42                         ${A2W_FLAGS}
43                         ${PROTO_OPT}
44                         -c "${CMAKE_CURRENT_SOURCE_DIR}/${PROTOCOL_NAME}.cnf"
45                         -s "${CMAKE_CURRENT_SOURCE_DIR}/packet-${PROTOCOL_NAME}-template"
46                         -D "${CMAKE_CURRENT_SOURCE_DIR}"
47                         -O "${A2W_OUTPUT_DIR}"
48                         ${EXT_ASN_FILE_LIST} ${ASN_FILE_LIST} ${EXT_ASN_FILE_LIST_LATE}
49                 COMMAND
50                         "${Python3_EXECUTABLE}" -c
51                                 "import shutil, sys; x,s,d=sys.argv; open(d, 'w'); shutil.copystat(s, d)"
52                                 "${A2W_OUTPUT_DIR}/packet-${PROTOCOL_NAME}.c"
53                                 packet-${PROTOCOL_NAME}-stamp
54                 DEPENDS
55                         ${CMAKE_SOURCE_DIR}/tools/asn2wrs.py
56                         ${SRC_FILES}
57                         ${EXTRA_CNF_targets}
58                         ${EXTRA_CNF}
59                 VERBATIM
60         )
62         add_custom_target(generate_dissector-${PROTOCOL_NAME} ALL
63                 DEPENDS packet-${PROTOCOL_NAME}-stamp
64         )
66         foreach(_asn2wrs_export_file IN LISTS EXPORT_FILES)
67                 add_custom_command(
68                         OUTPUT ${_asn2wrs_export_file}
69                         COMMAND "${Python3_EXECUTABLE}"
70                                 ${CMAKE_SOURCE_DIR}/tools/asn2wrs.py
71                                 -E
72                                 ${A2W_FLAGS}
73                                 ${PROTO_OPT}
74                                 -c "${CMAKE_CURRENT_SOURCE_DIR}/${PROTOCOL_NAME}.cnf"
75                                 -D "${CMAKE_CURRENT_SOURCE_DIR}"
76                                 ${EXT_ASN_FILE_LIST} ${ASN_FILE_LIST} ${EXT_ASN_FILE_LIST_LATE}
77                         DEPENDS
78                                 ${CMAKE_SOURCE_DIR}/tools/asn2wrs.py
79                                 ${SRC_FILES}
80                                 ${EXPORT_DEPENDS_targets}
81                                 ${EXPORT_DEPENDS}
82                 )
83                 # This target enables other dissectors to trigger the -exp cnf build
84                 add_custom_target(generate-${_asn2wrs_export_file}
85                         DEPENDS ${_asn2wrs_export_file}
86                 )
87         endforeach()
89 endfunction()