diff --git a/src/plugins/cmakeprojectmanager/cmakebuildenvironmentwidget.cpp b/src/plugins/cmakeprojectmanager/cmakebuildenvironmentwidget.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..99526421fbf1ff833f2dfe9f0e9122b56b13f0e1
--- /dev/null
+++ b/src/plugins/cmakeprojectmanager/cmakebuildenvironmentwidget.cpp
@@ -0,0 +1,84 @@
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact:  Qt Software Information (qt-info@nokia.com)
+**
+** Commercial Usage
+**
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+**
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+**
+**************************************************************************/
+
+#include "cmakebuildenvironmentwidget.h"
+#include "cmakeproject.h"
+#include <projectexplorer/environmenteditmodel.h>
+#include <QtGui/QVBoxLayout>
+
+namespace {
+bool debug = false;
+}
+
+using namespace CMakeProjectManager;
+using namespace CMakeProjectManager::Internal;
+using ProjectExplorer::EnvironmentModel;
+
+CMakeBuildEnvironmentWidget::CMakeBuildEnvironmentWidget(CMakeProject *project)
+    : BuildStepConfigWidget(), m_pro(project)
+{
+    QVBoxLayout *vbox = new QVBoxLayout(this);
+    vbox->setMargin(0);
+    m_buildEnvironmentWidget = new ProjectExplorer::EnvironmentWidget(this);
+    vbox->addWidget(m_buildEnvironmentWidget);
+
+    connect(m_buildEnvironmentWidget, SIGNAL(userChangesUpdated()),
+            this, SLOT(environmentModelUserChangesUpdated()));
+    connect(m_buildEnvironmentWidget, SIGNAL(clearSystemEnvironmentCheckBoxClicked(bool)),
+            this, SLOT(clearSystemEnvironmentCheckBoxClicked(bool)));
+}
+
+QString CMakeBuildEnvironmentWidget::displayName() const
+{
+    return tr("Build Environment");
+}
+
+void CMakeBuildEnvironmentWidget::init(const QString &buildConfiguration)
+{
+    if (debug)
+        qDebug() << "Qt4BuildConfigWidget::init()";
+
+    m_buildConfiguration = buildConfiguration;
+
+    m_buildEnvironmentWidget->setClearSystemEnvironment(!m_pro->useSystemEnvironment(buildConfiguration));
+    m_buildEnvironmentWidget->setBaseEnvironment(m_pro->baseEnvironment(buildConfiguration));
+    m_buildEnvironmentWidget->setUserChanges(m_pro->userEnvironmentChanges(buildConfiguration));
+    m_buildEnvironmentWidget->updateButtons();
+}
+
+void CMakeBuildEnvironmentWidget::environmentModelUserChangesUpdated()
+{
+    m_pro->setUserEnvironmentChanges(m_buildConfiguration, m_buildEnvironmentWidget->userChanges());
+}
+
+void CMakeBuildEnvironmentWidget::clearSystemEnvironmentCheckBoxClicked(bool checked)
+{
+    m_pro->setUseSystemEnvironment(m_buildConfiguration, !checked);
+    m_buildEnvironmentWidget->setBaseEnvironment(m_pro->baseEnvironment(m_buildConfiguration));
+}
diff --git a/src/plugins/cmakeprojectmanager/cmakebuildenvironmentwidget.h b/src/plugins/cmakeprojectmanager/cmakebuildenvironmentwidget.h
new file mode 100644
index 0000000000000000000000000000000000000000..db59b2c5dfeb116e747c56632dce725855c25dec
--- /dev/null
+++ b/src/plugins/cmakeprojectmanager/cmakebuildenvironmentwidget.h
@@ -0,0 +1,66 @@
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact:  Qt Software Information (qt-info@nokia.com)
+**
+** Commercial Usage
+**
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+**
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+**
+**************************************************************************/
+
+#ifndef QT4BUILDENVIRONMENTWIDGET_H
+#define QT4BUILDENVIRONMENTWIDGET_H
+
+#include <projectexplorer/buildstep.h>
+
+namespace ProjectExplorer {
+class EnvironmentWidget;
+}
+
+namespace CMakeProjectManager {
+namespace Internal {
+class CMakeProject;
+
+class CMakeBuildEnvironmentWidget : public ProjectExplorer::BuildStepConfigWidget
+{
+    Q_OBJECT
+
+public:
+    CMakeBuildEnvironmentWidget(CMakeProject *project);
+
+    QString displayName() const;
+    void init(const QString &buildConfiguration);
+
+private slots:
+    void environmentModelUserChangesUpdated();
+    void clearSystemEnvironmentCheckBoxClicked(bool checked);
+
+private:
+    ProjectExplorer::EnvironmentWidget *m_buildEnvironmentWidget;
+    CMakeProject *m_pro;
+    QString m_buildConfiguration;
+};
+
+} // namespace Internal
+} // namespace Qt4ProjectManager
+
+#endif // QT4BUILDENVIRONMENTWIDGET_H
diff --git a/src/plugins/cmakeprojectmanager/cmakeproject.cpp b/src/plugins/cmakeprojectmanager/cmakeproject.cpp
index 3b71d8c8b6f41ac5b19f49f1c7f025439965d2ac..8eb1415f8351d219606bc871606c1ff8e0b2d8b8 100644
--- a/src/plugins/cmakeprojectmanager/cmakeproject.cpp
+++ b/src/plugins/cmakeprojectmanager/cmakeproject.cpp
@@ -33,6 +33,7 @@
 #include "cmakerunconfiguration.h"
 #include "makestep.h"
 #include "cmakeopenprojectwizard.h"
