[CMake] include_directories(SYSTEM, GNU.cmake and -isystem for C (not CXX)

Campbell Barton ideasman42 at gmail.com
Sat Jun 11 02:08:22 EDT 2011


To follow up on this, I tested this on a test project and found the
problem was in my own macro which wasn't initializing an include list.
So only the  set(CMAKE_INCLUDE_SYSTEM_FLAG_C "-isystem ") remains
which should be fixed in CMake but is easy to workaround.

On Thu, Jun 9, 2011 at 10:59 PM, Michael Hertling <mhertling at online.de> wrote:
> On 06/08/2011 07:26 AM, Campbell Barton wrote:
>> There were some system headers giving warnings compiling on linux,
>> since I like to have warnings as errors, and not edit system headers,
>> I used:
>>  include_directories(SYSTEM dir1 dir2 ...)
>> ... for system directories only.
>>
>> However this does not result in -isystem being used in C because
>> GNU.cmake does not set:
>>  set(CMAKE_INCLUDE_SYSTEM_FLAG_C "-isystem ")
>> ... as it does for C++.
>
> On my system, I can confirm that. AFAICS, it's caused by the macro
> "__compiler_gnu" in ${CMAKE_ROOT}/Modules/Compiler/GNU.cmake; this
> macro is parameterized with the argument "lang" for the language,
> but for the "-isystem" option, it reads
>
> set(CMAKE_INCLUDE_SYSTEM_FLAG_CXX "-isystem ")
>
> i.e., the "-isystem" option is enabled statically for C++ only,
> regardless of the "lang" argument. Shouldn't this line read
>
> set(CMAKE_INCLUDE_SYSTEM_FLAG_${lang} "-isystem ")
>
> instead, i.e. "-isystem" for each "lang"?
>
>> I tried adding this directly after the project(), call (beforehand it
>> fails to have any effect):
>>
>>       if(CMAKE_COMPILER_IS_GNUCC)
>>               if(NOT APPLE)
>>                       set(CMAKE_INCLUDE_SYSTEM_FLAG_C "-isystem ")
>>               endif()
>>       endif()
>>
>>
>> So now it almost works, but I've noticed that If
>> "include_directories(SYSTEM" is called after a non system include, ALL
>> includes then use -isystem.
>>
>> Putting "include_directories(SYSTEM" first mostly works out OK, but I
>> found a few cases where the order isn't so easy to set in our own
>> CMakeLists.txt and still incorrectly uses -isystem where it shouldn't.
>> Also found using the BEFORE / AFTER arguments to include_directories(
>> doesn't make any difference to the use of -isystem.
>
> This, however, I can't confirm. Could you provide an example?
>
>> Is this a known problem or is there a way to get this working?
>
> If you tweak the above-noted line in GNU.cmake, i.e. replace CXX with
> ${lang}, things work as expected at the first glance. This issue does
> not seem to be correct, so I think your bug report is justified.
>
> Regards,
>
> Michael
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
>



-- 
- Campbell


More information about the CMake mailing list