[CMake] Problem with circular includes

Filipe Sousa filipe at ipb.pt
Thu Jul 27 18:29:07 EDT 2006


Marc-André Laverdière wrote:
> Dear CMakers,
> 
> I'm working on an extension to the standard C library and I'm porting to 
> home-brew makefiles to CMake. Not making much progress so far.
> 
> It looks like one hurdle is that we use stuff like #include "stdio.h", 
> which contains some extra definitions and then an include to the real 
> <stdio.h>.
> 
> Here is the interesting part of the CMakeLists.txt file I use:
> SUBDIRS(adapters stdio stdlib string test time wchar)
> 
> INCLUDE_DIRECTORIES(BEFORE . include stdio stdlib string test time wchar)
> 
> #add definitions, compiler switches, etc.
> ADD_DEFINITIONS(-I- -pipe -Wall -W -O3 -std=c99 -posix 
> -D__STDC_WANT_LIB_EXT1__ 1)
> 
> Now, if I have the -I-, the compiler whines that it can't find the file 
> (especially that the newer version doesn't like -I-). I narrowed it down 
> to the #include "stdio.h".
> Now, if I remove the -I-, I get a truckload of errors. My best guess is 
> that its trying to circularly find its include files withing mine.
> The makefiles I manually coded in the past digested -I- very well, so 
> this is an unenjoyed obstacle.
> 
> My guess is that I could rename our .h files and hope that there are not 
> too many references to fix, but that's not a very tempting option.
> 
> How can I resolve this situation using CMake? Will it be really portable?
> Is there an argument we can add in INCLUDE_DIRECTORIES to deal with the 
> situation cleanly (say, INCLUDE_DIRECTORIES(QUOTES ...) )?
> 
> With kind regards,
> 

It works here:

fsousa at neptuno ~/tmp/std $ tree
.
|-- CMakeLists.txt
|-- main.c
`-- stdio.h

0 directories, 3 files

fsousa at neptuno ~/tmp/std $ cat CMakeLists.txt
PROJECT(std C)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
ADD_DEFINITIONS(-I-)
ADD_EXECUTABLE(std main.c)

fsousa at neptuno ~/tmp/std $ cat main.c
#include "stdio.h"

int main() {
  return 0;
}

fsousa at neptuno ~/tmp/std $ cat stdio.h
#include <stdio.h>


fsousa at neptuno ~/tmp/std $ mkdir build
fsousa at neptuno ~/tmp/std $ cd build/
fsousa at neptuno ~/tmp/std/build $ cmake .. && make
-- Check for working C compiler: gcc
-- Check for working C compiler: gcc -- works
-- Check size of void*
-- Check size of void* - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/fsousa/tmp/std/build
Scanning dependencies of target std
[100%] Building C object CMakeFiles/std.dir/main.o
cc1: note: obsolete option -I- used, please use -iquote instead
Linking C executable std
[100%] Building target std

fsousa at neptuno ~/tmp/std/build $ cmake --version
cmake version 2.5-20060722

-- 
Filipe Sousa

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: OpenPGP digital signature
Url : http://public.kitware.com/pipermail/cmake/attachments/20060727/6bf1e6ee/signature-0001.pgp


More information about the CMake mailing list