+#include "cmakebuildenvironmentwidget.h"
 
 #include <projectexplorer/projectexplorerconstants.h>
 #include <cpptools/cppmodelmanagerinterface.h>
@@ -50,7 +51,8 @@
 
 using namespace CMakeProjectManager;
 using namespace CMakeProjectManager::Internal;
-
+using ProjectExplorer::Environment;
+using ProjectExplorer::EnvironmentItem;
 
 // QtCreator CMake Generator wishlist:
 // Which make targets we need to build to get all executables
@@ -62,7 +64,6 @@ using namespace CMakeProjectManager::Internal;
 // Who sets up the environment for cl.exe ? INCLUDEPATH and so on
 
 
-
 CMakeProject::CMakeProject(CMakeManager *manager, const QString &fileName)
     : m_manager(manager),
       m_fileName(fileName),
@@ -436,11 +437,38 @@ bool CMakeProject::isApplication() const
     return true;
 }
 
+ProjectExplorer::Environment CMakeProject::baseEnvironment(const QString &buildConfiguration) const
+{
+    Environment env = useSystemEnvironment(buildConfiguration) ? Environment(QProcess::systemEnvironment()) : Environment();
+    return env;
+}
+
 ProjectExplorer::Environment CMakeProject::environment(const QString &buildConfiguration) const
 {
-    Q_UNUSED(buildConfiguration)
-    //TODO CMakeProject::Environment;
-    return ProjectExplorer::Environment::systemEnvironment();
+    Environment env = baseEnvironment(buildConfiguration);
+    env.modify(userEnvironmentChanges(buildConfiguration));
+    return env;
+}
+
+void CMakeProject::setUseSystemEnvironment(const QString &buildConfiguration, bool b)
+{
+    setValue(buildConfiguration, "clearSystemEnvironment", !b);
+}
+
+bool CMakeProject::useSystemEnvironment(const QString &buildConfiguration) const
+{
+    bool b = !(value(buildConfiguration, "clearSystemEnvironment").isValid() && value(buildConfiguration, "clearSystemEnvironment").toBool());
+    return b;
+}
+
+QList<ProjectExplorer::EnvironmentItem> CMakeProject::userEnvironmentChanges(const QString &buildConfig) const
+{
+    return EnvironmentItem::fromStringList(value(buildConfig, "userEnvironmentChanges").toStringList());
+}
+
+void CMakeProject::setUserEnvironmentChanges(const QString &buildConfig, const QList<ProjectExplorer::EnvironmentItem> &diff)
+{
+    setValue(buildConfig, "userEnvironmentChanges", EnvironmentItem::toStringList(diff));
 }
 
 QString CMakeProject::buildDirectory(const QString &buildConfiguration) const
@@ -458,7 +486,9 @@ ProjectExplorer::BuildStepConfigWidget *CMakeProject::createConfigWidget()
 
 QList<ProjectExplorer::BuildStepConfigWidget*> CMakeProject::subConfigWidgets()
 {
-    return QList<ProjectExplorer::BuildStepConfigWidget*>();
+    QList<ProjectExplorer::BuildStepConfigWidget*> list;
+    list <<  new CMakeBuildEnvironmentWidget(this);
+    return list;
 }
 
 // This method is called for new build configurations
diff --git a/src/plugins/cmakeprojectmanager/cmakeproject.h b/src/plugins/cmakeprojectmanager/cmakeproject.h
index b8ec6a0215f21e10d54a0be4c89307d2a4f56bb9..e8964db982449b18dfb7394595ba5ead6da11dec 100644
--- a/src/plugins/cmakeprojectmanager/cmakeproject.h
+++ b/src/plugins/cmakeprojectmanager/cmakeproject.h
@@ -79,7 +79,14 @@ public:
 
     virtual bool isApplication() const;
 
