Re: [CMake] Prefix header for Makefiles

2015-08-26 Thread Bill Hoffman
CMake does not really support this.  At build time CMake scans the 
source files and builds the depend list.  Since your file is not 
actually included it does not end up in the depend list.  To add this as 
a feature you would have to put the information into DependInfo.cmake 
and have cmDependsC.cxx read the information.  If you are interested, I 
would suggest you come up with a patch and post it to the 
cmake-developer mailing list.  You could also try the ninja generator as 
it uses the compiler to compute depends and should have the correct 
information.


-Bill

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake


Re: [CMake] Prefix header for Makefiles

2015-08-26 Thread Andreas Pakulat
Hi,

On Wed, Aug 26, 2015 at 3:10 PM, Jakob van Bethlehem 
jsvanbethle...@gmail.com wrote:

 Hej Andrew,

 CMake does never scan source files (as far as I know), as it is not a
 compiler. From your question it almost seem you are making this assumption,
 so I just wanted to make sure to mention at least this.


Thats wrong, CMake has to parse the source files you add to a target to be
able to determine its dependencies (recursively) so it can generate
makefile rules that ensure that if one of the (indirectly) included headers
changes the source file is recompiled. You can see this in cmDependsC.cxx
in the CMake sources for C (and possibly C++) source files.

It of course does not parse the C/C++ code, it merely finds lines that
start with #include or #import and figures out the absolute path of the
mentioned header file based on the targets include directories.

Of course you can help CMake here by specifying all headers in the
add_executable/add_library call, but that easily ends up being a
maintenance nightmare for files outside of your actual project (system
headers, third-party libraries etc.).

Andreas
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

Re: [CMake] Prefix header for Makefiles

2015-08-26 Thread CHEVRIER, Marc
Hi,

You are wrong. CMake, during configuration/generation phase generates 
dependencies over C/C++ files.
So, the simple approach to handle dependency between Cpp and h files is to let 
CMake handle it:

add_executable (my_exe Main.cpp)

And, that it! By default current source directory is passed to the compiler for 
resolving #include directives.
And for adding other directories, use command target_include_directories.

Marc

From: CMake on behalf of Jakob van Bethlehem
Date: Wednesday 26 August 2015 15:10
To: cmake@cmake.orgmailto:cmake@cmake.org
Subject: Re: [CMake] Prefix header for Makefiles

Hej Andrew,

CMake does never scan source files (as far as I know), as it is not a compiler. 
From your question it almost seem you are making this assumption, so I just 
wanted to make sure to mention at least this.

Then, for your particular issue: two things that come to my mind:
* I’d imagine you have somewhere a add_executable(main Main.cpp Prefix.h 
DependHeader.h) - as far as I can tell, the only thing that really matters, is 
that the main executable gets recompiled whenever you make a change in any of 
the headers. To put it differently, I *don’t* think you (should) need the 
OBJECT_DEPENDS.
* If you’re worried about scaling, maybe you could have a look at the file(GLOB 
) command. However, be sure to also carefully read the potential problems with 
that approach. In my current (big) project, we explicitly list each source file 
for most parts of the source tree. In practice you’re surely *not* going to add 
all 50 new files at once. It is a very simple thing to add the newly created 
file to some variable in the correct CMakeLists.txt file. You just have to 
remember to do it, it’s really not a big deal.

By the way, we’re actually using the PrecompiledHeader script - it works 
flawlessly.

Sincerely, Jakob

On 26 Aug 2015, at 11:48, Andrew Shaitorov 
andrew.shaito...@gmail.commailto:andrew.shaito...@gmail.com wrote:

Hi All!

I have a very annoying problem with CMake Makefiles generator.

I'm using prefix header (see attached archive for minimized test).

There is one source file named Main.cpp and two header files: Prefix.h and 
DependHeader.h. Prefix.h includes DependHeader.h and Main.cpp includes Prefix.h 
by using prefix header compiler flag (-include for GCC/Clang and /FI for MSVC):

set_source_files_properties(Main.cpp PROPERTIES
COMPILE_FLAGS -include Prefix.h
OBJECT_DEPENDS ${CMAKE_CURRENT_LIST_DIR}/Prefix.h)

When I change Prefix.h, then make recompiles Main.cpp as needed. But when I 
make a change in DependHeader.h, then no recompilation happens. Its clear for 
me that I have to specify all depend files in OBJECT_DEPENDS option, but in 
real project there may be a lot of depend files with nested includes. And the 
most annoying thing is that the project compiles without any errors and may 
just crash because of struct layout or other critical changes in depend headers.

