[CMake] overruling compiler fails to work

J.S. van Bethlehem j.s.van.bethlehem at astro.rug.nl
Fri May 6 06:32:41 EDT 2011


Myles English wrote:
> On 6 May 2011 11:00, J.S. van Bethlehem <j.s.van.bethlehem at astro.rug.nl> wrote:
>   
>> Hello everybody,
>>
>> Let me say from the get-going: this is the worst question I could ask on
>> this list because I'm pretty sure I don't provide enough information for a
>> solution and the problem is likely not with CMake, but I can't think of
>> anything else currently, so I'll give it a go anyway, hoping that someone
>> recognizes the symptoms.
>>
>> In my lists-files I write currently at the very top:
>> if (NOT CMAKE_CXX_COMPILER)
>>  set(CMAKE_CXX_COMPILER g++-4.6)
>> endif(NOT CMAKE_CXX_COMPILER)
>>
>> It seems a bit contrived, but I use a lot of c++0x-stuff, the compiler on
>> the system is still at version 4.4 and so I have to rely on a local
>> installation of the more recent compiler. The if()-construct is there to
>> allow setting the variable through the environment or on the cmdline. This
>> worked fine for me, until this morning. I seemed to have changed something
>> that causes CMake to miss this. But AFAICS I didn't change anything to the
>> CMake-installation or to the lists-file(s) or to any part of my system for
>> that matter. Well.... obviously I'm overlooking something. I put a message()
>> before this construct and the output of that command appears right after all
>> the standard messages regarding compilers (but used to appear before it - I
>> know that for sure, because when I started to learn CMake I put a similar
>> message there to test the construct I created):
>> -- The C compiler identification is GNU
>> -- The CXX compiler identification is GNU
>> -- Check for working C compiler: /usr/bin/gcc
>> -- Check for working C compiler: /usr/bin/gcc -- works
>> -- Detecting C compiler ABI info
>> -- Detecting C compiler ABI info - done
>> -- Check for working CXX compiler: /usr/bin/c++
>> -- Check for working CXX compiler: /usr/bin/c++ -- works
>> -- Detecting CXX compiler ABI info
>> -- Detecting CXX compiler ABI info - done
>> -- Compiler = /usr/bin/c++   #   <- result of message(STATUS "Compiler =
>> ${CMAKE_CXX_COMPILER}") in front of the if()-construct
>> ...
>>
>> Again: I'm well aware that I don't nearly provide enough info about this.
>> And odds are almost certain that no one can 'guess' what I'm overlooking
>> here. My hope is just that by chance someone came across a similar situation
>> and did manage to figure out what is going on. Hopefully that was the same
>> mistake I'm making....
>>
>> Yours sincerely,
>> Jakob van Bethlehem
>>
>>     
> Hi Jakob,
>
> What if you comment out the 'if' and 'endif' lines?
>
> Myles
>
>   
Thanks a lot for the quick reply. That didn't really help. But in the 
meantime I did figure out what was the cause. Kind of funny how simply 
writing something up sometimes helps in determining the cause of a 
problem. So there was one thing that I changed between yesterday and 
today: I created a macro for setting up a whole bunch of variables in a 
given project. Since I was writing the same set of lines repeatedly, I 
figured I could just as well put them in a macro. So 'before' my 
lists-file had right after the if() construct:
project(project_name)

Then I changed the call to the project() command to the macro, so 
'after' my lists-file has after the if()-construct:
make_project(project_name)

and in my macro-file I have:
macro(make_project PNAME)
 project(${PNAME})
 # other stuff
endmacro(make_project)

So it seems that to CMake project() does not only set a project-name and 
some corresponding variables but it also affects the way CMake parses. 
I'm guessing here, but to me it looks as if CMake somehow adds special 
meaning to the file that has the project() command in it when parsing a 
project. Whatever the cause: my problem is fixed - thanks to everyone 
who took some time to think this one over.
Remains one question though: is this actually a bug, or is this a 
feature (I'm at version 2.8.4), which is not properly documented yet 
(documentation is kind of scattered in different places, but I'd expect 
at least some remark in the documentation generated from cmake 
--help-html?)

Yours sincerely,
Jakob




More information about the CMake mailing list