-    virtual ProjectExplorer::Environment environment(const QString &buildConfiguration) const;
+    //building environment
+    ProjectExplorer::Environment environment(const QString &buildConfiguration) const;
+    ProjectExplorer::Environment baseEnvironment(const QString &buildConfiguration) const;
+    void setUserEnvironmentChanges(const QString &buildConfig, const QList<ProjectExplorer::EnvironmentItem> &diff);
+    QList<ProjectExplorer::EnvironmentItem> userEnvironmentChanges(const QString &buildConfig) const;
+    bool useSystemEnvironment(const QString &buildConfiguration) const;
+    void setUseSystemEnvironment(const QString &buildConfiguration, bool b);
+
     virtual QString buildDirectory(const QString &buildConfiguration) const;
 
     virtual ProjectExplorer::BuildStepConfigWidget *createConfigWidget();
diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.pro b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.pro
index c851b79fd1fde423f61386c243c1210b13389d85..fe516111f6e24d37be03b3d5b24de5ab9cbacfa9 100644
--- a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.pro
+++ b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.pro
@@ -9,14 +9,16 @@ HEADERS = cmakeproject.h \
     cmakeprojectnodes.h \
     makestep.h \
     cmakerunconfiguration.h \
-    cmakeopenprojectwizard.h
+    cmakeopenprojectwizard.h \
+    cmakebuildenvironmentwidget.h
 SOURCES = cmakeproject.cpp \
     cmakeprojectplugin.cpp \
     cmakeprojectmanager.cpp \
     cmakeprojectnodes.cpp \
     makestep.cpp \
     cmakerunconfiguration.cpp \
-    cmakeopenprojectwizard.cpp
+    cmakeopenprojectwizard.cpp \
+    cmakebuildenvironmentwidget.cpp
 RESOURCES += cmakeproject.qrc
 FORMS += 
 
diff --git a/src/plugins/cmakeprojectmanager/cmakerunconfiguration.cpp b/src/plugins/cmakeprojectmanager/cmakerunconfiguration.cpp
index 6e013c77f827f8deffc2b85eaed2072a10d6266c..08fa7c1d07b4b81d2af712c4c2ef9f45bf2a99ed 100644
--- a/src/plugins/cmakeprojectmanager/cmakerunconfiguration.cpp
+++ b/src/plugins/cmakeprojectmanager/cmakerunconfiguration.cpp
@@ -82,8 +82,7 @@ QStringList CMakeRunConfiguration::commandLineArguments() const
 
 ProjectExplorer::Environment CMakeRunConfiguration::environment() const
 {
-    // TODO have a way for the user to setup the environment
-    return ProjectExplorer::Environment::systemEnvironment();
+    return project()->environment(project()->activeBuildConfiguration());
 }
 
 QString CMakeRunConfiguration::title() const
diff --git a/src/plugins/qt4projectmanager/qt4buildenvironmentwidget.cpp b/src/plugins/qt4projectmanager/qt4buildenvironmentwidget.cpp
index 1d5bfd1e704098bbe5dfaa99018bfe7d7b916f2a..c7b51997255b315f1aceab3ef499d7c9cb14d869 100644
--- a/src/plugins/qt4projectmanager/qt4buildenvironmentwidget.cpp
+++ b/src/plugins/qt4projectmanager/qt4buildenvironmentwidget.cpp
@@ -28,8 +28,6 @@
 **************************************************************************/
 
 #include "qt4buildenvironmentwidget.h"
-
-#include "ui_qt4buildenvironmentwidget.h"
 #include "qt4project.h"
 
 #include <projectexplorer/environmenteditmodel.h>
@@ -56,11 +54,6 @@ Qt4BuildEnvironmentWidget::Qt4BuildEnvironmentWidget(Qt4Project *project)
             this, SLOT(clearSystemEnvironmentCheckBoxClicked(bool)));
 }
 
