views:

253

answers:

2

Hello,

I'm working with CMake, and my program compiles fine with g++. However, I also wish to compiled it with bcc32 and cl.

I am running into an issue -- I'm telling cmake to use those compilers by doing a command line somewhat like "cmake -DCMAKE_CXX_COMPILER=cl" or whatnot, and it picks up the compiler correctly (ie, in that case, the MSVC variable is set to true).

However, it still seems to be using the gnu command line arguments, which causes the compiler to fail on the CXX compiler test (ie, it tries to use -o to specify and output file for cl instead of /Fe, and instead of -e for bcc32).

Is there some proper way to specify which compiler to use, or some way to fix this?

+3  A: 

You must use the -G parameter which defines for which compiler the make files should be generated. Just start cmake --help to see which generators are available. For example, -G "Visual Studio 9 2008" will create makefiles for 32-bit Visual Studio 2008.

AndiDog
This confuses me slightly. From the man page, it seems that -G specifies a makefile generator -- I'm using GNU make to automate compilation, not MSVC projects or stuff. So what I want cmake to produce is something that I can run with gmake, but can use cl or bcc32 as the compiler.Or am I misinterpreting this? cmake --help doesn't mention anything about available visual studio generators.
Kozaki
AFAIK the only way to define `cl` as compiler is to create VS projects - which is what the "Visual Studio" generators will do for you. With normal GNU makefiles, you can only use GCC, MinGW, etc. but not cl.
AndiDog
A: 

You can use any compiler you want with the makefile generators, but it has to be specified by full path, or available in the PATH environment variable.

One thing that might be confusing you is that once a compiler is specified in a CMake build tree, there is no way to change it. You have to blow away the build tree and start over to use a new compiler. You cannot simply run cmake over again with a different -DCMAKE_CXX_COMPILER argument. Start from scratch...

We run CMake dashboards on some clients using gmake and cl and the "Unix Makefiles" generator. See the script that sets up such a build here:

http://www.cdash.org/CDash/viewNotes.php?buildid=581283

To see the results of running the script, replace "viewNotes" with "buildSummary" in the URL...

DLRdave