I've just started using CMake for some personal and school projects, and I've been stumped by a minor issue.
Let's say I'm trying to get a C++ program compiling under multiple compilers (g++, cl, and bcc32 in this case). I have different command line switches for each compiler, and what I was attempting to do was to basically make a gnu/ms/borland directory and create CMake stuff in there (by entering the directories and doing a cmake -DCMAKE_CXX_COMPILER=g++
.. in the gnu, directory, for instance).
In the CMakeLists.txt on the top level directory, I tried doing something along the lines of:
if(CMAKE_CXX_COMPILER STREQUAL g++)
set(CMAKE_CXX_FLAGS "-Wextra -Wall -ansi -pedantic")
And so on with elsifs for the other compilers, but this doesn't seem to work correctly -- it drops the CXXFLAGS
entirely. The line works if I make the file completely unconditional (ie, just assume g++ and use g++ flags.).
What am I doing wrong here, or is there a better way to handle this sort of a problem?