-Qt4BuildEnvironmentWidget::~Qt4BuildEnvironmentWidget()
-{
-
-}
-
 QString Qt4BuildEnvironmentWidget::displayName() const
 {
     return tr("Build Environment");
diff --git a/src/plugins/qt4projectmanager/qt4buildenvironmentwidget.h b/src/plugins/qt4projectmanager/qt4buildenvironmentwidget.h
index b139704707c3313a022035b99c67f61192b86272..6a8396811cfd545db13835b2ebd8ba02ec655020 100644
--- a/src/plugins/qt4projectmanager/qt4buildenvironmentwidget.h
+++ b/src/plugins/qt4projectmanager/qt4buildenvironmentwidget.h
@@ -47,7 +47,6 @@ class Qt4BuildEnvironmentWidget : public ProjectExplorer::BuildStepConfigWidget
 
 public:
     Qt4BuildEnvironmentWidget(Qt4Project *project);
-    ~Qt4BuildEnvironmentWidget();
 
     QString displayName() const;
     void init(const QString &buildConfiguration);
diff --git a/src/plugins/qt4projectmanager/qt4buildenvironmentwidget.ui b/src/plugins/qt4projectmanager/qt4buildenvironmentwidget.ui
deleted file mode 100644
index 45c4c906a245f89b7398b99425bd425583f74f87..0000000000000000000000000000000000000000
--- a/src/plugins/qt4projectmanager/qt4buildenvironmentwidget.ui
+++ /dev/null
@@ -1,90 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
- <class>Qt4ProjectManager::Internal::Qt4BuildEnvironmentWidget</class>
- <widget class="QWidget" name="Qt4ProjectManager::Internal::Qt4BuildEnvironmentWidget">
-  <property name="geometry">
-   <rect>
-    <x>0</x>
-    <y>0</y>
-    <width>400</width>
-    <height>300</height>
-   </rect>
-  </property>
-  <layout class="QVBoxLayout" name="verticalLayout">
-   <item>
-    <widget class="QCheckBox" name="clearSystemEnvironmentCheckBox">
-     <property name="text">
-      <string>Clear system environment</string>
-     </property>
-    </widget>
-   </item>
-   <item>
-    <layout class="QHBoxLayout" name="horizontalLayout">
-     <item>
-      <widget class="QTreeView" name="environmentTreeView">
-       <property name="rootIsDecorated">
-        <bool>false</bool>
-       </property>
-       <property name="headerHidden">
-        <bool>false</bool>
-       </property>
-      </widget>
-     </item>
-     <item>
-      <layout class="QVBoxLayout" name="verticalLayout_2">
-       <item>
-        <widget class="QPushButton" name="editButton">
-         <property name="text">
-          <string>&amp;Edit</string>
-         </property>
-        </widget>
-       </item>
-       <item>
-        <widget class="QPushButton" name="addButton">
-         <property name="text">
-          <string>&amp;Add</string>
-         </property>
-        </widget>
-       </item>
-       <item>
-        <widget class="QPushButton" name="removeButton">
-         <property name="enabled">
-          <bool>false</bool>
-         </property>
-         <property name="text">
-          <string>&amp;Reset</string>
-         </property>
-        </widget>
-       </item>
-       <item>
-        <widget class="QPushButton" name="unsetButton">
-         <property name="enabled">
-          <bool>false</bool>
-         </property>
-         <property name="text">
-          <string>&amp;Unset</string>
-         </property>
-        </widget>
-       </item>
-       <item>
-        <spacer name="verticalSpacer">
-         <property name="orientation">
-          <enum>Qt::Vertical</enum>
-         </property>
-         <property name="sizeHint" stdset="0">
-          <size>
-           <width>20</width>
-           <height>40</height>
-          </size>
-         </property>
-        </spacer>
-       </item>
-      </layout>
-     </item>
-    </layout>
-   </item>
-  </layout>
- </widget>
- <resources/>
- <connections/>
-</ui>
diff --git a/src/plugins/qt4projectmanager/qt4project.cpp b/src/plugins/qt4projectmanager/qt4project.cpp
index ebdbf43d3fe4401dfc2f9d6560e0066c30789c21..80f2c6f22176bad4d2b745fc1697976f635a5109 100644
--- a/src/plugins/qt4projectmanager/qt4project.cpp
+++ b/src/plugins/qt4projectmanager/qt4project.cpp
@@ -698,6 +698,16 @@ Qt4ProFileNode *Qt4Project::rootProjectNode() const
     return m_rootProjectNode;
 }
 
