IAR: Add tests covering IAR toolchains

Run the tests only if enabled explicitly by an undocumented cache
entry.  We will enable it on hosts known to have the toolchains.
This commit is contained in:
Felipe Torrezan
2023-10-21 18:36:21 +02:00
committed by Brad King
parent aab0d6bc4f
commit 37e44707bc
12 changed files with 177 additions and 0 deletions

View File

@@ -1097,3 +1097,8 @@ endif()
if(WIN32)
add_RunCMake_test(Win32GenEx)
endif()
if(CMake_TEST_IAR_TOOLCHAINS)
add_RunCMake_test(IAR -DCMake_TEST_IAR_TOOLCHAINS=${CMake_TEST_IAR_TOOLCHAINS})
set_property(TEST RunCMake.IAR APPEND PROPERTY LABELS "IAR")
endif()

View File

@@ -0,0 +1,3 @@
cmake_minimum_required(VERSION 3.28)
project(${RunCMake_TEST} NONE)
include(${RunCMake_TEST}.cmake)

View File

@@ -0,0 +1,64 @@
include(RunCMake)
if(RunCMake_GENERATOR MATCHES "Makefile|Ninja")
file(GLOB _iar_toolchains
"${CMake_TEST_IAR_TOOLCHAINS}/bx*-*/*/bin/icc*" )
if(_iar_toolchains STREQUAL "")
message(FATAL_ERROR "Could not find any IAR toolchains at: ${CMake_TEST_IAR_TOOLCHAINS}.")
endif()
endif()
foreach(_iar_toolchain IN LISTS _iar_toolchains)
message(STATUS "Found IAR toolchain: ${_iar_toolchain}")
cmake_path(GET _iar_toolchain PARENT_PATH BIN_DIR)
cmake_path(GET BIN_DIR PARENT_PATH TOOLKIT_DIR)
cmake_path(GET TOOLKIT_DIR FILENAME ARCH)
# Sets the minimal requirements for linking each target architecture
if(ARCH STREQUAL rl78)
set(LINK_OPTS
"--config_def _STACK_SIZE=256 \
--config_def _NEAR_HEAP_SIZE=0x400 \
--config_def _FAR_HEAP_SIZE=4096 \
--config_def _HUGE_HEAP_SIZE=0 \
--config_def _NEAR_CONST_LOCATION_START=0x2000 \
--config_def _NEAR_CONST_LOCATION_SIZE=0x6F00 \
--define_symbol _NEAR_CONST_LOCATION=0 \
--config ${TOOLKIT_DIR}/config/lnkrl78_s3.icf" )
else()
set(LINK_OPTS "")
endif()
# Set IAR Assembler (ILINK || XLINK)
find_program(IAR_ASSEMBLER
NAMES iasm${ARCH} a${ARCH}
PATHS ${BIN_DIR}
REQUIRED )
set(RunCMake_TEST_OPTIONS
-DCMAKE_SYSTEM_NAME=Generic
-DCMAKE_C_COMPILER=${_iar_toolchain}
-DCMAKE_EXE_LINKER_FLAGS=${LINK_OPTS}
)
run_cmake(iar-c)
set(RunCMake_TEST_OPTIONS
-DCMAKE_SYSTEM_NAME=Generic
-DCMAKE_CXX_COMPILER=${_iar_toolchain}
-DCMAKE_EXE_LINKER_FLAGS=${LINK_OPTS}
)
run_cmake(iar-cxx)
set(RunCMake_TEST_OPTIONS
-DCMAKE_SYSTEM_NAME=Generic
-DCMAKE_ASM_COMPILER=${IAR_ASSEMBLER}
)
run_cmake(iar-asm)
set(RunCMake_TEST_OPTIONS
-DCMAKE_SYSTEM_NAME=Generic
-DCMAKE_C_COMPILER=${_iar_toolchain}
-DCMAKE_EXE_LINKER_FLAGS=${LINK_OPTS}
)
run_cmake(iar-lib)
endforeach()

View File

@@ -0,0 +1,5 @@
enable_language(ASM)
add_executable(exec-asm)
target_sources(exec-asm PRIVATE module.asm)
target_link_options(exec-asm PRIVATE ${LINKER_OPTS})

View File

@@ -0,0 +1,5 @@
enable_language(C)
add_executable(exec-c)
target_sources(exec-c PRIVATE module.c)
target_link_options(exec-c PRIVATE ${LINKER_OPTS})

View File

@@ -0,0 +1,5 @@
enable_language(CXX)
add_executable(exec-cxx)
target_sources(exec-cxx PRIVATE module.cxx)
target_link_options(exec-cxx PRIVATE ${LINKER_OPTS})

View File

@@ -0,0 +1,10 @@
enable_language(C)
add_library(iar-test-lib)
target_sources(iar-test-lib PRIVATE libmod.c)
add_executable(exec-lib-c)
target_sources(exec-lib-c PRIVATE module.c)
target_compile_definitions(exec-lib-c PRIVATE __USE_LIBFUN)
target_link_libraries(exec-lib-c LINK_PUBLIC iar-test-lib)
target_link_options(exec-lib-c PRIVATE ${LINKER_OPTS})

View File

@@ -0,0 +1,4 @@
int iar_libfun()
{
return 42;
}

View File

@@ -0,0 +1,41 @@
#if defined(__IASM8051__) || defined(__IASM430__)
NAME main
#else
MODULE main
#endif
PUBLIC main
PUBLIC __iar_program_start
PUBLIC __program_start
#if defined(__IASMSTM8__)
EXTERN CSTACK$$Limit
SECTION `.near_func.text`:CODE:NOROOT(0)
#elif defined(__IASMAVR__)
ORG $0
RJMP main
RSEG CODE
#elif defined(__IASM8051__)
ORG 0FFFEh
DC16 main
RSEG RCODE
?cmain:
#elif defined(__IASM430__)
ORG 0FFFEh
DC16 init
RSEG CSTACK
RSEG CODE
init:
MOV #SFE(CSTACK), SP
#else
EXTERN __iar_static_base$$GPREL
SECTION CSTACK:DATA:NOROOT(4)
SECTION `.cstartup`:CODE(2)
CODE
#endif
__program_start:
__iar_program_start:
main:
NOP
END

View File

@@ -0,0 +1,14 @@
#include "module.h"
#if defined(__USE_LIBFUN)
extern int iar_libfun();
#endif
__root int i;
__root int main()
{
#if defined(__USE_LIBFUN)
i = iar_libfun();
#else
i = INTERNAL;
#endif
return i;
}

View File

@@ -0,0 +1,7 @@
#include "module.h"
__root int i;
__root int main()
{
i = INTERNAL;
return i;
}

View File

@@ -0,0 +1,14 @@
#ifndef __MODULE_H__
#define __MODULE_H__
#if defined(__cplusplus)
# define INTERNAL 64
#elif !defined(__cplusplus) && defined(__IAR_SYSTEMS_ICC__)
# define INTERNAL 32
#elif defined(__IAR_SYSTEMS_ASM__)
# define INTERNAL 16
#else
# error "Unable to determine INTERNAL symbol."
#endif /* __IAR_SYSTEMS_ICC */
#endif /* __MODULE_H__ */