From b9c24f8a929a7c6dd84f5e8f9e82e05be1d1b94e Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 21 Aug 2018 13:20:58 +0200 Subject: [PATCH] reduce compile time after each time cmake configure is executed (swig) --- src/Base/CMakeLists.txt | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Base/CMakeLists.txt b/src/Base/CMakeLists.txt index 467d1df2bf..73edf0738d 100644 --- a/src/Base/CMakeLists.txt +++ b/src/Base/CMakeLists.txt @@ -90,7 +90,27 @@ generate_from_xml(UnitPy) generate_from_xml(QuantityPy) if(SWIG_FOUND) - execute_process(COMMAND ${SWIG_EXECUTABLE} -python -external-runtime ${CMAKE_CURRENT_BINARY_DIR}/swigpyrun.h) + # Create the file swigpyrun.hh and then compare with the file swigpyrun.h. + # If the files are different or if swigpyrun.h doesn't exist then copy swigpyrun.hh. + # This is to avoid to having to build the target each time cmake configure is executed. + execute_process(COMMAND ${SWIG_EXECUTABLE} -python -external-runtime ${CMAKE_CURRENT_BINARY_DIR}/swigpyrun.hh) + if (EXISTS "${CMAKE_CURRENT_BINARY_DIR}/swigpyrun.h") + execute_process( + COMMAND ${CMAKE_COMMAND} -E compare_files ${CMAKE_CURRENT_BINARY_DIR}/swigpyrun.hh + ${CMAKE_CURRENT_BINARY_DIR}/swigpyrun.h + RESULT_VARIABLE DIFFERENT_FILES + OUTPUT_QUIET + ERROR_QUIET + ) + + if (DIFFERENT_FILES) + execute_process(COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_BINARY_DIR}/swigpyrun.hh" + "${CMAKE_CURRENT_BINARY_DIR}/swigpyrun.h") + endif() + else() + execute_process(COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_BINARY_DIR}/swigpyrun.hh" + "${CMAKE_CURRENT_BINARY_DIR}/swigpyrun.h") + endif() add_definitions(-DHAVE_SWIG=1) endif(SWIG_FOUND)