[CMake] How to create SOURCE_GROUP for include files
Steve Johns
steve.johns at verizon.net
Fri Jul 7 14:20:44 EDT 2006
> The source and header files will not magically be found in other
> directories. You have to tell CMake where to find them. Try this in the
> top-level CMakeLists.txt file:
>
> ADD_LIBRARY(mylib src/x.cpp incl/x.hpp)
> SOURCE_GROUP("Include Files" FILES incl/x.hpp)
>
> Basically source files have to be named with a relative path to the
> location of the CMakeLists.txt file. This may also work from
> lib/CMakeLists.txt:
>
> ADD_LIBRARY(mylib ../src/x.cpp ../incl/x.hpp)
> SOURCE_GROUP("Include Files" FILES ../incl/x.hpp)
>
It works both ways, thank you very much!
__
As an aside, I would add that the "simple example" off of the documentation
page starts one off in the habit of coding this:
ADD_LIBRARY(mylib ../src/x.cpp )
(which results in no "Header Files" group being created)
instead of this:
ADD_LIBRARY(mylib ../src/x.cpp ../incl/x.hpp)
(which results in a "Header Files" group being created for you )
One could read the example as implying that the .cpp dependence upon .hpp is
implied and "automagical".
What actually seems to be "automagical" is the creation of a "Header Files"
group when header files are explicitly listed as dependencies.
I grant that the example is not referring to header files because it is "so
simple" that header files are not even present at all. However, I think it
might actually save people some run-around (taking myself as a case in
point!) if the example were just slightly more complex to illustrate the
"useful and proper" inclusion of header files in dependency lists (my $.02
worth).
Thanks again for the assistance! :^)
More information about the CMake
mailing list