mdbx-cmake: fix/rework LTO-support for clang.

Change-Id: I04340e98c92b4006d78fcd58a657841287271a70
This commit is contained in:
Leonid Yuriev 2020-05-06 18:25:11 +03:00
parent 1cab079d6f
commit b67f2da821

View File

@ -309,52 +309,65 @@ if(CMAKE_COMPILER_IS_CLANG)
execute_process(COMMAND ${CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER} -print-search-dirs
OUTPUT_VARIABLE clang_search_dirs RESULT_VARIABLE clang_probe_result ERROR_QUIET)
unset(clang_bindir)
unset(clang_libdir)
unset(clang_bindirs)
unset(clang_libdirs)
if(clang_probe_result EQUAL 0)
string(REGEX MATCH "^(.*programs: =)([^:]*:)*([^:]+/llvm[-.0-9]+/bin[^:]*)(:[^:]*)*(\n.+)$" clang_bindir_valid ${clang_search_dirs})
if(clang_bindir_valid)
string(REGEX REPLACE "^(.*programs: =)([^:]*:)*([^:]+/llvm[-.0-9]+/bin[^:]*)(:[^:]*)*(\n.+)$" "\\3" clang_bindir ${clang_search_dirs})
if(CMAKE_SYSTEM_NAME STREQUAL "WINDOWS")
set(clang_libdir ${clang_bindir})
else()
get_filename_component(clang_libdir "${clang_bindir}/../lib" REALPATH)
endif()
string(REGEX MATCH "(^|\n.*)(.*programs: =)([^\n]+)((\n.*)|$)" regexp_valid ${clang_search_dirs})
if(regexp_valid)
string(REGEX REPLACE "(^|\n.*)(.*programs: =)([^\n]+)((\n.*)|$)" "\\3" list ${clang_search_dirs})
string(REPLACE ":" ";" list "${list}")
#set(clang_bindirs "")
foreach(dir IN LISTS list)
get_filename_component(dir "${dir}" REALPATH)
list(APPEND clang_bindirs "${dir}")
endforeach()
list(REMOVE_DUPLICATES clang_bindirs)
endif()
string(REGEX MATCH "(^|\n.*)(.*libraries: =)([^\n]+)((\n.*)|$)" regexp_valid ${clang_search_dirs})
if(regexp_valid)
string(REGEX REPLACE "(^|\n.*)(.*libraries: =)([^\n]+)((\n.*)|$)" "\\3" list ${clang_search_dirs})
string(REPLACE ":" ";" list "${list}")
#set(clang_libdirs "")
foreach(dir IN LISTS list)
get_filename_component(dir "${dir}" REALPATH)
list(APPEND clang_libdirs "${dir}")
endforeach()
list(REMOVE_DUPLICATES clang_libdirs)
endif()
else()
get_filename_component(clang_bindir ${CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER} DIRECTORY)
get_filename_component(clang_bindirs ${CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER} DIRECTORY)
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
set(clang_libdir ${clang_bindir})
set(clang_libdirs ${clang_bindirs})
else()
get_filename_component(clang_libdir "${clang_bindir}/../lib" REALPATH)
get_filename_component(clang_libdirs "${CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER}/../lib" REALPATH)
endif()
endif()
if(clang_bindir AND clang_libdir)
message(STATUS "Found CLANG/LLVM directories: ${clang_bindir}, ${clang_libdir}")
if(clang_bindirs AND clang_libdirs)
message(STATUS "Found CLANG/LLVM directories: ${clang_bindirs}, ${clang_libdirs}")
else()
message(STATUS "Could NOT find CLANG/LLVM directories (bin and/or lib).")
endif()
if(NOT CMAKE_CLANG_LD AND clang_bindir)
find_program(CMAKE_CLANG_LD NAMES lld-link ld.lld ld64.lld lld-link llvm-link link llvm-ld ld PATHS ${clang_bindir} NO_DEFAULT_PATH)
if(NOT CMAKE_CLANG_LD AND clang_bindirs)
find_program(CMAKE_CLANG_LD NAMES lld-link ld.lld ld64.lld lld-link llvm-link link llvm-ld ld PATHS ${clang_bindirs} NO_DEFAULT_PATH)
endif()
if(NOT CMAKE_CLANG_AR AND clang_bindir)
find_program(CMAKE_CLANG_AR NAMES llvm-ar ar PATHS ${clang_bindir} NO_DEFAULT_PATH)
if(NOT CMAKE_CLANG_AR AND clang_bindirs)
find_program(CMAKE_CLANG_AR NAMES llvm-ar ar PATHS ${clang_bindirs} NO_DEFAULT_PATH)
endif()
if(NOT CMAKE_CLANG_NM AND clang_bindir)
find_program(CMAKE_CLANG_NM NAMES llvm-nm nm PATHS ${clang_bindir} NO_DEFAULT_PATH)
if(NOT CMAKE_CLANG_NM AND clang_bindirs)
find_program(CMAKE_CLANG_NM NAMES llvm-nm nm PATHS ${clang_bindirs} NO_DEFAULT_PATH)
endif()
if(NOT CMAKE_CLANG_RANLIB AND clang_bindir)
find_program(CMAKE_CLANG_RANLIB NAMES llvm-ranlib ranlib PATHS ${clang_bindir} NO_DEFAULT_PATH)
if(NOT CMAKE_CLANG_RANLIB AND clang_bindirs)
find_program(CMAKE_CLANG_RANLIB NAMES llvm-ranlib ranlib PATHS ${clang_bindirs} NO_DEFAULT_PATH)
endif()
set(clang_lto_plugin_name "LLVMgold${CMAKE_SHARED_LIBRARY_SUFFIX}")
if(NOT CMAKE_LD_GOLD AND clang_bindir)
find_program(CMAKE_LD_GOLD NAMES ld.gold PATHS)
if(NOT CMAKE_LD_GOLD AND clang_bindirs)
find_program(CMAKE_LD_GOLD NAMES ld.gold PATHS ${clang_bindirs})
endif()
if(NOT CLANG_LTO_PLUGIN AND clang_libdir)
find_file(CLANG_LTO_PLUGIN ${clang_lto_plugin_name} PATH ${clang_libdir} NO_DEFAULT_PATH)
if(NOT CLANG_LTO_PLUGIN AND clang_libdirs)
find_file(CLANG_LTO_PLUGIN ${clang_lto_plugin_name} PATHS ${clang_libdirs} NO_DEFAULT_PATH)
endif()
if(CLANG_LTO_PLUGIN)
message(STATUS "Found CLANG/LLVM's plugin for LTO: ${CLANG_LTO_PLUGIN}")