I seems like the following script have the same problem when using 
FORCE_INCLUDE option:

https://github.com/larsch/cmake-precompiled-header/blob/master/PrecompiledHeader.cmake

I looked in CMake source code and didn't find a way to add Prefix.h in a list 
for dependency scanning. Also I don't know how to run depend scanner on 
Prefix.h in CMake script to generate a list of all depend files for 
OBJECT_DEPENDS option.

Any advise?

Best,
Andrew.

CMakePrefixHeaderTest.zip--

Powered by www.kitware.comhttp://www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

Re: [CMake] Prefix header for Makefiles

2015-08-26 Thread Jakob van Bethlehem
Hej Andrew,

CMake does never scan source files (as far as I know), as it is not a compiler. 
From your question it almost seem you are making this assumption, so I just 
wanted to make sure to mention at least this.

Then, for your particular issue: two things that come to my mind:
* I’d imagine you have somewhere a add_executable(main Main.cpp Prefix.h 
DependHeader.h) - as far as I can tell, the only thing that really matters, is 
that the main executable gets recompiled whenever you make a change in any of 
the headers. To put it differently, I *don’t* think you (should) need the 
OBJECT_DEPENDS.
* If you’re worried about scaling, maybe you could have a look at the file(GLOB 
) command. However, be sure to also carefully read the potential problems with 
that approach. In my current (big) project, we explicitly list each source file 
for most parts of the source tree. In practice you’re surely *not* going to add 
all 50 new files at once. It is a very simple thing to add the newly created 
file to some variable in the correct CMakeLists.txt file. You just have to 
remember to do it, it’s really not a big deal.

By the way, we’re actually using the PrecompiledHeader script - it works 
flawlessly.

Sincerely, Jakob 

 On 26 Aug 2015, at 11:48, Andrew Shaitorov andrew.shaito...@gmail.com wrote:
 
 Hi All!
 
 I have a very annoying problem with CMake Makefiles generator.
 
 I'm using prefix header (see attached archive for minimized test).
 
 There is one source file named Main.cpp and two header files: Prefix.h and 
 DependHeader.h. Prefix.h includes DependHeader.h and Main.cpp includes 
 Prefix.h by using prefix header compiler flag (-include for GCC/Clang and /FI 
 for MSVC):
 
   set_source_files_properties(Main.cpp PROPERTIES
   COMPILE_FLAGS -include Prefix.h
   OBJECT_DEPENDS ${CMAKE_CURRENT_LIST_DIR}/Prefix.h)
 
 When I change Prefix.h, then make recompiles Main.cpp as needed. But when I 
 make a change in DependHeader.h, then no recompilation happens. Its clear for 
 me that I have to specify all depend files in OBJECT_DEPENDS option, but in 
 real project there may be a lot of depend files with nested includes. And the 
 most annoying thing is that the project compiles without any errors and may 
 just crash because of struct layout or other critical changes in depend 
 headers.
 
 I seems like the following script have the same problem when using 
 FORCE_INCLUDE option:
 
 https://github.com/larsch/cmake-precompiled-header/blob/master/PrecompiledHeader.cmake
  
 https://github.com/larsch/cmake-precompiled-header/blob/master/PrecompiledHeader.cmake
 
 I looked in CMake source code and didn't find a way to add Prefix.h in a list 
 for dependency scanning. Also I don't know how to run depend scanner on 
 Prefix.h in CMake script to generate a list of all depend files for 
 OBJECT_DEPENDS option.
 
 Any advise?
 
 Best,
 Andrew.
 
 CMakePrefixHeaderTest.zip-- 
 
 Powered by www.kitware.com
 
 Please keep messages on-topic and check the CMake FAQ at: 
 http://www.cmake.org/Wiki/CMake_FAQ
 
 Kitware offers various services to support the CMake community. For more 
 information on each offering, please visit:
 
 CMake Support: http://cmake.org/cmake/help/support.html
 CMake Consulting: http://cmake.org/cmake/help/consulting.html
 CMake Training Courses: http://cmake.org/cmake/help/training.html
 
 Visit other Kitware open-source projects at 
 http://www.kitware.com/opensource/opensource.html
 
 Follow this link to subscribe/unsubscribe:
 http://public.kitware.com/mailman/listinfo/cmake

-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake