Skip to content

Commit ee933ef

Browse files
authored
cmake: Check if C macros are correctly parse when building module info (#3191)
The macro **THIS_MODULE_KEYS** could be empty, but the other 4 macros must be non-empty: - THIS_MODULE_CLASSIC_NAME - THIS_MODULE_MODERN_NAME - THIS_MODULE_LIB - THIS_MODULE_PURPOSE If any of the 4 macros are not given, given an empty string, or incorrectly parsed by our regex, the CMake script will report warnings like: ``` CMake Warning at /Users/seisman/Gits/gmt/gmt/cmake/modules/GmtGenExtraHeaders.cmake:111 (message): THIS_MODULE_PURPOSE is empty in seis/pssac.c Call Stack (most recent call first): /Users/seisman/Gits/gmt/gmt/cmake/modules/GmtGenExtraHeaders.cmake:130 (gen_gmt_moduleinfo_h) ``` Address #3180.
1 parent 95f5c4a commit ee933ef

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

cmake/modules/GmtGenExtraHeaders.cmake

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,34 @@ macro (gen_gmt_moduleinfo_h output_header_file)
8686
set (_moduleinfo)
8787
foreach (_prog_src ${ARGN})
8888
file (READ ${GMT_SRC}/src/${_prog_src} _src_content)
89+
8990
string (REGEX MATCH "#define[ \t]*THIS_MODULE_CLASSIC_NAME[ \t]*\"([^\n]*)\"[ \t]*\n" _this_module_classic_name ${_src_content})
9091
set (_this_module_classic_name ${CMAKE_MATCH_1})
92+
if ("${_this_module_classic_name}" STREQUAL "")
93+
message (WARNING "THIS_MODULE_CLASSIC_NAME is empty in ${_prog_src}")
94+
endif ("${_this_module_classic_name}" STREQUAL "")
95+
9196
string (REGEX MATCH "#define[ \t]*THIS_MODULE_MODERN_NAME[ \t]*\"([^\n]*)\"[ \t]*\n" _this_module_modern_name ${_src_content})
9297
set (_this_module_modern_name ${CMAKE_MATCH_1})
98+
if ("${_this_module_modern_name}" STREQUAL "")
99+
message (WARNING "THIS_MODULE_MODERN_NAME is empty in ${_prog_src}")
100+
endif ("${_this_module_modern_name}" STREQUAL "")
101+
93102
string (REGEX MATCH "#define[ \t]*THIS_MODULE_LIB[ \t]*\"([^\n]*)\"[ \t]*\n" _this_module_lib ${_src_content})
94103
set (_this_module_lib ${CMAKE_MATCH_1})
104+
if ("${_this_module_lib}" STREQUAL "")
105+
message (WARNING "THIS_MODULE_LIB is empty in ${_prog_src}")
106+
endif ("${_this_module_lib}" STREQUAL "")
107+
95108
string (REGEX MATCH "#define[ \t]*THIS_MODULE_PURPOSE[ \t]*\"([^\n]*)\"[ \t]*\n" _this_module_purpose ${_src_content})
96109
set (_this_module_purpose ${CMAKE_MATCH_1})
110+
if ("${_this_module_purpose}" STREQUAL "")
111+
message (WARNING "THIS_MODULE_PURPOSE is empty in ${_prog_src}")
112+
endif ("${_this_module_purpose}" STREQUAL "")
113+
97114
string (REGEX MATCH "#define[ \t]*THIS_MODULE_KEYS[ \t]*\"([^\n]*)\"[ \t]*\n" _this_module_keys ${_src_content})
98115
set (_this_module_keys ${CMAKE_MATCH_1})
116+
99117
list (APPEND _moduleinfo "\t{\"${_this_module_modern_name}\", \"${_this_module_classic_name}\", \"${_this_module_lib}\", \"${_this_module_purpose}\", \"${_this_module_keys}\"},")
100118
endforeach (_prog_src ${ARGN})
101119
list (JOIN _moduleinfo "\n" _moduleinfo)

0 commit comments

Comments
 (0)