IAR.cmake 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. # This file is processed when the IAR compiler is used for a C or C++ file
  2. # Documentation can be downloaded here: http://www.iar.com/website1/1.0.1.0/675/1/
  3. # The initial feature request is here: https://gitlab.kitware.com/cmake/cmake/issues/10176
  4. # It also contains additional links and information.
  5. # See USER GUIDES -> C/C++ Development Guide and ReleaseNotes for EWARM:
  6. # version 6.30.8: http://supp.iar.com/FilesPublic/UPDINFO/006607/arm/doc/infocenter/index.ENU.html
  7. # version 7.60.1: http://supp.iar.com/FilesPublic/UPDINFO/011006/arm/doc/infocenter/index.ENU.html
  8. # version 8.10.1: http://netstorage.iar.com/SuppDB/Public/UPDINFO/011854/arm/doc/infocenter/index.ENU.html
  9. # The IAR internal compiler platform generations (Predefined symbol __IAR_SYSTEMS_ICC__):
  10. # 9 and higher means C11 and C++14 as language default (EWARM v8.x, EWRX v4.x and higher)
  11. # 8 means C99 and C++03 as language default (EWARM v6.x, v7.x. EWRX v2.x, 3.x)
  12. # 7 and lower means C89 and EC++ as language default. (EWARM v5.x and lower)
  13. # C/C++ Standard versions
  14. #
  15. # IAR typically only supports one C and C++ Standard version,
  16. # the exception is C89 which is always supported and can be selected
  17. # if its not the default
  18. #
  19. # C++ is trickier, there were historically 3 switches,
  20. # and some IAR versions support multiple of those.
  21. # they are --eec++, --ec++ and --c++ and where used to
  22. # enable various language features like exceptions
  23. #
  24. # recent versions only have --c++ for full support
  25. # but can choose to disable features with further arguments
  26. #
  27. # C/C++ Standard compliance
  28. #
  29. # IAR has 3 modes: default, strict and extended
  30. # the extended mode is needed for popular libraries like CMSIS
  31. #
  32. # "Silent" Operation
  33. #
  34. # this really is different to most programs I know.
  35. # nothing meaningful from the operation is lost, just some redundant
  36. # code and data size printouts (that can be inspected with common tools).
  37. # This module is shared by multiple languages; use include blocker.
  38. include_guard()
  39. macro(__compiler_iar_ilink lang)
  40. set(CMAKE_EXECUTABLE_SUFFIX ".elf")
  41. if (${lang} STREQUAL "C" OR ${lang} STREQUAL "CXX")
  42. set(CMAKE_${lang}_COMPILE_OBJECT "<CMAKE_${lang}_COMPILER> ${CMAKE_IAR_${lang}_FLAG} --silent <SOURCE> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT>")
  43. set(CMAKE_${lang}_CREATE_PREPROCESSED_SOURCE "<CMAKE_${lang}_COMPILER> ${CMAKE_IAR_${lang}_FLAG} --silent <SOURCE> <DEFINES> <INCLUDES> <FLAGS> --preprocess=cnl <PREPROCESSED_SOURCE>")
  44. set(CMAKE_${lang}_CREATE_ASSEMBLY_SOURCE "<CMAKE_${lang}_COMPILER> ${CMAKE_IAR_${lang}_FLAG} --silent <SOURCE> <DEFINES> <INCLUDES> <FLAGS> -lAH <ASSEMBLY_SOURCE> -o <OBJECT>.dummy")
  45. set(CMAKE_${lang}_RESPONSE_FILE_LINK_FLAG "-f ")
  46. set(CMAKE_DEPFILE_FLAGS_${lang} "--dependencies=ns <DEPFILE>")
  47. string(APPEND CMAKE_${lang}_FLAGS_INIT " ")
  48. string(APPEND CMAKE_${lang}_FLAGS_DEBUG_INIT " -r")
  49. string(APPEND CMAKE_${lang}_FLAGS_MINSIZEREL_INIT " -Ohz -DNDEBUG")
  50. string(APPEND CMAKE_${lang}_FLAGS_RELEASE_INIT " -Oh -DNDEBUG")
  51. string(APPEND CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT " -Oh -r -DNDEBUG")
  52. endif()
  53. if (${lang} STREQUAL "ASM")
  54. string(APPEND CMAKE_ASM_FLAGS_INIT " ")
  55. string(APPEND CMAKE_ASM_FLAGS_DEBUG_INIT " -r")
  56. string(APPEND CMAKE_ASM_FLAGS_MINSIZEREL_INIT " -DNDEBUG")
  57. string(APPEND CMAKE_ASM_FLAGS_RELEASE_INIT " -DNDEBUG")
  58. string(APPEND CMAKE_ASM_FLAGS_RELWITHDEBINFO_INIT " -r -DNDEBUG")
  59. endif()
  60. set(CMAKE_${lang}_LINK_EXECUTABLE "\"${CMAKE_IAR_LINKER}\" --silent <OBJECTS> <CMAKE_${lang}_LINK_FLAGS> <LINK_FLAGS> <LINK_LIBRARIES> -o <TARGET>")
  61. set(CMAKE_${lang}_CREATE_STATIC_LIBRARY "\"${CMAKE_IAR_ARCHIVE}\" <TARGET> --create <LINK_FLAGS> <OBJECTS>")
  62. set(CMAKE_${lang}_ARCHIVE_CREATE "\"${CMAKE_IAR_ARCHIVE}\" <TARGET> --create <LINK_FLAGS> <OBJECTS>")
  63. set(CMAKE_${lang}_ARCHIVE_APPEND "\"${CMAKE_IAR_ARCHIVE}\" <TARGET> --replace <LINK_FLAGS> <OBJECTS>")
  64. set(CMAKE_${lang}_ARCHIVE_FINISH "")
  65. set(CMAKE_LINKER "${CMAKE_IAR_LINKER}" CACHE FILEPATH "The IAR linker" FORCE)
  66. set(CMAKE_AR "${CMAKE_IAR_ARCHIVE}" CACHE FILEPATH "The IAR archiver" FORCE)
  67. endmacro()
  68. macro(__compiler_iar_xlink lang)
  69. set(CMAKE_EXECUTABLE_SUFFIX ".bin")
  70. if (${lang} STREQUAL "C" OR ${lang} STREQUAL "CXX")
  71. set(CMAKE_${lang}_COMPILE_OBJECT "<CMAKE_${lang}_COMPILER> ${CMAKE_IAR_${lang}_FLAG} --silent <SOURCE> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT>")
  72. set(CMAKE_${lang}_CREATE_PREPROCESSED_SOURCE "<CMAKE_${lang}_COMPILER> ${CMAKE_IAR_${lang}_FLAG} --silent <SOURCE> <DEFINES> <INCLUDES> <FLAGS> --preprocess=cnl <PREPROCESSED_SOURCE>")
  73. set(CMAKE_${lang}_CREATE_ASSEMBLY_SOURCE "<CMAKE_${lang}_COMPILER> ${CMAKE_IAR_${lang}_FLAG} --silent <SOURCE> <DEFINES> <INCLUDES> <FLAGS> -lAH <ASSEMBLY_SOURCE> -o <OBJECT>.dummy")
  74. set(CMAKE_${lang}_RESPONSE_FILE_LINK_FLAG "-f ")
  75. set(CMAKE_DEPFILE_FLAGS_${lang} "--dependencies=ns <DEPFILE>")
  76. string(APPEND CMAKE_${lang}_FLAGS_INIT " ")
  77. string(APPEND CMAKE_${lang}_FLAGS_DEBUG_INIT " -r")
  78. string(APPEND CMAKE_${lang}_FLAGS_MINSIZEREL_INIT " -Ohz -DNDEBUG")
  79. string(APPEND CMAKE_${lang}_FLAGS_RELEASE_INIT " -Oh -DNDEBUG")
  80. string(APPEND CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT " -Oh -r -DNDEBUG")
  81. endif()
  82. if (${lang} STREQUAL "ASM")
  83. string(APPEND CMAKE_ASM_FLAGS_INIT " ")
  84. string(APPEND CMAKE_ASM_FLAGS_DEBUG_INIT " -r")
  85. string(APPEND CMAKE_ASM_FLAGS_MINSIZEREL_INIT " -DNDEBUG")
  86. string(APPEND CMAKE_ASM_FLAGS_RELEASE_INIT " -DNDEBUG")
  87. string(APPEND CMAKE_ASM_FLAGS_RELWITHDEBINFO_INIT " -r -DNDEBUG")
  88. endif()
  89. set(CMAKE_${lang}_LINK_EXECUTABLE "\"${CMAKE_IAR_LINKER}\" -S <OBJECTS> <CMAKE_${lang}_LINK_FLAGS> <LINK_FLAGS> <LINK_LIBRARIES> -o <TARGET>")
  90. set(CMAKE_${lang}_CREATE_STATIC_LIBRARY "\"${CMAKE_IAR_AR}\" <TARGET> <LINK_FLAGS> <OBJECTS>")
  91. set(CMAKE_${lang}_ARCHIVE_CREATE "\"${CMAKE_IAR_AR}\" <TARGET> <LINK_FLAGS> <OBJECTS>")
  92. set(CMAKE_${lang}_ARCHIVE_APPEND "")
  93. set(CMAKE_${lang}_ARCHIVE_FINISH "")
  94. set(CMAKE_LIBRARY_PATH_FLAG "-I")
  95. set(CMAKE_LINKER "${CMAKE_IAR_LINKER}" CACHE FILEPATH "The IAR linker" FORCE)
  96. set(CMAKE_AR "${CMAKE_IAR_AR}" CACHE FILEPATH "The IAR archiver" FORCE)
  97. endmacro()