[CMake] Including a header file fails

Andreas Pakulat apaku at gmx.de
Mon Feb 28 18:26:17 EST 2011


On 28.02.11 16:55:12, Enrique Izaguirre wrote:
> Hello,
> 
> I am trying to include a windows header file in my build.
> The simplest way I found is to add the following in the main CMakeLists.txt
> file:
> 
> include_directories ("${MYPRJ_SOURCE_DIR}/../../../usr/include/w32api")
> add_library (w32api w32api/winbase.h)
> 
> add_executable (myprj ${hostFiles})
> target_link_libraries (myprj w32api)
> 
> 
> I am working in Cygwin, and my project is in /home/<my-user>/myprj, that's
> why I am using
> 
>  ${MYPRJ_SOURCE_DIR}/../../../usr/include/w32api
> 
> since "/" is the root in my cygwin system and the file I want is in
> /usr/include/w32api
> 
> but when running cmake I get the following error:
> 
> CMake Error in CMakeLists.txt:
>   Cannot find source file "winbase.h".  Tried extensions .c .C .c++ .cc .cpp
>   .cxx .m .M .mm .h .hh .h++ .hm .hpp .hxx .in .txx
> 
> I have not been able to find out what is going on. Could you help please?

There are several errors here:

1. you already added the w32api directory to the include-dirs, so you
don't need it in the add_library line
2. you're trying to build a library from a header file
3. you're adding files that are not part of your source code to your
targets
4. you're trying to link an executable against that header file, what
you really want is #include the header file in your sources and link to
whatever library provides the implementation for winbase.h

If you fix 4. you won't need to fix 1-3.

Andreas



More information about the CMake mailing list