[cmake-developers] [CMake 0013096]: CMake Using Wrong Compiler

Mantis Bug Tracker mantis at public.kitware.com
Mon Apr 2 09:49:42 EDT 2012

The following issue has been SUBMITTED. 
Reported By:                sobigboy
Assigned To:                
Project:                    CMake
Issue ID:                   13096
Category:                   CMake
Reproducibility:            sometimes
Severity:                   minor
Priority:                   normal
Status:                     new
Date Submitted:             2012-04-02 09:49 EDT
Last Modified:              2012-04-02 09:49 EDT
Summary:                    CMake Using Wrong Compiler
When both the GNU and the Sun compilers are installed on the same server, and
when starting with a clean build, cMake is not always recognizing the Sun
compiler setting:


Instead, cMake is defaulting to the GNU compiler.

Steps to Reproduce: 
1.  Create an folder structure to support an in-source build which looks as
- Source
  - Build

2.  Create a single source file called hello.cpp containing a main() function
with a simple Hello output statement, and place it in the Source folder.

3.  Create a CMakeLists.txt file containing the following statements:

ADD_EXECUTABLE(hello hello.cpp)

4.  Run cMake from the Build folder using:
> cmake ../

Additional Information: 
After installing cMake, the first test build did not use the CMAKE_CXX_COMPILER
statement in the CMakeLists.txt file, and so cMake defaulted to the GNU
compiler.  (This behavior was not unexpected.)  The next clean build included
the CMAKE_CXX_COMPILER statement specifying the Sun compiler, and cMake did
successfully use the Sun compiler.  Subsequently, every build (some clean-some
not) always included the the CMAKE_CXX_COMPILER statement specifying the Sun
compiler, and for each of these builds cMake continued using the Sun compiler. 
At no time was the GNU compiler ever specified.  (I am the only cMake user.)

Several days later, beginning with a clean build, cMake mysteriously reverted
back to using the GNU compiler, despite that the CMakeLists.txt still included
the CMAKE_CXX_COMPILER statement specifying the Sun compiler.  Once cMake began
using the GNUCXX compiler, nothing could make it use the Sun compiler, including
the methods recommended in the cMake FAQ.  Finally, the only solution that
worked was removing the GNU compiler from the Path statement in one's .profile

After doing this, cMake began recognizing the Sun compiler in the
CMAKE_CXX_COMPILER statement again.  Then, as a test, I modified the .profile
file and re-entered the path to the GNUCXX compiler.  This caused cMake to once
again ignore the CMAKE_CXX_COMPILER statement and use the GNUCXX compiler.  It
made no difference whether I did an in-source build or out-source build.


Issue History 
Date Modified    Username       Field                    Change               
2012-04-02 09:49 sobigboy       New Issue                                    

More information about the cmake-developers mailing list