Skip to content

Commit 05bcf83

Browse files
authored
[OpenMP][Build][Wasm][116552] Fixed build problem when compiling with Emscripten on Windows (llvm#116874)
1 parent 08e7609 commit 05bcf83

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

openmp/runtime/src/CMakeLists.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,22 @@ if(${LIBOMP_OMPT_SUPPORT})
2626
endif()
2727

2828
# Generate message catalog files: kmp_i18n_id.inc and kmp_i18n_default.inc
29+
set(LIBOMP_MESSAGE_CONVERTER_EXTRA_ARGS "")
30+
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Emscripten")
31+
# Required as Python doesn't inherit CMake's environment setup and uses the host system as the target system by default
32+
set(LIBOMP_MESSAGE_CONVERTER_EXTRA_ARGS ${LIBOMP_MESSAGE_CONVERTER_EXTRA_ARGS} --target-system-override=${CMAKE_SYSTEM_NAME})
33+
endif()
34+
2935
add_custom_command(
3036
OUTPUT kmp_i18n_id.inc
3137
COMMAND ${Python3_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/message-converter.py
32-
--enum=kmp_i18n_id.inc ${LIBOMP_SRC_DIR}/i18n/en_US.txt
38+
--enum=kmp_i18n_id.inc ${LIBOMP_MESSAGE_CONVERTER_EXTRA_ARGS} ${LIBOMP_SRC_DIR}/i18n/en_US.txt
3339
DEPENDS ${LIBOMP_SRC_DIR}/i18n/en_US.txt ${LIBOMP_TOOLS_DIR}/message-converter.py
3440
)
3541
add_custom_command(
3642
OUTPUT kmp_i18n_default.inc
3743
COMMAND ${Python3_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/message-converter.py
38-
--default=kmp_i18n_default.inc ${LIBOMP_SRC_DIR}/i18n/en_US.txt
44+
--default=kmp_i18n_default.inc ${LIBOMP_MESSAGE_CONVERTER_EXTRA_ARGS} ${LIBOMP_SRC_DIR}/i18n/en_US.txt
3945
DEPENDS ${LIBOMP_SRC_DIR}/i18n/en_US.txt ${LIBOMP_TOOLS_DIR}/message-converter.py
4046
)
4147

openmp/runtime/tools/message-converter.py

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,32 @@
1919
from libomputils import ScriptError, error
2020

2121

22+
class TargetPlatform:
23+
"""Convenience class for handling the target platform for configuration/compilation"""
24+
25+
system_override = None
26+
"""
27+
Target system name override by the user.
28+
It follows the conventions from https://docs.python.org/3/library/platform.html#platform.system
29+
"""
30+
31+
def set_system_override(override_system):
32+
"""
33+
Set a system override for the target.
34+
Please follow the style from https://docs.python.org/3/library/platform.html#platform.system
35+
"""
36+
TargetPlatform.system_override = override_system
37+
38+
def system():
39+
"""
40+
Target System name.
41+
It follows the conventions from https://docs.python.org/3/library/platform.html#platform.system
42+
"""
43+
if TargetPlatform.system_override is None:
44+
return platform.system()
45+
return TargetPlatform.system_override
46+
47+
2248
class ParseMessageDataError(ScriptError):
2349
"""Convenience class for parsing message data file errors"""
2450

@@ -55,7 +81,7 @@ def __init__(self, lineNumber, name, text):
5581
self.text = text
5682

5783
def toSrc(self):
58-
if platform.system() == "Windows":
84+
if TargetPlatform.system().casefold() == "Windows".casefold():
5985
return re.sub(r"%([0-9])\$(s|l?[du])", r"%\1!\2!", self.text)
6086
return str(self.text)
6187

@@ -363,6 +389,13 @@ def main():
363389
parser.add_argument(
364390
"--message", metavar="FILE", help="Generate message file named FILE"
365391
)
392+
parser.add_argument(
393+
"--target-system-override",
394+
metavar="TARGET_SYSTEM_NAME",
395+
help="Target System override.\n"
396+
"By default the target system is the host system\n"
397+
"See possible values at https://docs.python.org/3/library/platform.html#platform.system",
398+
)
366399
parser.add_argument("inputfile")
367400
commandArgs = parser.parse_args()
368401

@@ -371,14 +404,16 @@ def main():
371404
return
372405
data = MessageData.create(commandArgs.inputfile)
373406
prefix = commandArgs.prefix
407+
if commandArgs.target_system_override:
408+
TargetPlatform.set_system_override(commandArgs.target_system_override)
374409
if commandArgs.enum:
375410
generate_enum_file(commandArgs.enum, prefix, data)
376411
if commandArgs.default:
377412
generate_default_messages_file(commandArgs.default, prefix, data)
378413
if commandArgs.signature:
379414
generate_signature_file(commandArgs.signature, data)
380415
if commandArgs.message:
381-
if platform.system() == "Windows":
416+
if TargetPlatform.system().casefold() == "Windows".casefold():
382417
generate_message_file_windows(commandArgs.message, data)
383418
else:
384419
generate_message_file_unix(commandArgs.message, data)

0 commit comments

Comments
 (0)