From 9e8e4574285cc52caaba1b5ad595fad3c4e89cb8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Peter=20K=C3=BCmmel?= Date: Wed, 2 May 2007 20:47:47 +0000 Subject: [PATCH] cmake: don't rebuild merges files on each cmake run, force rebuild by -Dmerge_rebuild=1 git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18175 a592a061-630c-0410-9148-cb99ea01b6c8 --- development/cmake/modules/LyXMacros.cmake | 63 ++++++++++++++++++----- 1 file changed, 50 insertions(+), 13 deletions(-) diff --git a/development/cmake/modules/LyXMacros.cmake b/development/cmake/modules/LyXMacros.cmake index 8af9eca67d..0749961f1c 100644 --- a/development/cmake/modules/LyXMacros.cmake +++ b/development/cmake/modules/LyXMacros.cmake @@ -131,13 +131,46 @@ macro(lyx_const_touched_files _allinone_name _list) set(_file_const ${CMAKE_CURRENT_BINARY_DIR}/${_allinone_name}_const.C) set(_file_touched ${CMAKE_CURRENT_BINARY_DIR}/${_allinone_name}_touched.C) - file(WRITE ${_file_const} "//autogenerated file\n") - file(WRITE ${_file_touched} "//autogenerated file\n") - file(APPEND ${_file_touched} "// touched files\n\n") - file(APPEND ${_file_touched} "// look for non-const files\n") - file(APPEND ${_file_touched} "#define DONT_INCLUDE_CONST_FILES\n") - file(APPEND ${_file_touched} "#include \"${_file_const}\"\n\n\n") + # don't touch exisiting or non-empty file, + # so a cmake re-run doesn't touch all created files + set(_rebuild_file_const 0) + if (NOT EXISTS ${_file_const}) + set(_rebuild_file_const 1) + else (NOT EXISTS ${_file_const}) + FILE(READ ${_file_const} _file_content) + if (NOT _file_content) + set(_rebuild_file_const 1) + endif (NOT _file_content) + endif (NOT EXISTS ${_file_const}) + + set(_rebuild_file_touched 0) + if (NOT EXISTS ${_file_touched}) + set(_rebuild_file_touched 1) + else (NOT EXISTS ${_file_touched}) + FILE(READ ${_file_touched} _file_content) + if (NOT _file_content) + set(_rebuild_file_touched 1) + endif (NOT _file_content) + endif (NOT EXISTS ${_file_touched}) + + if (merge_rebuild) + set(_rebuild_file_const 1) + set(_rebuild_file_touched 1) + endif (merge_rebuild) + + if (_rebuild_file_const) + file(WRITE ${_file_const} "// autogenerated file \n//\n") + file(APPEND ${_file_const} "// * clear or delete this file to build it again by cmake \n//\n\n") + endif (_rebuild_file_const) + + if (_rebuild_file_touched) + file(WRITE ${_file_touched} "// autogenerated file \n//\n") + file(APPEND ${_file_touched} "// * clear or delete this file to build it again by cmake \n//\n") + file(APPEND ${_file_touched} "// * don't touch this file \n//\n\n") + file(APPEND ${_file_touched} "#define DONT_INCLUDE_CONST_FILES\n") + file(APPEND ${_file_touched} "#include \"${_file_const}\"\n\n\n") + endif (_rebuild_file_touched) set(${_file_list} ${_file_const} ${_file_touched}) @@ -153,14 +186,18 @@ macro(lyx_const_touched_files _allinone_name _list) STRING(REGEX REPLACE "-" "_" _file_name "${_file_name}" ) set(__macro_name ${_file_name}___ASSUME_CONST) - file(APPEND ${_file_const} "#define ${__macro_name}\n") - file(APPEND ${_file_const} "#if defined(${__macro_name}) && !defined(DONT_INCLUDE_CONST_FILES)\n") - file(APPEND ${_file_const} "#include \"${_abs_FILE}\"\n") - file(APPEND ${_file_const} "#endif\n\n") + if (_rebuild_file_const) + file(APPEND ${_file_const} "#define ${__macro_name}\n") + file(APPEND ${_file_const} "#if defined(${__macro_name}) && !defined(DONT_INCLUDE_CONST_FILES)\n") + file(APPEND ${_file_const} "#include \"${_abs_FILE}\"\n") + file(APPEND ${_file_const} "#endif\n\n") + endif (_rebuild_file_const) - file(APPEND ${_file_touched} "#ifndef ${__macro_name}\n") - file(APPEND ${_file_touched} "#include \"${_abs_FILE}\"\n") - file(APPEND ${_file_touched} "#endif\n\n") + if (_rebuild_file_touched) + file(APPEND ${_file_touched} "#ifndef ${__macro_name}\n") + file(APPEND ${_file_touched} "#include \"${_abs_FILE}\"\n") + file(APPEND ${_file_touched} "#endif\n\n") + endif (_rebuild_file_touched) endif (_isGenerated) endforeach (_current_FILE) endmacro(lyx_const_touched_files) -- 2.39.5