Re: [CMake] How to build only when file contents are actually changed?
Pretty much every build system will rebuild if you touch the file. This is a way to force it to compile it's a feature not a bug :) On Mon, Aug 13, 2012 at 10:56 PM, Michael Wild them...@gmail.com wrote: CMake really leaves the decision when to recompile something to the backend, i.e. GNU Make, Xcode, Visual Studio, ninja etc. It merely defines dependencies and then lets the actual build tool handle the rest, and most of them choose to use simple time-stamps instead of hashes. Also note that computing the hash might also incur considerable overhead, in particular for very large projects with thousands of files. You can alleviate the situation a bit by using e.g. ccache to speed up unnecessary recompilations. E.g. on a system that has ccache installed in /usr/lib/ccache (Ubuntu, Debian,...) mkdir build cd build rm -rf * PATH=/usr/lib/cchace:$PATH cmake .. will build using ccache instead the normal compilers. HTH Michael On 08/14/2012 05:22 AM, Peng Yu wrote: Hi, The following command output shows that when I touch a source without changing the content, the source are compiled and linked, which is a waste. This post shows how to use the checksum to decide whether a file is changed or not, if changed then update target. This feature seems to be missing in cmake. In case that I miss something in the document, could anybody let me know if this is the case? http://blog.jgc.org/2006/04/rebuilding-when-hash-has-changed-not.html ~/linux/test/cmake/lang/command/target_link_libraries/src$ cat.sh * == CMakeLists.txt == cmake_minimum_required(VERSION 2.8) add_library(print print.cpp) #include_directories(${HELLO_SOURCE_DIR}) add_executable(main main.cpp) target_link_libraries(main print) == main.cpp == #include print.hpp int main() { print(); } == print.cpp == #include print.hpp #include iostream using namespace std; void print() { cout Hello, World! endl; } == print.hpp == #ifndef _hello_h #define _hello_h void print(); #endif ~/linux/test/cmake/lang/command/target_link_libraries/build$ cmake ../src/ -- The C compiler identification is GNU 4.2.1 -- The CXX compiler identification is GNU 4.2.1 -- Checking whether C compiler has -isysroot -- Checking whether C compiler has -isysroot - yes -- Checking whether C compiler supports OSX deployment target flag -- Checking whether C compiler supports OSX deployment target flag - yes -- Check for working C compiler: /usr/bin/gcc -- Check for working C compiler: /usr/bin/gcc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Checking whether CXX compiler has -isysroot -- Checking whether CXX compiler has -isysroot - yes -- Checking whether CXX compiler supports OSX deployment target flag -- Checking whether CXX compiler supports OSX deployment target flag - yes -- Check for working CXX compiler: /usr/bin/c++ -- Check for working CXX compiler: /usr/bin/c++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Configuring done -- Generating done -- Build files have been written to: /Users/pengy/linux/test/cmake/lang/command/target_link_libraries/build ~/linux/test/cmake/lang/command/target_link_libraries/build$ make Scanning dependencies of target print [ 50%] Building CXX object CMakeFiles/print.dir/print.cpp.o Linking CXX static library libprint.a [ 50%] Built target print Scanning dependencies of target main [100%] Building CXX object CMakeFiles/main.dir/main.cpp.o Linking CXX executable main [100%] Built target main ~/linux/test/cmake/lang/command/target_link_libraries/build$ touch ../src/print.hpp ~/linux/test/cmake/lang/command/target_link_libraries/build$ make Scanning dependencies of target print [ 50%] Building CXX object CMakeFiles/print.dir/print.cpp.o Linking CXX static library libprint.a [ 50%] Built target print Scanning dependencies of target main [100%] Building CXX object CMakeFiles/main.dir/main.cpp.o Linking CXX executable main [100%] Built target main -- 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 -- 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
Re: [CMake] How to build only when file contents are actually changed?
CMake really leaves the decision when to recompile something to the backend, i.e. GNU Make, Xcode, Visual Studio, ninja etc. It merely defines dependencies and then lets the actual build tool handle the rest, and most of them choose to use simple time-stamps instead of Although GNU Make natively does not support build on content change, it can be hijacked using the trick in the link that I mentioned. I think that it is not impossible to do so in cmake at the language level. But it is better if cmake can support this natively. Yes this is a feature request not a bug report. (To J Decker) This feature is available to scons. And I think it is reasonable to expect cmake also have it. I seems that people here did think about it seriously before, which is a surprise to me. http://www.scons.org/doc/0.97/HTML/scons-user/c762.html hashes. Also note that computing the hash might also incur considerable overhead, in particular for very large projects with thousands of files. It might or might not. The decision should be up to the users. In a lot of cases, using hash is faster than recompile the objects. -- Regards, Peng -- 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
Re: [CMake] How to build only when file contents are actually changed?
On 08/14/2012 01:18 PM, Peng Yu wrote: CMake really leaves the decision when to recompile something to the backend, i.e. GNU Make, Xcode, Visual Studio, ninja etc. It merely defines dependencies and then lets the actual build tool handle the rest, and most of them choose to use simple time-stamps instead of Although GNU Make natively does not support build on content change, it can be hijacked using the trick in the link that I mentioned. I think that it is not impossible to do so in cmake at the language level. But it is better if cmake can support this natively. Again, using ccache solves this much more elegantly. And calling md5sum twice is also not very nice... Yes this is a feature request not a bug report. (To J Decker) Well, if you have the time, I'm pretty sure that the CMake developers would happily review your patch implementing this feature. This feature is available to scons. And I think it is reasonable to expect cmake also have it. I seems that people here did think about it seriously before, which is a surprise to me. Yes, but scons is monolithic. It doesn't have the backend build-system from the front end and hence doesn't have to ensure that GNU Make behaves consistently with what Xcode, Visual Studio, ninja etc. do. 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
Re: [CMake] How to build only when file contents are actually changed?
Again, using ccache solves this much more elegantly. And calling md5sum twice is also not very nice... I'm not sure ccache replaces hash. My understanding is that ccache speed up individual compilation, but all the targets that depends on it are still compiled. With hash, a file is checked first whether it should be recompiled, if not, it will not be recompiled, and all the targets that depend on it will not be compiled either. I'm not with a machine that I can check ccache as this moment. Please correct me if I'm wrong. The following compares a few features. But since it is from waf, it might be biased in favor of waf. Nevertheless, there are some features that available in other tools missing in cmake. http://code.google.com/p/waf/wiki/WafAndOtherBuildSystems -- Regards, Peng -- 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
Re: [CMake] How to build only when file contents are actually changed?
On 08/14/2012 02:41 PM, Peng Yu wrote: Again, using ccache solves this much more elegantly. And calling md5sum twice is also not very nice... I'm not sure ccache replaces hash. My understanding is that ccache speed up individual compilation, but all the targets that depends on it are still compiled. With hash, a file is checked first whether it should be recompiled, if not, it will not be recompiled, and all the targets that depend on it will not be compiled either. I'm not with a machine that I can check ccache as this moment. Please correct me if I'm wrong. The following compares a few features. But since it is from waf, it might be biased in favor of waf. Nevertheless, there are some features that available in other tools missing in cmake. http://code.google.com/p/waf/wiki/WafAndOtherBuildSystems You miss the point. If CMake wanted to offer hash-based checking, it would need to do so for *all* backends, not just GNU Make. Good look implementing that hack in Visual Studio or Xcode... 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
Re: [CMake] How to build only when file contents are actually changed?
You miss the point. If CMake wanted to offer hash-based checking, it would need to do so for *all* backends, not just GNU Make. Good look implementing that hack in Visual Studio or Xcode... I get your point that there is not an easy to do content based dependency (hash as an approximation) for all backends. For the reason mentioned below, I'd think that content based dependency is important. The support for this feature should be considered first for GNU make, which does seem to be too difficult (as it just requires some additional rules). The support for *all* backends can be added later on one by one. o Makepp will not recompile if only comments or whitespace in C/C++ sources have changed. This is especially important for header files which are automatically generated by other programs and are included in many modules. Even if the date has changed because the file was remade, makepp won't recompile if the file hasn't changed. -- Regards, Peng -- 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
Re: [CMake] How to build only when file contents are actually changed?
On 08/14/2012 04:32 PM, Peng Yu wrote: You miss the point. If CMake wanted to offer hash-based checking, it would need to do so for *all* backends, not just GNU Make. Good look implementing that hack in Visual Studio or Xcode... I get your point that there is not an easy to do content based dependency (hash as an approximation) for all backends. For the reason mentioned below, I'd think that content based dependency is important. The support for this feature should be considered first for GNU make, which does seem to be too difficult (as it just requires some additional rules). The support for *all* backends can be added later on one by one. I'm not sure how the CMake-devs feel about that, but again, you are most welcome to submit a patch implementing this. o Makepp will not recompile if only comments or whitespace in C/C++ sources have changed. This is especially important for header files which are automatically generated by other programs and are included in many modules. Even if the date has changed because the file was remade, makepp won't recompile if the file hasn't changed. That's plenty dangerous! Only a full C/C++ compiler can decide whether something is a comment or not (as this requires full parsing capabilities) and further it might interfere with compiler bugs; I remember having the problem that with -O3 and old version of the Apple GCC produced code that segfaulted depending on whether a certain comment line was present or not! 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
Re: [CMake] How to build only when file contents are actually changed?
o Makepp will not recompile if only comments or whitespace in C/C++ sources have changed. This is especially important for header files which are automatically generated by other programs and are included in many modules. Even if the date has changed because the file was remade, makepp won't recompile if the file hasn't changed. That's plenty dangerous! Only a full C/C++ compiler can decide whether something is a comment or not (as this requires full parsing capabilities) and further it might interfere with compiler bugs; I remember having the problem that with -O3 and old version of the Apple GCC produced code that segfaulted depending on whether a certain comment line was present or not! This depends on how many different things in C++ are used. With some restrictions, the drawbacks of this approach can be circumvented. To work with some legacy code which include things that may cause failure, makepp may not be the appropriate tool. For a project starting from scratch (so these intruding things can be forbidden), makepp can be a very good tool as it results in much less makefile to write compared with cmake. -- Regards, Peng -- 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
Re: [CMake] How to build only when file contents are actually changed?
2012/8/14 Peng Yu pengyu...@gmail.com: o Makepp will not recompile if only comments or whitespace in C/C++ sources have changed. This is especially important for header files which are automatically generated by other programs and are included in many modules. Even if the date has changed because the file was remade, makepp won't recompile if the file hasn't changed. That's plenty dangerous! Only a full C/C++ compiler can decide whether something is a comment or not (as this requires full parsing capabilities) and further it might interfere with compiler bugs; I remember having the problem that with -O3 and old version of the Apple GCC produced code that segfaulted depending on whether a certain comment line was present or not! This depends on how many different things in C++ are used. With some restrictions, the drawbacks of this approach can be circumvented. To work with some legacy code which include things that may cause failure, makepp may not be the appropriate tool. For a project starting from scratch (so these intruding things can be forbidden), makepp can be a very good tool as it results in much less makefile to write compared with cmake. From http://makepp.sourceforge.net/ I read: Makepp, a build program which has a number of features that allow for reliable builds and simpler build files, is a drop-in replacement for GNU make. Then why can't you use makepp with Makefiles generated by CMake? If Makepp cannot use them, then may be you can try to contribute a Makepp generator to CMake? If you are concerned with speed of build may be you can try the new Ninja generator. Concerning CMake vs (Make vs Makepp vs SCons) as Michael already mentionned, CMake cannot [easily] do build-time action, like hash computation, because it's a build **generator** not a build tool. -- Erk Le gouvernement représentatif n'est pas la démocratie -- http://www.le-message.org -- 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
Re: [CMake] How to build only when file contents are actually changed?
CMake really leaves the decision when to recompile something to the backend, i.e. GNU Make, Xcode, Visual Studio, ninja etc. It merely defines dependencies and then lets the actual build tool handle the rest, and most of them choose to use simple time-stamps instead of hashes. Also note that computing the hash might also incur considerable overhead, in particular for very large projects with thousands of files. You can alleviate the situation a bit by using e.g. ccache to speed up unnecessary recompilations. E.g. on a system that has ccache installed in /usr/lib/ccache (Ubuntu, Debian,...) mkdir build cd build rm -rf * PATH=/usr/lib/cchace:$PATH cmake .. will build using ccache instead the normal compilers. HTH Michael On 08/14/2012 05:22 AM, Peng Yu wrote: Hi, The following command output shows that when I touch a source without changing the content, the source are compiled and linked, which is a waste. This post shows how to use the checksum to decide whether a file is changed or not, if changed then update target. This feature seems to be missing in cmake. In case that I miss something in the document, could anybody let me know if this is the case? http://blog.jgc.org/2006/04/rebuilding-when-hash-has-changed-not.html ~/linux/test/cmake/lang/command/target_link_libraries/src$ cat.sh * == CMakeLists.txt == cmake_minimum_required(VERSION 2.8) add_library(print print.cpp) #include_directories(${HELLO_SOURCE_DIR}) add_executable(main main.cpp) target_link_libraries(main print) == main.cpp == #include print.hpp int main() { print(); } == print.cpp == #include print.hpp #include iostream using namespace std; void print() { cout Hello, World! endl; } == print.hpp == #ifndef _hello_h #define _hello_h void print(); #endif ~/linux/test/cmake/lang/command/target_link_libraries/build$ cmake ../src/ -- The C compiler identification is GNU 4.2.1 -- The CXX compiler identification is GNU 4.2.1 -- Checking whether C compiler has -isysroot -- Checking whether C compiler has -isysroot - yes -- Checking whether C compiler supports OSX deployment target flag -- Checking whether C compiler supports OSX deployment target flag - yes -- Check for working C compiler: /usr/bin/gcc -- Check for working C compiler: /usr/bin/gcc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Checking whether CXX compiler has -isysroot -- Checking whether CXX compiler has -isysroot - yes -- Checking whether CXX compiler supports OSX deployment target flag -- Checking whether CXX compiler supports OSX deployment target flag - yes -- Check for working CXX compiler: /usr/bin/c++ -- Check for working CXX compiler: /usr/bin/c++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Configuring done -- Generating done -- Build files have been written to: /Users/pengy/linux/test/cmake/lang/command/target_link_libraries/build ~/linux/test/cmake/lang/command/target_link_libraries/build$ make Scanning dependencies of target print [ 50%] Building CXX object CMakeFiles/print.dir/print.cpp.o Linking CXX static library libprint.a [ 50%] Built target print Scanning dependencies of target main [100%] Building CXX object CMakeFiles/main.dir/main.cpp.o Linking CXX executable main [100%] Built target main ~/linux/test/cmake/lang/command/target_link_libraries/build$ touch ../src/print.hpp ~/linux/test/cmake/lang/command/target_link_libraries/build$ make Scanning dependencies of target print [ 50%] Building CXX object CMakeFiles/print.dir/print.cpp.o Linking CXX static library libprint.a [ 50%] Built target print Scanning dependencies of target main [100%] Building CXX object CMakeFiles/main.dir/main.cpp.o Linking CXX executable main [100%] Built target main -- 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