59 lines
1.7 KiB
CMake
59 lines
1.7 KiB
CMake
if(NOT DEFINED OUTPUT_FILE OR OUTPUT_FILE STREQUAL "")
|
|
message(FATAL_ERROR "OUTPUT_FILE is required")
|
|
endif()
|
|
|
|
if(NOT DEFINED HEADER_LIST)
|
|
set(HEADER_LIST "")
|
|
endif()
|
|
|
|
# add_custom_command passes list args as an escaped string (\;). Normalize it.
|
|
string(REPLACE "\\;" ";" HEADER_LIST "${HEADER_LIST}")
|
|
|
|
set(_entries "")
|
|
set(_seen_names "")
|
|
set(_processed_headers "")
|
|
|
|
foreach(_header IN LISTS HEADER_LIST)
|
|
if(NOT EXISTS "${_header}")
|
|
continue()
|
|
endif()
|
|
|
|
list(APPEND _processed_headers "${_header}")
|
|
|
|
file(STRINGS "${_header}" _header_lines REGEX "^#[ \t]*define[ \t]+IDS_[A-Za-z0-9_]+[ \t]+[0-9]+([ \t].*)?$")
|
|
|
|
foreach(_line IN LISTS _header_lines)
|
|
string(REGEX REPLACE "^#[ \t]*define[ \t]+(IDS_[A-Za-z0-9_]+)[ \t]+([0-9]+).*$" "\\1;\\2" _parts "${_line}")
|
|
|
|
list(LENGTH _parts _part_count)
|
|
if(_part_count LESS 2)
|
|
continue()
|
|
endif()
|
|
|
|
list(GET _parts 0 _name)
|
|
list(FIND _seen_names "${_name}" _seen_index)
|
|
if(NOT _seen_index EQUAL -1)
|
|
continue()
|
|
endif()
|
|
|
|
list(APPEND _seen_names "${_name}")
|
|
string(APPEND _entries "#ifdef ${_name}\n")
|
|
string(APPEND _entries "case ${_name}: return L\"${_name}\";\n")
|
|
string(APPEND _entries "#endif\n")
|
|
endforeach()
|
|
endforeach()
|
|
|
|
list(LENGTH _seen_names _entry_count)
|
|
if(_entry_count EQUAL 0)
|
|
message(FATAL_ERROR "GenerateStringIdLookup.cmake found no IDS_ defines. HEADER_LIST='${HEADER_LIST}'")
|
|
endif()
|
|
|
|
get_filename_component(_output_dir "${OUTPUT_FILE}" DIRECTORY)
|
|
if(NOT _output_dir STREQUAL "")
|
|
file(MAKE_DIRECTORY "${_output_dir}")
|
|
endif()
|
|
|
|
file(WRITE "${OUTPUT_FILE}" "// Auto-generated by cmake/GenerateStringIdLookup.cmake.\n")
|
|
file(APPEND "${OUTPUT_FILE}" "// Do not edit manually.\n\n")
|
|
file(APPEND "${OUTPUT_FILE}" "${_entries}")
|