append("/Zc:inline" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
- # Disable string literal const->non-const type conversion
- # "When specified, the compiler requires strict const-qualification
- # conformance for pointers initialized by using string literals."
- append("/Zc:strictStrings" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
-
- # Generate Intrinsic Functions
- append("/Oi" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
-
- # Enforce type conversion rules
- append("/Zc:rvalueCast" CMAKE_CXX_FLAGS)
+ if (NOT LLVM_ENABLE_TIMESTAMPS AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")
+ # clang-cl and cl by default produce non-deterministic binaries because
+ # link.exe /incremental requires a timestamp in the .obj file. clang-cl
+ # has the flag /Brepro to force deterministic binaries, so pass that when
+ # LLVM_ENABLE_TIMESTAMPS is turned off.
+ # This checks CMAKE_CXX_COMPILER_ID in addition to check_cxx_compiler_flag()
+ # because cl.exe does not emit an error on flags it doesn't understand,
+ # letting check_cxx_compiler_flag() claim it understands all flags.
+ check_cxx_compiler_flag("/Brepro" SUPPORTS_BREPRO)
+ append_if(SUPPORTS_BREPRO "/Brepro" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
+
+ if (SUPPORTS_BREPRO)
+ # Check if /INCREMENTAL is passed to the linker and complain that it
+ # won't work with /Brepro.
+ string(TOUPPER "${CMAKE_EXE_LINKER_FLAGS}" upper_exe_flags)
+ string(TOUPPER "${CMAKE_MODULE_LINKER_FLAGS}" upper_module_flags)
+ string(TOUPPER "${CMAKE_SHARED_LINKER_FLAGS}" upper_shared_flags)
+
+ string(FIND "${upper_exe_flags}" "/INCREMENTAL" exe_index)
+ string(FIND "${upper_module_flags}" "/INCREMENTAL" module_index)
+ string(FIND "${upper_shared_flags}" "/INCREMENTAL" shared_index)
+
+ if (${exe_index} GREATER -1 OR
+ ${module_index} GREATER -1 OR
+ ${shared_index} GREATER -1)
+ message(FATAL_ERROR "LLVM_ENABLE_TIMESTAMPS not compatible with /INCREMENTAL linking")
+ endif()
+ endif()
+ endif()
# Disable sized deallocation if the flag is supported. MSVC fails to compile
# the operator new overload in User otherwise.