detect llvm toolchain utilities #392
Use `clang -print-prog-path=<tool>` to find the locations of llvm toolchain utilities such as `llvm-ranlib` and set the appropriate cmake variables to the resultant paths. Signed-off-by: Rafael Kitover <rkitover@gmail.com>
This commit is contained in:
parent
c714ff825a
commit
3da07f4083
|
@ -359,7 +359,11 @@ endif()
|
||||||
include(ProcessorCount)
|
include(ProcessorCount)
|
||||||
ProcessorCount(num_cpus)
|
ProcessorCount(num_cpus)
|
||||||
|
|
||||||
# Compiler flags
|
# Compiler stuff
|
||||||
|
|
||||||
|
if(CMAKE_C_COMPILER_ID STREQUAL Clang AND CMAKE_CXX_COMPILER_ID STREQUAL Clang)
|
||||||
|
include(LLVMToolchain)
|
||||||
|
endif()
|
||||||
|
|
||||||
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL Clang)
|
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL Clang)
|
||||||
set(LTO_FLAGS "")
|
set(LTO_FLAGS "")
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
function(use_llvm_toolchain)
|
||||||
|
if(CMAKE_C_COMPILER_ID STREQUAL Clang)
|
||||||
|
set(compiler "${CMAKE_C_COMPILER}")
|
||||||
|
elseif(CMAKE_CXX_COMPILER_ID STREQUAL Clang)
|
||||||
|
set(compiler "${CMAKE_CXX_COMPILER}")
|
||||||
|
else()
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
foreach(tool ar ranlib ld nm objdump as)
|
||||||
|
execute_process(
|
||||||
|
COMMAND "${compiler}" -print-prog-name=llvm-${tool}
|
||||||
|
OUTPUT_VARIABLE prog_path
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||||
|
)
|
||||||
|
|
||||||
|
if(prog_path MATCHES "^/")
|
||||||
|
if(tool STREQUAL ld)
|
||||||
|
set(tool linker)
|
||||||
|
elseif(tool STREQUAL as)
|
||||||
|
set(tool asm_compiler)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
string(TOUPPER ${tool} utool)
|
||||||
|
|
||||||
|
set(CMAKE_${utool} "${prog_path}" PARENT_SCOPE)
|
||||||
|
set(CMAKE_${utool} "${prog_path}" CACHE FILEPATH "${tool}" FORCE)
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
use_llvm_toolchain()
|
Loading…
Reference in New Issue