From cf82300a63d476f897c2cf6176378dc870be4282 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 27 May 2021 09:43:57 -0400 Subject: BinUtils: Clarify search logic and make it more consistent Consistently consider more-specific names before less-specific names. --- Modules/CMakeFindBinUtils.cmake | 75 ++++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 34 deletions(-) diff --git a/Modules/CMakeFindBinUtils.cmake b/Modules/CMakeFindBinUtils.cmake index 4ce45af..bfa9491 100644 --- a/Modules/CMakeFindBinUtils.cmake +++ b/Modules/CMakeFindBinUtils.cmake @@ -70,14 +70,17 @@ if(("x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_SIMULATE_ID}" STREQUAL "xMSVC" AND OR (CMAKE_GENERATOR MATCHES "Visual Studio" AND NOT CMAKE_VS_PLATFORM_NAME STREQUAL "Tegra-Android")) + # Start with the canonical names. set(_CMAKE_LINKER_NAMES "link") set(_CMAKE_AR_NAMES "lib") set(_CMAKE_MT_NAMES "mt") + + # Prepend toolchain-specific names. if("x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ID}" STREQUAL "xClang") set(_CMAKE_NM_NAMES "llvm-nm" "nm") - list(APPEND _CMAKE_AR_NAMES "lib" "llvm-lib") - list(APPEND _CMAKE_MT_NAMES "mt" "llvm-mt") - list(APPEND _CMAKE_LINKER_NAMES "lld-link") + list(PREPEND _CMAKE_AR_NAMES "llvm-lib") + list(PREPEND _CMAKE_MT_NAMES "llvm-mt") + list(PREPEND _CMAKE_LINKER_NAMES "lld-link") list(APPEND _CMAKE_TOOL_VARS NM) endif() @@ -92,50 +95,54 @@ else() set(_CMAKE_TOOLCHAIN_LOCATION ${_CMAKE_TOOLCHAIN_LOCATION} ${CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN}/bin) endif() + # Start with the canonical names. + set(_CMAKE_AR_NAMES "ar") + set(_CMAKE_RANLIB_NAMES "ranlib") + set(_CMAKE_STRIP_NAMES "strip") + set(_CMAKE_LINKER_NAMES "ld") + set(_CMAKE_NM_NAMES "nm") + set(_CMAKE_OBJDUMP_NAMES "objdump") + set(_CMAKE_OBJCOPY_NAMES "objcopy") + set(_CMAKE_READELF_NAMES "readelf") + set(_CMAKE_DLLTOOL_NAMES "dlltool") + set(_CMAKE_ADDR2LINE_NAMES "addr2line") + + # Prepend toolchain-specific names. if("${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ID}" STREQUAL Clang) if("x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_SIMULATE_ID}" STREQUAL "xMSVC") set(_CMAKE_LINKER_NAMES "lld-link") else() set(_CMAKE_LINKER_NAMES "ld.lld") endif() - list(APPEND _CMAKE_AR_NAMES "llvm-ar") - list(APPEND _CMAKE_RANLIB_NAMES "llvm-ranlib") - list(APPEND _CMAKE_STRIP_NAMES "llvm-strip") - list(APPEND _CMAKE_NM_NAMES "llvm-nm") - list(APPEND _CMAKE_OBJDUMP_NAMES "llvm-objdump") - list(APPEND _CMAKE_OBJCOPY_NAMES "llvm-objcopy") - list(APPEND _CMAKE_READELF_NAMES "llvm-readelf") - list(APPEND _CMAKE_DLLTOOL_NAMES "llvm-dlltool") - list(APPEND _CMAKE_ADDR2LINE_NAMES "llvm-addr2line") + list(PREPEND _CMAKE_AR_NAMES "llvm-ar") + list(PREPEND _CMAKE_RANLIB_NAMES "llvm-ranlib") + list(PREPEND _CMAKE_STRIP_NAMES "llvm-strip") + list(PREPEND _CMAKE_NM_NAMES "llvm-nm") + list(PREPEND _CMAKE_OBJDUMP_NAMES "llvm-objdump") + list(PREPEND _CMAKE_OBJCOPY_NAMES "llvm-objcopy") + list(PREPEND _CMAKE_READELF_NAMES "llvm-readelf") + list(PREPEND _CMAKE_DLLTOOL_NAMES "llvm-dlltool") + list(PREPEND _CMAKE_ADDR2LINE_NAMES "llvm-addr2line") endif() - list(APPEND _CMAKE_AR_NAMES "ar") - list(APPEND _CMAKE_RANLIB_NAMES "ranlib") - list(APPEND _CMAKE_STRIP_NAMES "strip") - list(APPEND _CMAKE_LINKER_NAMES "ld") - list(APPEND _CMAKE_NM_NAMES "nm") - list(APPEND _CMAKE_OBJDUMP_NAMES "objdump") - list(APPEND _CMAKE_OBJCOPY_NAMES "objcopy") - list(APPEND _CMAKE_READELF_NAMES "readelf") - list(APPEND _CMAKE_DLLTOOL_NAMES "dlltool") - list(APPEND _CMAKE_ADDR2LINE_NAMES "addr2line") - - list(APPEND _CMAKE_TOOL_VARS AR RANLIB STRIP LINKER NM OBJDUMP OBJCOPY READELF DLLTOOL ADDR2LINE) + list(APPEND _CMAKE_TOOL_VARS AR RANLIB STRIP LINKER NM OBJDUMP OBJCOPY READELF DLLTOOL ADDR2LINE) endif() foreach(_CMAKE_TOOL IN LISTS _CMAKE_TOOL_VARS) + # Build the final list of prefixed/suffixed names. + set(_CMAKE_${_CMAKE_TOOL}_FIND_NAMES "") foreach(_CMAKE_TOOL_NAME IN LISTS _CMAKE_${_CMAKE_TOOL}_NAMES) - if(NOT _CMAKE_TOOLCHAIN_PREFIX STREQUAL "") - if(NOT _CMAKE_TOOLCHAIN_SUFFIX STREQUAL "") - list(PREPEND _CMAKE_${_CMAKE_TOOL}_NAMES ${_CMAKE_TOOL_NAME}${_CMAKE_TOOLCHAIN_SUFFIX}) - endif() - list(PREPEND _CMAKE_${_CMAKE_TOOL}_NAMES ${_CMAKE_TOOLCHAIN_PREFIX}${_CMAKE_TOOL_NAME}) - endif() - if(NOT _CMAKE_TOOLCHAIN_SUFFIX STREQUAL "") - list(PREPEND _CMAKE_${_CMAKE_TOOL}_NAMES ${_CMAKE_TOOLCHAIN_PREFIX}${_CMAKE_TOOL_NAME}${_CMAKE_TOOLCHAIN_SUFFIX}) - endif() + list(APPEND _CMAKE_${_CMAKE_TOOL}_FIND_NAMES + ${_CMAKE_TOOLCHAIN_PREFIX}${_CMAKE_TOOL_NAME}${_CMAKE_TOOLCHAIN_SUFFIX} + ${_CMAKE_TOOLCHAIN_PREFIX}${_CMAKE_TOOL_NAME} + ${_CMAKE_TOOL_NAME}${_CMAKE_TOOLCHAIN_SUFFIX} + ${_CMAKE_TOOL_NAME} + ) endforeach() - find_program(CMAKE_${_CMAKE_TOOL} NAMES ${_CMAKE_${_CMAKE_TOOL}_NAMES} HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) + list(REMOVE_DUPLICATES _CMAKE_${_CMAKE_TOOL}_FIND_NAMES) + + find_program(CMAKE_${_CMAKE_TOOL} NAMES ${_CMAKE_${_CMAKE_TOOL}_FIND_NAMES} HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) + unset(_CMAKE_${_CMAKE_TOOL}_FIND_NAMES) endforeach() if(NOT CMAKE_RANLIB) -- cgit v0.12 From 995f5b4e7b81e6672eaafba2c6d9a145e3aefe5d Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 27 May 2021 09:29:35 -0400 Subject: BinUtils: Find linker and librarian for OpenWatcom Update our OpenWatcom linker and archiver rules to use the `` and `` placeholders instead of hard-coding the tool names. --- Modules/CMakeFindBinUtils.cmake | 5 +++++ Modules/Compiler/OpenWatcom.cmake | 10 +++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Modules/CMakeFindBinUtils.cmake b/Modules/CMakeFindBinUtils.cmake index bfa9491..de516fc 100644 --- a/Modules/CMakeFindBinUtils.cmake +++ b/Modules/CMakeFindBinUtils.cmake @@ -86,6 +86,11 @@ if(("x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_SIMULATE_ID}" STREQUAL "xMSVC" AND list(APPEND _CMAKE_TOOL_VARS LINKER MT AR) +elseif("x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ID}" MATCHES "^x(Open)?Watcom$") + set(_CMAKE_LINKER_NAMES "wlink") + set(_CMAKE_AR_NAMES "wlib") + list(APPEND _CMAKE_TOOL_VARS LINKER AR) + # in all other cases search for ar, ranlib, etc. else() if(CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN) diff --git a/Modules/Compiler/OpenWatcom.cmake b/Modules/Compiler/OpenWatcom.cmake index a962513..ec36908 100644 --- a/Modules/Compiler/OpenWatcom.cmake +++ b/Modules/Compiler/OpenWatcom.cmake @@ -43,13 +43,13 @@ endforeach() # C create import library set(CMAKE_C_CREATE_IMPORT_LIBRARY - "wlib -c -q -n -b +") + " -c -q -n -b +") # C++ create import library set(CMAKE_CXX_CREATE_IMPORT_LIBRARY ${CMAKE_C_CREATE_IMPORT_LIBRARY}) # C link a object files into an executable file set(CMAKE_C_LINK_EXECUTABLE - "wlink ${CMAKE_WLINK_QUIET} name file {} ") + " ${CMAKE_WLINK_QUIET} name file {} ") # C++ link a object files into an executable file set(CMAKE_CXX_LINK_EXECUTABLE ${CMAKE_C_LINK_EXECUTABLE}) @@ -69,19 +69,19 @@ set(CMAKE_CXX_CREATE_PREPROCESSED_SOURCE # C create a shared library set(CMAKE_C_CREATE_SHARED_LIBRARY - "wlink ${CMAKE_WLINK_QUIET} name option implib= file {} ") + " ${CMAKE_WLINK_QUIET} name option implib= file {} ") # C++ create a shared library set(CMAKE_CXX_CREATE_SHARED_LIBRARY ${CMAKE_C_CREATE_SHARED_LIBRARY}) # C create a shared module set(CMAKE_C_CREATE_SHARED_MODULE - "wlink ${CMAKE_WLINK_QUIET} name file {} ") + " ${CMAKE_WLINK_QUIET} name file {} ") # C++ create a shared module set(CMAKE_CXX_CREATE_SHARED_MODULE ${CMAKE_C_CREATE_SHARED_MODULE}) # C create a static library set(CMAKE_C_CREATE_STATIC_LIBRARY - "wlib ${CMAKE_LIB_QUIET} -c -n -b ") + " ${CMAKE_LIB_QUIET} -c -n -b ") # C++ create a static library set(CMAKE_CXX_CREATE_STATIC_LIBRARY ${CMAKE_C_CREATE_STATIC_LIBRARY}) -- cgit v0.12 From 047585edc62fc4223a77a2c587a2ac795c91718f Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 27 May 2021 10:37:17 -0400 Subject: BinUtils: Find linker and librarian for Intel compilers on Windows Update our Intel linker and archiver rules to use the `` and `` placeholders instead of hard-coding the tool names. --- Modules/CMakeFindBinUtils.cmake | 3 +++ Modules/Platform/Windows-Intel.cmake | 4 ---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Modules/CMakeFindBinUtils.cmake b/Modules/CMakeFindBinUtils.cmake index de516fc..9dac4a9 100644 --- a/Modules/CMakeFindBinUtils.cmake +++ b/Modules/CMakeFindBinUtils.cmake @@ -82,6 +82,9 @@ if(("x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_SIMULATE_ID}" STREQUAL "xMSVC" AND list(PREPEND _CMAKE_MT_NAMES "llvm-mt") list(PREPEND _CMAKE_LINKER_NAMES "lld-link") list(APPEND _CMAKE_TOOL_VARS NM) + elseif("x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ID}" MATCHES "^xIntel") + list(PREPEND _CMAKE_AR_NAMES "xilib") + list(PREPEND _CMAKE_LINKER_NAMES "xilink") endif() list(APPEND _CMAKE_TOOL_VARS LINKER MT AR) diff --git a/Modules/Platform/Windows-Intel.cmake b/Modules/Platform/Windows-Intel.cmake index 01f8dd0..26e0cde 100644 --- a/Modules/Platform/Windows-Intel.cmake +++ b/Modules/Platform/Windows-Intel.cmake @@ -25,8 +25,4 @@ endif() include(Platform/Windows-MSVC) macro(__windows_compiler_intel lang) __windows_compiler_msvc(${lang}) - string(REPLACE "" "xilib" CMAKE_${lang}_CREATE_STATIC_LIBRARY "${CMAKE_${lang}_CREATE_STATIC_LIBRARY}") - foreach(rule CREATE_SHARED_LIBRARY CREATE_SHARED_MODULE LINK_EXECUTABLE) - string(REPLACE "" "xilink" CMAKE_${lang}_${rule} "${CMAKE_${lang}_${rule}}") - endforeach() endmacro() -- cgit v0.12