Skip to content

Commit 5c1cc2f

Browse files
committed
Set CC and CXX environment variables for GCC/Clang toolchain
Sets the C (CC) and C++ (CXX) compiler environment variables so the choice of toolchain selected in the Build Settings tab is respected. Toolchains supported are GNU GCC and Clang. Cross prefix is supported for GNU GCC. Version suffix and extension supported. Added JUnit tests for GCCToolChain and ClangToolChain. Added test document describing manual test steps. Fixes #1140
1 parent 2c82545 commit 5c1cc2f

File tree

6 files changed

+865
-5
lines changed

6 files changed

+865
-5
lines changed

build/org.eclipse.cdt.build.gcc.core.tests/META-INF/MANIFEST.MF

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ Require-Bundle: org.eclipse.core.resources,
99
org.junit,
1010
org.eclipse.jdt.junit4.runtime,
1111
org.eclipse.core.runtime,
12-
org.eclipse.cdt.build.gcc.core
12+
org.eclipse.cdt.build.gcc.core,
13+
junit-jupiter-api
1314
Automatic-Module-Name: org.eclipse.cdt.build.gcc.core.tests
1415
Bundle-RequiredExecutionEnvironment: JavaSE-17
1516
Bundle-ActivationPolicy: lazy
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
## Overview
2+
3+
This document captures the manual tests that should be completed for Core Build toolchains.
4+
5+
Added:
6+
7+
20250617 John Moule
8+
Set CC and CXX environment variables for clang toolchain #1169
9+
https://github.com/eclipse-cdt/cdt/pull/1169
10+
11+
## Tests
12+
The manual test cases below are useful to show the expected toolchain is used for a build.
13+
14+
The following JUnits are also added:
15+
- org.eclipse.cdt.build.gcc.core.tests.TestGCCToolChain
16+
- org.eclipse.cdt.build.gcc.core.tests.TestClangToolChain
17+
18+
## Test Case Summary
19+
- A) Clang toolchain can be used to build when selected in Build Settings > Toolchain.
20+
- B) GCC toolchain can be used to build when selected in Build Settings > Toolchain.
21+
- C) Clang toolchain can be used to build when CC/CXX defined externally to gcc/g++
22+
- D) GCC toolchain can be used to build when CC/CXX defined externally to clang/clang++
23+
24+
Tests should be performed on Linux & Windows.
25+
26+
### Prerequisites
27+
Make sure cmake, make, ninja, GCC and clang toolchains are installed on the host - see [1].
28+
CC/CXX are not defined in the system environment, unless specified in the test.
29+
30+
31+
## Test case A) Clang toolchain can be used to build when selected in Build Settings > Toolchain.
32+
- Create a CMake Hello World project
33+
- From the Launch Bar, open the Launch Configuration (gear icon)
34+
- Select Build Settings tab and in the Toolchain dropdown, change to clang toolchain and click OK.
35+
- From the Launch Bar, build the project.
36+
37+
Expected: The project builds successfully and in the Console build output, it can be seen that the C and CXX compiler are identified as "Clang".
38+
39+
Actual: The following shows an example of Console build output:
40+
41+
42+
Configuring in: C:\Users\a5107948\cdt-main20250110b\runtime-cdtruntime_clean\cmake_hw\build\cmake.debug.win32.x86_64.Local
43+
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -G Ninja C:\Users\a5107948\cdt-main20250110b\runtime-cdtruntime_clean\cmake_hw
44+
-- The C compiler identification is Clang 19.1.7
45+
-- The CXX compiler identification is Clang 19.1.7
46+
-- Detecting C compiler ABI info
47+
-- Detecting C compiler ABI info - done
48+
-- Check for working C compiler: C:/msys64/ucrt64/bin/clang.exe - skipped
49+
-- Detecting C compile features
50+
-- Detecting C compile features - done
51+
-- Detecting CXX compiler ABI info
52+
-- Detecting CXX compiler ABI info - done
53+
-- Check for working CXX compiler: C:/msys64/ucrt64/bin/clang++.exe - skipped
54+
-- Detecting CXX compile features
55+
-- Detecting CXX compile features - done
56+
-- Configuring done (3.1s)
57+
-- Generating done (0.1s)
58+
-- Build files have been written to: C:/Users/a5107948/cdt-main20250110b/runtime-cdtruntime_clean/cmake_hw/build/cmake.debug.win32.x86_64.Local
59+
Building in: C:\Users\a5107948\cdt-main20250110b\runtime-cdtruntime_clean\cmake_hw\build\cmake.debug.win32.x86_64.Local
60+
cmake --build . --target all
61+
[1/2] Building CXX object CMakeFiles/cmake_hw.dir/cmake_hw.cpp.obj
62+
[2/2] Linking CXX executable cmake_hw.exe
63+
Build complete (0 errors, 0 warnings): C:\Users\a5107948\cdt-main20250110b\runtime-cdtruntime_clean\cmake_hw\build\cmake.debug.win32.x86_64.Local
64+
65+
66+
## Test case B) GCC toolchain can be used to build when selected in Build Settings > Toolchain.
67+
- From the Launch Bar, open the Launch Configuration (gear icon)
68+
- Select Build Settings tab and in the Toolchain dropdown, change to gcc toolchain and click OK.
69+
- Delete the project's build folder.
70+
- From the Launch Bar, build the project.
71+
72+
Expected: The project builds successfully and in the Console build output, it can be seen that the C and CXX compiler are identified as "gnu".
73+
74+
Actual: The following shows an example of Console build output:
75+
76+
Configuring in: C:\Users\a5107948\cdt-main20250110b\runtime-cdtruntime_clean\cmake_hw\build\cmake.debug.win32.x86_64.Local
77+
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -G Ninja C:\Users\a5107948\cdt-main20250110b\runtime-cdtruntime_clean\cmake_hw
78+
-- The C compiler identification is GNU 14.2.0
79+
-- The CXX compiler identification is GNU 14.2.0
80+
-- Detecting C compiler ABI info
81+
-- Detecting C compiler ABI info - done
82+
-- Check for working C compiler: C:/msys64/ucrt64/bin/gcc.exe - skipped
83+
-- Detecting C compile features
84+
-- Detecting C compile features - done
85+
-- Detecting CXX compiler ABI info
86+
-- Detecting CXX compiler ABI info - done
87+
-- Check for working CXX compiler: C:/msys64/ucrt64/bin/g++.exe - skipped
88+
-- Detecting CXX compile features
89+
-- Detecting CXX compile features - done
90+
-- Configuring done (3.4s)
91+
-- Generating done (0.1s)
92+
-- Build files have been written to: C:/Users/a5107948/cdt-main20250110b/runtime-cdtruntime_clean/cmake_hw/build/cmake.debug.win32.x86_64.Local
93+
Building in: C:\Users\a5107948\cdt-main20250110b\runtime-cdtruntime_clean\cmake_hw\build\cmake.debug.win32.x86_64.Local
94+
cmake --build . --target all
95+
[1/2] Building CXX object CMakeFiles/cmake_hw.dir/cmake_hw.cpp.obj
96+
[2/2] Linking CXX executable cmake_hw.exe
97+
Build complete (0 errors, 0 warnings): C:\Users\a5107948\cdt-main20250110b\runtime-cdtruntime_clean\cmake_hw\build\cmake.debug.win32.x86_64.Local
98+
99+
100+
101+
## Test case C) Clang toolchain can be used to build when CC/CXX defined externally to gcc/g++
102+
- Exit Eclipse and in a command shell, define the environment variables CC and CXX, for example on Windows:
103+
- - set CC=gcc
104+
- - set CXX=g++
105+
- Launch Eclipse from this command shell, so it inherits the environment.
106+
- From the Launch Bar, open the Launch Configuration (gear icon)
107+
- Select Build Settings tab and in the Toolchain dropdown, change to clang toolchain and click OK.
108+
- From the Launch Bar, build the project.
109+
110+
Expected: The project builds successfully and in the Console build output, it can be seen that the C and CXX compiler are identified as "Clang".
111+
112+
Actual: same output as Test case A).
113+
114+
## Test case D) GCC toolchain can be used to build when CC/CXX defined externally to clang/clang++
115+
- Exit Eclipse and in a command shell, define the environment variables CC and CXX, for example on Windows:
116+
- - set CC=clang
117+
- - set CXX=clang++
118+
- Launch Eclipse from this command shell, so it inherits the environment.
119+
- From the Launch Bar, open the Launch Configuration (gear icon)
120+
- Select Build Settings tab and in the Toolchain dropdown, change to gcc toolchain and click OK.
121+
- From the Launch Bar, build the project.
122+
123+
Expected: The project builds successfully and in the Console build output, it can be seen that the C and CXX compiler are identified as "gnu".
124+
125+
Actual: same output as Test case B).
126+
127+
----
128+
[1]: Before you begin
129+
C/C++ Development User Guide > Before you begin
130+
https://github.com/eclipse-cdt/cdt/blob/abe4d1b8e16b03ceafbeb25f063cb728c7487862/doc/org.eclipse.cdt.doc.user/concepts/cdt_c_before_you_begin.htm
131+
132+

0 commit comments

Comments
 (0)