Skip to content

Commit 7a5ac89

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 fe35b9f commit 7a5ac89

File tree

6 files changed

+858
-5
lines changed

6 files changed

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

0 commit comments

Comments
 (0)