[CMake] How to build only when file contents are actually changed?
Peng Yu
pengyu.ut at gmail.com
Mon Aug 13 23:22:13 EDT 2012
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
--
Regards,
Peng
More information about the CMake
mailing list