+QString Qt4Project::buildDirectory(const QString &buildConfiguration) const
+{
+    QString workingDirectory;
+    if (value(buildConfiguration, "useShadowBuild").toBool())
+        workingDirectory = value(buildConfiguration, "buildDirectory").toString();
+    if (workingDirectory.isEmpty())
+        workingDirectory = QFileInfo(file()->fileName()).absolutePath();
+    return workingDirectory;
+}
+
 ProjectExplorer::Environment Qt4Project::baseEnvironment(const QString &buildConfiguration) const
 {
     Environment env = useSystemEnvironment(buildConfiguration) ? Environment(QProcess::systemEnvironment()) : Environment();
@@ -712,16 +722,6 @@ ProjectExplorer::Environment Qt4Project::environment(const QString &buildConfigu
     return env;
 }
 
-QString Qt4Project::buildDirectory(const QString &buildConfiguration) const
-{
-    QString workingDirectory;
-    if (value(buildConfiguration, "useShadowBuild").toBool())
-        workingDirectory = value(buildConfiguration, "buildDirectory").toString();
-    if (workingDirectory.isEmpty())
-        workingDirectory = QFileInfo(file()->fileName()).absolutePath();
-    return workingDirectory;
-}
-
 void Qt4Project::setUseSystemEnvironment(const QString &buildConfiguration, bool b)
 {
     setValue(buildConfiguration, "clearSystemEnvironment", !b);
@@ -733,6 +733,16 @@ bool Qt4Project::useSystemEnvironment(const QString &buildConfiguration) const
     return b;
 }
 
+QList<ProjectExplorer::EnvironmentItem> Qt4Project::userEnvironmentChanges(const QString &buildConfig) const
+{
+    return EnvironmentItem::fromStringList(value(buildConfig, "userEnvironmentChanges").toStringList());
+}
+
+void Qt4Project::setUserEnvironmentChanges(const QString &buildConfig, const QList<ProjectExplorer::EnvironmentItem> &diff)
+{
+    setValue(buildConfig, "userEnvironmentChanges", EnvironmentItem::toStringList(diff));
+}
+
 QString Qt4Project::qtDir(const QString &buildConfiguration) const
 {
     QtVersion *version = qtVersion(buildConfiguration);
@@ -802,16 +812,6 @@ QList<BuildStepConfigWidget*> Qt4Project::subConfigWidgets()
     return subWidgets;
 }
 
-QList<ProjectExplorer::EnvironmentItem> Qt4Project::userEnvironmentChanges(const QString &buildConfig) const
-{
-    return EnvironmentItem::fromStringList(value(buildConfig, "userEnvironmentChanges").toStringList());
-}
-
-void Qt4Project::setUserEnvironmentChanges(const QString &buildConfig, const QList<ProjectExplorer::EnvironmentItem> &diff)
-{
-    setValue(buildConfig, "userEnvironmentChanges", EnvironmentItem::toStringList(diff));
-}
-
 /// **************************
 /// Qt4ProjectBuildConfigWidget
 /// **************************
diff --git a/src/plugins/qt4projectmanager/qt4project.h b/src/plugins/qt4projectmanager/qt4project.h
index d89158737a1d74e02b0d60a5446d82034edeb66e..e4d5e9205ea300a126b8fd6fa67f0a756946366d 100644
--- a/src/plugins/qt4projectmanager/qt4project.h
+++ b/src/plugins/qt4projectmanager/qt4project.h
@@ -143,13 +143,10 @@ public:
     ProjectExplorer::Environment baseEnvironment(const QString &buildConfiguration) const;
     void setUserEnvironmentChanges(const QString &buildConfig, const QList<ProjectExplorer::EnvironmentItem> &diff);
     QList<ProjectExplorer::EnvironmentItem> userEnvironmentChanges(const QString &buildConfig) const;
-
-    virtual QString buildDirectory(const QString &buildConfiguration) const;
-
-    //Qt4Project specific(?)
     bool useSystemEnvironment(const QString &buildConfiguration) const;
     void setUseSystemEnvironment(const QString &buildConfiguration, bool b);
 
+    virtual QString buildDirectory(const QString &buildConfiguration) const;
     // returns the CONFIG variable from the .pro file
     QStringList qmakeConfig() const;
     // returns the qtdir (depends on the current QtVersion)
diff --git a/src/plugins/qt4projectmanager/qt4projectmanager.pro b/src/plugins/qt4projectmanager/qt4projectmanager.pro
index a128681f17cb915a750c6268663ed372d86825fd..8be3a9e61377ec85d35822e19139a0f3fd6999fe 100644
--- a/src/plugins/qt4projectmanager/qt4projectmanager.pro
+++ b/src/plugins/qt4projectmanager/qt4projectmanager.pro
@@ -77,7 +77,6 @@ FORMS = makestep.ui \
     qmakestep.ui \
     qt4projectconfigwidget.ui \
     embeddedpropertiespage.ui \
-    qt4buildenvironmentwidget.ui \
     qtversionmanager.ui \
     showbuildlog.ui
 RESOURCES = qt4projectmanager.qrc \