diff --git a/icu4c/source/common/unicode/platform.h b/icu4c/source/common/unicode/platform.h index 7aca76c67db8..d0d87202f36a 100644 --- a/icu4c/source/common/unicode/platform.h +++ b/icu4c/source/common/unicode/platform.h @@ -217,6 +217,16 @@ # define U_REAL_MSVC #endif +/** + * \def U_CLANG_CL + * Defined if the compiler is Clang compatible with MSVC (Clang on Windows). + * Otherwise undefined. + * @internal + */ +#if (defined(_MSC_VER) && defined(__clang__) && __clang__) +# define U_CLANG_CL +#endif + /** * \def CYGWINMSVC * Defined if this is Windows with Cygwin, but using MSVC rather than gcc. @@ -235,7 +245,7 @@ /** * \def U_PLATFORM_USES_ONLY_WIN32_API * Defines whether the platform uses only the Win32 API. - * Set to 1 for Windows/MSVC and MinGW but not Cygwin. + * Set to 1 for Windows/MSVC, ClangCL and MinGW but not Cygwin. * @internal */ #ifdef U_PLATFORM_USES_ONLY_WIN32_API @@ -250,7 +260,7 @@ /** * \def U_PLATFORM_HAS_WIN32_API * Defines whether the Win32 API is available on the platform. - * Set to 1 for Windows/MSVC, MinGW and Cygwin. + * Set to 1 for Windows/MSVC, ClangCL, MinGW and Cygwin. * @internal */ #ifdef U_PLATFORM_HAS_WIN32_API diff --git a/icu4c/source/tools/genccode/genccode.c b/icu4c/source/tools/genccode/genccode.c index 388317a0634d..f79c2b51cd3d 100644 --- a/icu4c/source/tools/genccode/genccode.c +++ b/icu4c/source/tools/genccode/genccode.c @@ -70,7 +70,9 @@ enum { #ifdef CAN_GENERATE_OBJECTS kOptObject, kOptMatchArch, +#ifdef U_CLANG_CL kOptCpuArch, +#endif kOptSkipDllExport, #endif kOptFilename, @@ -87,7 +89,9 @@ static UOption options[]={ #ifdef CAN_GENERATE_OBJECTS /*6*/UOPTION_DEF("object", 'o', UOPT_NO_ARG), UOPTION_DEF("match-arch", 'm', UOPT_REQUIRES_ARG), +#ifdef U_CLANG_CL UOPTION_DEF("cpu-arch", 'c', UOPT_REQUIRES_ARG), +#endif UOPTION_DEF("skip-dll-export", '\0', UOPT_NO_ARG), #endif UOPTION_DEF("filename", 'f', UOPT_REQUIRES_ARG), @@ -133,7 +137,9 @@ main(int argc, char* argv[]) { "\t-o or --object write a .obj file instead of .c\n" "\t-m or --match-arch file.o match the architecture (CPU, 32/64 bits) of the specified .o\n" "\t ELF format defaults to i386. Windows defaults to the native platform.\n" +#ifdef U_CLANG_CL "\t-c or --cpu-arch Specify a CPU architecture for which to write a .obj file for ClangCL on Windows\n" +#endif "\t--skip-dll-export Don't export the ICU data entry point symbol (for use when statically linking)\n"); #endif fprintf(stderr, @@ -199,7 +205,11 @@ main(int argc, char* argv[]) { writeObjectCode(filename, options[kOptDestDir].value, options[kOptEntryPoint].doesOccur ? options[kOptEntryPoint].value : NULL, options[kOptMatchArch].doesOccur ? options[kOptMatchArch].value : NULL, +#ifdef U_CLANG_CL options[kOptCpuArch].doesOccur ? options[kOptCpuArch].value : NULL, +#else + NULL, +#endif options[kOptFilename].doesOccur ? options[kOptFilename].value : NULL, NULL, 0, diff --git a/icu4c/source/tools/toolutil/pkg_genc.cpp b/icu4c/source/tools/toolutil/pkg_genc.cpp index 438552ab32ea..69bd5d30254c 100644 --- a/icu4c/source/tools/toolutil/pkg_genc.cpp +++ b/icu4c/source/tools/toolutil/pkg_genc.cpp @@ -858,14 +858,17 @@ getArchitecture( // this would potentially be problematic when cross-compiling as this code // would most likely be ran on host machine to generate the .obj file for // the target architecture. -# if defined(__clang__) +# ifdef U_CLANG_CL if (strcmp(optCpuArch, "x64") == 0) { *pCPU = IMAGE_FILE_MACHINE_AMD64; + } else if (strcmp(optCpuArch, "x86") == 0) { + *pCPU = IMAGE_FILE_MACHINE_I386; } else if (strcmp(optCpuArch, "arm64") == 0) { *pCPU = IMAGE_FILE_MACHINE_ARM64; } else { // This should never happen. - *pCPU = IMAGE_FILE_MACHINE_UNKNOWN; + fprintf(stderr, "genccode: unable to process %s CPU architecture\n", optCpuArch); + exit(U_ILLEGAL_ARGUMENT_ERROR); } # else *pCPU = IMAGE_FILE_MACHINE_UNKNOWN;