aboutsummaryrefslogtreecommitdiff
path: root/cmake/Modules/CompilerRTCompile.cmake
diff options
context:
space:
mode:
Diffstat (limited to 'cmake/Modules/CompilerRTCompile.cmake')
-rw-r--r--cmake/Modules/CompilerRTCompile.cmake38
1 files changed, 30 insertions, 8 deletions
diff --git a/cmake/Modules/CompilerRTCompile.cmake b/cmake/Modules/CompilerRTCompile.cmake
index de73ccfc5cb8..b2e62dd0bac6 100644
--- a/cmake/Modules/CompilerRTCompile.cmake
+++ b/cmake/Modules/CompilerRTCompile.cmake
@@ -1,4 +1,28 @@
-include(LLVMParseArguments)
+# On Windows, CMAKE_*_FLAGS are built for MSVC but we use the GCC clang.exe,
+# which uses completely different flags. Translate some common flag types, and
+# drop the rest.
+function(translate_msvc_cflags out_flags msvc_flags)
+ # Insert an empty string in the list to simplify processing.
+ set(msvc_flags ";${msvc_flags}")
+
+ # Canonicalize /flag to -flag.
+ string(REPLACE ";/" ";-" msvc_flags "${msvc_flags}")
+
+ # Make space separated -D and -U flags into joined flags.
+ string(REGEX REPLACE ";-\([DU]\);" ";-\\1" msvc_flags "${msvc_flags}")
+
+ set(clang_flags "")
+ foreach(flag ${msvc_flags})
+ if ("${flag}" MATCHES "^-[DU]")
+ # Pass through basic command line macro definitions (-DNDEBUG).
+ list(APPEND clang_flags "${flag}")
+ elseif ("${flag}" MATCHES "^-O[2x]")
+ # Canonicalize normal optimization flags to -O2.
+ list(APPEND clang_flags "-O2")
+ endif()
+ endforeach()
+ set(${out_flags} "${clang_flags}" PARENT_SCOPE)
+endfunction()
# Compile a source into an object file with COMPILER_RT_TEST_COMPILER using
# a provided compile flags and dependenices.
@@ -6,7 +30,7 @@ include(LLVMParseArguments)
# CFLAGS <list of compile flags>
# DEPS <list of dependencies>)
macro(clang_compile object_file source)
- parse_arguments(SOURCE "CFLAGS;DEPS" "" ${ARGN})
+ cmake_parse_arguments(SOURCE "" "" "CFLAGS;DEPS" ${ARGN})
get_filename_component(source_rpath ${source} REALPATH)
if(NOT COMPILER_RT_STANDALONE_BUILD)
list(APPEND SOURCE_DEPS clang compiler-rt-headers)
@@ -20,13 +44,11 @@ macro(clang_compile object_file source)
else()
string(REPLACE " " ";" global_flags "${CMAKE_C_FLAGS}")
endif()
- # On Windows, CMAKE_*_FLAGS are built for MSVC but we use the GCC clang.exe
- # which doesn't support flags starting with "/smth". Replace those with
- # "-smth" equivalents.
- if(MSVC)
- string(REGEX REPLACE "^/" "-" global_flags "${global_flags}")
- string(REPLACE ";/" ";-" global_flags "${global_flags}")
+
+ if (MSVC)
+ translate_msvc_cflags(global_flags "${global_flags}")
endif()
+
# Ignore unknown warnings. CMAKE_CXX_FLAGS may contain GCC-specific options
# which are not supported by Clang.
list(APPEND global_flags -Wno-unknown-warning-option)