diff options
author | Jean-Marc Hengen <jean-marc.hengen@zuehlke.com> | 2021-07-19 21:14:29 (GMT) |
---|---|---|
committer | Jean-Marc Hengen <jean-marc.hengen@zuehlke.com> | 2021-07-23 12:34:26 (GMT) |
commit | 5b9bfe738cfa96ca12ca82506f234aae787965e9 (patch) | |
tree | f2799bb70661b3d9b067047c5410fde3b58f1c01 /Modules | |
parent | 31ecd3718047874b5eeb939e9608fa1bd386c1a7 (diff) | |
download | CMake-5b9bfe738cfa96ca12ca82506f234aae787965e9.zip CMake-5b9bfe738cfa96ca12ca82506f234aae787965e9.tar.gz CMake-5b9bfe738cfa96ca12ca82506f234aae787965e9.tar.bz2 |
IAR: Moved search logic to BinUtils.
The search logic for the IAR linker, librarian and related tools is
moved from `Modules/Compiler/IAR-FindBinUtils.cmake` to
`Modules/CMakeFindBinUtils.cmake` by introducing an new elseif block
for the IAR toolchain.
The search logic was refactored to omit repeating itself.
Fixes: #22425
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/CMakeFindBinUtils.cmake | 54 | ||||
-rw-r--r-- | Modules/Compiler/IAR-FindBinUtils.cmake | 80 | ||||
-rw-r--r-- | Modules/Compiler/IAR.cmake | 6 |
3 files changed, 54 insertions, 86 deletions
diff --git a/Modules/CMakeFindBinUtils.cmake b/Modules/CMakeFindBinUtils.cmake index 3162ec5..f139ff4 100644 --- a/Modules/CMakeFindBinUtils.cmake +++ b/Modules/CMakeFindBinUtils.cmake @@ -94,6 +94,53 @@ elseif("x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ID}" MATCHES "^x(Open)?W set(_CMAKE_AR_NAMES "wlib") list(APPEND _CMAKE_TOOL_VARS LINKER AR) +elseif("x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ID}" MATCHES "^xIAR$") + # Small helper declaring an IAR tool (e.g. linker) to avoid repeating the same idiom every time + macro(__append_IAR_tool TOOL_VAR NAME) + set(_CMAKE_${TOOL_VAR}_NAMES "${NAME}" "${NAME}.exe") + list(APPEND _CMAKE_TOOL_VARS ${TOOL_VAR}) + endmacro() + + # Resolve hint path from an IAR compiler + function(__resolve_IAR_hints COMPILER RESULT) + get_filename_component(_CMAKE_IAR_HINT "${COMPILER}" REALPATH) + get_filename_component(_CMAKE_IAR_HINT "${_CMAKE_IAR_HINT}" DIRECTORY) + list(APPEND _IAR_HINTS "${_CMAKE_IAR_HINT}") + + get_filename_component(_CMAKE_IAR_HINT "${COMPILER}" DIRECTORY) + list(APPEND _IAR_HINTS "${_CMAKE_IAR_HINT}") + + set(${RESULT} "${_IAR_HINTS}" PARENT_SCOPE) + endfunction() + + __resolve_IAR_hints("${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER}" _CMAKE_TOOLCHAIN_LOCATION) + set(_CMAKE_IAR_ITOOLS "ARM" "RX" "RH850" "RL78" "RISCV" "STM8") + set(_CMAKE_IAR_XTOOLS "AVR" "MSP430" "V850" "8051") + + if("${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ARCHITECTURE_ID}" IN_LIST _CMAKE_IAR_ITOOLS) + string(TOLOWER "${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ARCHITECTURE_ID}" _CMAKE_IAR_LOWER_ARCHITECTURE_ID) + + __append_IAR_tool(AR "iarchive") + __append_IAR_tool(LINKER "ilink${_CMAKE_IAR_LOWER_ARCHITECTURE_ID}") + + __append_IAR_tool(IAR_ELFDUMP "ielfdump${_CMAKE_IAR_LOWER_ARCHITECTURE_ID}") + __append_IAR_tool(IAR_ELFTOOL "ielftool") + __append_IAR_tool(IAR_OBJMANIP "iobjmanip") + __append_IAR_tool(IAR_SYMEXPORT "isymexport") + + unset(_CMAKE_IAR_LOWER_ARCHITECTURE_ID) + + elseif("${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ARCHITECTURE_ID}" IN_LIST _CMAKE_IAR_XTOOLS) + __append_IAR_tool(AR "xar") + __append_IAR_tool(LINKER "xlink") + + else() + message(FATAL_ERROR "Failed to find linker and librarian for ${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ID} on ${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ARCHITECTURE_ID}.") + endif() + + unset(_CMAKE_IAR_ITOOLS) + unset(_CMAKE_IAR_XTOOLS) + # in all other cases search for ar, ranlib, etc. else() if(CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN) @@ -186,3 +233,10 @@ unset(_CMAKE_TOOL_VARS) unset(_CMAKE_TOOL_CACHED) unset(_CMAKE_TOOL_NAME) unset(_CMAKE_TOOL) + +if("x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ID}" MATCHES "^xIAR$") + # Set for backwards compatibility + set(CMAKE_IAR_ARCHIVE "${CMAKE_AR}" CACHE FILEPATH "The IAR archiver") + set(CMAKE_IAR_LINKER "${CMAKE_LINKER}" CACHE FILEPATH "The IAR ILINK linker") + mark_as_advanced(CMAKE_IAR_LINKER CMAKE_IAR_AR) +endif() diff --git a/Modules/Compiler/IAR-FindBinUtils.cmake b/Modules/Compiler/IAR-FindBinUtils.cmake deleted file mode 100644 index 01f6d22..0000000 --- a/Modules/Compiler/IAR-FindBinUtils.cmake +++ /dev/null @@ -1,80 +0,0 @@ -if(NOT DEFINED _CMAKE_PROCESSING_LANGUAGE OR _CMAKE_PROCESSING_LANGUAGE STREQUAL "") - message(FATAL_ERROR "Internal error: _CMAKE_PROCESSING_LANGUAGE is not set") -endif() - -# Try to find tools in the same directory as the compiler itself -get_filename_component(__iar_hint_1 "${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER}" REALPATH) -get_filename_component(__iar_hint_1 "${__iar_hint_1}" DIRECTORY) - -get_filename_component(__iar_hint_2 "${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER}" DIRECTORY) - -set(__iar_hints "${__iar_hint_1}" "${__iar_hint_2}") - -if("${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ARCHITECTURE_ID}" STREQUAL "ARM" OR - "${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ARCHITECTURE_ID}" STREQUAL "RX" OR - "${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ARCHITECTURE_ID}" STREQUAL "RH850" OR - "${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ARCHITECTURE_ID}" STREQUAL "RL78" OR - "${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ARCHITECTURE_ID}" STREQUAL "RISCV" OR - "${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ARCHITECTURE_ID}" STREQUAL "STM8") - - string(TOLOWER "${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ARCHITECTURE_ID}" _archid_lower) - - # Find linker - find_program(CMAKE_IAR_LINKER - NAMES ilink${_archid_lower} ilink${_archid_lower}.exe - HINTS ${__iar_hints} - DOC "The IAR ILINK linker") - find_program(CMAKE_IAR_ARCHIVE - NAMES iarchive iarchive.exe - HINTS ${__iar_hints} - DOC "The IAR archiver") - - # Find utility tools - find_program(CMAKE_IAR_ELFTOOL - NAMES ielftool ielftool.exe - HINTS ${__iar_hints} - DOC "The IAR ELF Tool") - find_program(CMAKE_IAR_ELFDUMP - NAMES ielfdump${_archid_lower} ielfdump${_archid_lower}.exe - HINTS ${__iar_hints} - DOC "The IAR ELF Dumper") - find_program(CMAKE_IAR_OBJMANIP - NAMES iobjmanip iobjmanip.exe - HINTS ${__iar_hints} - DOC "The IAR ELF Object Tool") - find_program(CMAKE_IAR_SYMEXPORT - NAMES isymexport - HINTS ${__iar_hints} - DOC "The IAR Absolute Symbol Exporter") - mark_as_advanced(CMAKE_IAR_LINKER CMAKE_IAR_ARCHIVE CMAKE_IAR_ELFTOOL CMAKE_IAR_ELFDUMP CMAKE_IAR_OBJMANIP CMAKE_IAR_SYMEXPORT) - - set(CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_CUSTOM_CODE -"set(CMAKE_IAR_LINKER \"${CMAKE_IAR_LINKER}\") -set(CMAKE_IAR_ARCHIVE \"${CMAKE_IAR_ARCHIVE}\") -set(CMAKE_IAR_ELFTOOL \"${CMAKE_IAR_ELFTOOL}\") -set(CMAKE_IAR_ELFDUMP \"${CMAKE_IAR_ELFDUMP}\") -set(CMAKE_IAR_OBJMANIP \"${CMAKE_IAR_OBJMANIP}\") -set(CMAKE_IAR_LINKER \"${CMAKE_IAR_LINKER}\") -") - -elseif("${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ARCHITECTURE_ID}" STREQUAL "AVR" OR - "${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ARCHITECTURE_ID}" STREQUAL "MSP430" OR - "${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ARCHITECTURE_ID}" STREQUAL "V850" OR - "${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ARCHITECTURE_ID}" STREQUAL "8051") - - # Find the "xlink" linker and "xar" archiver: - find_program(CMAKE_IAR_LINKER - NAMES xlink xlink.exe - HINTS ${__iar_hints} - DOC "The IAR XLINK linker") - find_program(CMAKE_IAR_AR - NAMES xar xar.exe - HINTS ${__iar_hints} - DOC "The IAR archiver") - mark_as_advanced(CMAKE_IAR_LINKER CMAKE_IAR_AR) - - set(CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_CUSTOM_CODE -"set(CMAKE_IAR_LINKER \"${CMAKE_IAR_LINKER}\") -set(CMAKE_IAR_AR \"${CMAKE_IAR_AR}\") -") -endif() diff --git a/Modules/Compiler/IAR.cmake b/Modules/Compiler/IAR.cmake index a6b436a..2200a21 100644 --- a/Modules/Compiler/IAR.cmake +++ b/Modules/Compiler/IAR.cmake @@ -71,9 +71,6 @@ macro(__compiler_iar_ilink lang) set(CMAKE_${lang}_ARCHIVE_CREATE "<CMAKE_AR> <TARGET> --create <LINK_FLAGS> <OBJECTS>") set(CMAKE_${lang}_ARCHIVE_APPEND "<CMAKE_AR> <TARGET> --replace <LINK_FLAGS> <OBJECTS>") set(CMAKE_${lang}_ARCHIVE_FINISH "") - - set(CMAKE_LINKER "${CMAKE_IAR_LINKER}" CACHE FILEPATH "The IAR linker" FORCE) - set(CMAKE_AR "${CMAKE_IAR_ARCHIVE}" CACHE FILEPATH "The IAR archiver" FORCE) endmacro() macro(__compiler_iar_xlink lang) @@ -109,7 +106,4 @@ macro(__compiler_iar_xlink lang) set(CMAKE_${lang}_ARCHIVE_FINISH "") set(CMAKE_LIBRARY_PATH_FLAG "-I") - - set(CMAKE_LINKER "${CMAKE_IAR_LINKER}" CACHE FILEPATH "The IAR linker" FORCE) - set(CMAKE_AR "${CMAKE_IAR_AR}" CACHE FILEPATH "The IAR archiver" FORCE) endmacro() |