Index: llvm/cmake/modules/HandleLLVMOptions.cmake =================================================================== --- llvm/cmake/modules/HandleLLVMOptions.cmake +++ llvm/cmake/modules/HandleLLVMOptions.cmake @@ -145,6 +145,28 @@ set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-flat_namespace -Wl,-undefined -Wl,suppress") endif() +if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") + # RHEL7 has ar and ranlib being non-deterministic by default. The D flag forces determinism, + # however only GNU version of ar and ranlib (2.27) have this option. + # RHEL DTS7 is also affected by this, which uses GNU binutils 2.28 + execute_process(COMMAND ${CMAKE_AR} rD t.a + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} RESULT_VARIABLE AR_RESULT OUTPUT_VARIABLE RANLIB_OUTPUT) + if(${AR_RESULT} EQUAL 0) + execute_process(COMMAND ${CMAKE_RANLIB} -D t.a + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} RESULT_VARIABLE RANLIB_RESULT OUTPUT_VARIABLE RANLIB_OUTPUT) + if(${RANLIB_RESULT} EQUAL 0) + set(CMAKE_C_ARCHIVE_CREATE " Dqc ") + set(CMAKE_C_ARCHIVE_APPEND " Dq ") + set(CMAKE_C_ARCHIVE_FINISH " -D ") + + set(CMAKE_CXX_ARCHIVE_CREATE " Dqc ") + set(CMAKE_CXX_ARCHIVE_APPEND " Dq ") + set(CMAKE_CXX_ARCHIVE_FINISH " -D ") + endif() + file(REMOVE ${CMAKE_BINARY_DIR}/t.a) + endif() +endif() + if(${CMAKE_SYSTEM_NAME} MATCHES "AIX") if(NOT LLVM_BUILD_32_BITS) if (CMAKE_CXX_COMPILER_ID MATCHES "XL")