Skip to content

Commit

Permalink
win: Fix upperilm header generation
Browse files Browse the repository at this point in the history
clang-cl doesn't recognize "-P -E -x c" compiler arguments,
we should use MSVC version of them "/E /TC".

Seems clang-cl is not able to handle /P /E together
so I only left the necessary one.

Due to preprocessing upperilm.in, '#' will be represented in output.
It needs to add a new list filter which exclude those lines
which starts with '#'.

Fixes: #1192
  • Loading branch information
kaadam authored and bryanpkc committed Dec 21, 2021
1 parent 18a324a commit aae655a
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion tools/flang2/utils/upper/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,23 @@ add_executable(upperl
# FIXME: Preprocessing and sorting should be part of add_custom_command below.
get_property(cdefs DIRECTORY PROPERTY COMPILE_DEFINITIONS)
list(TRANSFORM cdefs PREPEND "-D")
execute_process(COMMAND "${CMAKE_C_COMPILER}" -E -P -x c ${cdefs} ${UTILS_UPPER_DIR}/upperilm.in

if (NOT MSVC OR "${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "GNU")
set(COMPILER_ARGUMENTS -E -P -x c)
else()
set(COMPILER_ARGUMENTS /E /TC)
endif()

execute_process(COMMAND "${CMAKE_C_COMPILER}" ${COMPILER_ARGUMENTS} ${cdefs} ${UTILS_UPPER_DIR}/upperilm.in
WORKING_DIRECTORY ${UTILS_UPPER_BIN_DIR}
RESULT_VARIABLE cpp_result
OUTPUT_VARIABLE cpp_output
ERROR_QUIET)
if(cpp_result EQUAL 0)
string(REPLACE "\n" ";" UPPERILM_H_CONTENTS ${cpp_output})
list(SORT UPPERILM_H_CONTENTS)
# Skip all lines which starts with '#'
list(FILTER UPPERILM_H_CONTENTS EXCLUDE REGEX "^#")
list(JOIN UPPERILM_H_CONTENTS "\n" UPPERILM_H_CONTENTS_SORTED)
file(WRITE ${UTILS_UPPER_BIN_DIR}/upperilm.sort "${UPPERILM_H_CONTENTS_SORTED}")
else()
Expand Down

0 comments on commit aae655a

Please sign in to comment.