Skip to content

Commit be355cf

Browse files
author
Felipe Torrezan
authored
Fix support to other generators (#19)
* Fix support for alternative generators
1 parent 179297a commit be355cf

3 files changed

Lines changed: 83 additions & 28 deletions

File tree

tests/CMakeLists.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
cmake_minimum_required(VERSION 3.22)
22

33
set(TOOLKIT_DIR $ENV{TOOLKIT_DIR})
4-
set(CMAKE_GENERATOR "Ninja Multi-Config")
54
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
5+
66
list(APPEND CMAKE_CONFIGURATION_TYPES Debug Release RelWithDebInfo MinSizeRel)
77

88
project(IAR-test LANGUAGES C CXX ASM)
99

10-
set(LINKER_MAP --map $<CONFIG>/$<TARGET_PROPERTY:NAME>.map)
10+
if(CMAKE_GENERATOR MATCHES "Ninja Multi-Config")
11+
set(LINKER_MAP --map $<CONFIG>/$<TARGET_PROPERTY:NAME>.map)
12+
else()
13+
if(NOT CMAKE_BUILD_TYPE)
14+
set(CMAKE_BUILD_TYPE Debug)
15+
endif()
16+
set(LINKER_MAP --map ${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_PROPERTY:NAME>-${CMAKE_BUILD_TYPE}.map)
17+
endif()
1118

1219
# arch-specific
1320
if(TARGET_ARCH STREQUAL arm)

tests/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ Export the `$IAR_TOOL_ROOT` environment variable, pointing to the top-level loca
3535
### IAR_LMS2_SERVER_IP (optional)
3636
Export the `IAR_LMS2_SERVER_IP` environment variable pointing to the license server, if the client's 1st-time license setup is required. Applies to the `-GL` and `-NW` products. (Default: not set)
3737

38-
### CMAKE_MAKE_PROGRAM (optional)
39-
Export the `CMAKE_MAKE_PROGRAM` environment variable to specify which generator to use. (Default: `Ninja`)
38+
### CMAKE_GENERATOR (optional)
39+
Export the `CMAKE_GENERATOR` environment variable to specify which generator to use. (Default: `Ninja Multi-Config`)
4040

4141
### MSYSTEM
4242
This environment variable is automatically set by MSYS2, MINGW64 and MINGW32. Cygwin users must set it manually.

tests/run-tests.sh

Lines changed: 72 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
# CygWin users: must manually export the variable to CYGWIN
2424
# (e.g., export MSYSTEM=CYGWIN)
2525
#
26+
# CMAKE_GENERATOR
27+
# Default: "Ninja Multi-Config"
28+
# (e.g., export CMAKE_GENERATOR="MinGW Makefiles")
29+
#
2630

2731
BUILD_CFGS=(Debug RelWithDebInfo Release MinSizeRel)
2832

@@ -50,7 +54,7 @@ function lms2-setup() {
5054
}
5155

5256
function find_icc() {
53-
if [ -z "$MSYSTEM" ]; then
57+
if [ "$MSYSTEM" = "" ]; then
5458
export CC="${p}";
5559
export CXX="${p}";
5660
else
@@ -63,7 +67,7 @@ function find_icc() {
6367
}
6468

6569
function find_ilink() {
66-
if [ -z "$MSYSTEM" ]; then
70+
if [ "$MSYSTEM" = "" ]; then
6771
export ASM=$(dirname ${p})/iasm${a};
6872
else
6973
export ASM=$(cygpath -m $(dirname ${p})/iasm${a}${EXT});
@@ -72,38 +76,50 @@ function find_ilink() {
7276
}
7377

7478
function find_xlink() {
75-
if [ ! -z "$MSYSTEM" ]; then
79+
if [ "$MSYSTEM" = "" ]; then
7680
export ASM=$(cygpath -m $(dirname ${p})/a${a}${EXT});
7781
else
7882
export ASM=$(dirname ${p})/a${a};
7983
fi
8084
echo "Using ASM_COMPILER: $ASM";
8185
}
8286

83-
function cmake_configure() {
84-
rm -rf _builds;
85-
# If no CMAKE_MAKE_PROGRAM is set, defaults to ninja
86-
if [ -z "$CMAKE_MAKE_PROGRAM" ]; then
87-
if [ -z "$MSYSTEM" ]; then
87+
function cmake_set_gen() {
88+
# If no CMAKE_GENERATOR is set, defaults to `Ninja Multi-Config`
89+
if [ "$CMAKE_GENERATOR" = "" ]; then
90+
if [ "$MSYSTEM" = "" ]; then
8891
export CMAKE_MAKE_PROGRAM=$(which ninja);
8992
else
9093
export CMAKE_MAKE_PROGRAM=$(cygpath -m $(which ninja));
9194
fi
95+
if [ ! -f $CMAKE_MAKE_PROGRAM ]; then
96+
echo "FATAL ERROR: CMAKE_MAKE_PROGRAM not found ($CMAKE_MAKE_PROGRAM). No ninja executable found either.";
97+
exit 1;
98+
fi
99+
export CMAKE_GENERATOR="Ninja Multi-Config";
100+
else
101+
export CONFIGURATION_TYPES=(Debug Release RelWithDebInfo MinSizeRel)
92102
fi
93-
if [ ! -f $CMAKE_MAKE_PROGRAM ]; then
94-
echo "FATAL ERROR: CMAKE_MAKE_PROGRAM not found ($CMAKE_MAKE_PROGRAM). No ninja executable found either.";
95-
exit 1;
103+
}
104+
105+
function cmake_configure() {
106+
# Remove stale builds
107+
rm -rf _build*;
108+
if [ -z ${CONFIGURATION_TYPES} ]; then
109+
cmake -B_builds -DTARGET_ARCH=${a} -DTOOLKIT_DIR=${TOOLKIT_DIR};
110+
else
111+
for cfg in ${CONFIGURATION_TYPES[@]}; do
112+
cmake -B_build-${cfg} -DCMAKE_BUILD_TYPE=${cfg} -DTARGET_ARCH=${a} -DTOOLKIT_DIR=${TOOLKIT_DIR}
113+
done
96114
fi
97-
cmake -B _builds -G "Ninja Multi-Config" \
98-
-DTARGET_ARCH=${a} \
99-
-DTOOLKIT_DIR=${TOOLKIT_DIR};
100115
if [ $? -ne 0 ]; then
101-
echo "FAIL: CMake configuration phase.";
116+
echo "FATAL ERROR: CMake configuration phase.";
102117
exit 1;
103118
fi
104119
}
105120

106121
function check_output() {
122+
if [ -z ${CONFIGURATION_TYPES} ]; then
107123
if [ -f _builds/${cfg}/test-c.${OUTPUT_FORMAT,,} ]; then
108124
echo "+${cfg}:C ${OUTPUT_FORMAT} built successfully.";
109125
else
@@ -119,20 +135,51 @@ function check_output() {
119135
else
120136
echo "-${cfg}:ASM ${OUTPUT_FORMAT} not built.";
121137
fi
138+
else
139+
if [ -f _build-${cfg}/test-c.${OUTPUT_FORMAT,,} ]; then
140+
echo "+${cfg}:C ${OUTPUT_FORMAT} built successfully.";
141+
else
142+
echo "-${cfg}:C ${OUTPUT_FORMAT} not built.";
143+
fi
144+
if [ -f _build-${cfg}/test-cxx.${OUTPUT_FORMAT,,} ]; then
145+
echo "+${cfg}:CXX ${OUTPUT_FORMAT} built successfully.";
146+
else
147+
echo "-${cfg}:CXX ${OUTPUT_FORMAT} not built.";
148+
fi
149+
if [ -f _build-${cfg}/test-asm.${OUTPUT_FORMAT,,} ]; then
150+
echo "+${cfg}:ASM ${OUTPUT_FORMAT} built successfully.";
151+
else
152+
echo "-${cfg}:ASM ${OUTPUT_FORMAT} not built.";
153+
fi
154+
fi
122155
}
123156

124157
function cmake_build() {
125-
for cfg in ${BUILD_CFGS[@]}; do
126-
echo "===== Build configuration: [${cfg}]";
127-
cmake --build _builds --config ${cfg} --verbose;
128-
if [ $? -ne 0 ]; then
129-
echo "FAIL: CMake building phase (${cfg}).";
130-
exit 1;
131-
fi
132-
check_output;
133-
done
158+
if [ -z ${CONFIGURATION_TYPES} ]; then
159+
for cfg in ${BUILD_CFGS[@]}; do
160+
echo "===== Build configuration: [${cfg}]";
161+
cmake --build _builds --config ${cfg} --verbose;
162+
if [ $? -ne 0 ]; then
163+
echo "FAIL: CMake building phase (${cfg}).";
164+
exit 1;
165+
fi
166+
check_output;
167+
done
168+
else
169+
for cfg in ${CONFIGURATION_TYPES[@]}; do
170+
echo "===== Build configuration: [${cfg}]";
171+
cmake --build _build-${cfg} --verbose;
172+
if [ $? -ne 0 ]; then
173+
echo "FAIL: CMake building phase (${cfg}).";
174+
exit 1;
175+
fi
176+
check_output;
177+
done
178+
179+
fi
134180
}
135181

182+
cmake_set_gen;
136183

137184
echo "----------- ilink tools";
138185
ILINK_TOOL=(arm riscv rh850 rl78 rx stm8);
@@ -167,3 +214,4 @@ for r in ${IAR_TOOL_ROOT[@]}; do
167214
done
168215
done
169216
done
217+

0 commit comments

Comments
 (0)