]> git.lyx.org Git - lyx.git/blobdiff - development/cmake/modules/LyXMacros.cmake
cmake cosmetics
[lyx.git] / development / cmake / modules / LyXMacros.cmake
index 3536c035180de044d43e18653c3827ce1beba533..609e83099506d03b5710dadbd41d1d47bc589ed1 100644 (file)
@@ -42,7 +42,7 @@ macro (LYX_ADD_UI_FILES _sources _ui)
 
       get_filename_component(_tmp_FILE ${_current_FILE} ABSOLUTE)
       get_filename_component(_basename ${_tmp_FILE} NAME_WE)
-      set(_header ${CMAKE_CURRENT_BINARY_DIR}/ui/${_basename}.h)
+      set(_header ${CMAKE_CURRENT_BINARY_DIR}/ui_${_basename}.h)
 
       # we need to run uic and replace some things in the generated file
       # this is done by executing the cmake script kde4uic.cmake
@@ -66,7 +66,7 @@ endmacro (LYX_ADD_UI_FILES)
 MACRO (LYX_AUTOMOC)
    if(QT4_GET_MOC_INC_DIRS)
       QT4_GET_MOC_INC_DIRS(_moc_INCS)
-   endif(QT4_GET_MOC_INC_DIRS)
+   endif()
 
    set(_matching_FILES )
    foreach (_current_FILE ${ARGN})
@@ -117,70 +117,89 @@ MACRO (LYX_AUTOMOC)
                macro_add_file_dependencies(${_abs_FILE} ${_moc})
 
             endforeach (_current_MOC_INC)
-         else(_match)
+         else()
                #message(STATUS "moc not found : ${_abs_FILE} ")
-         endif (_match)
+         endif()
 
-      endif (EXISTS ${_abs_FILE} AND NOT _skip)
+      endif()
    endforeach (_current_FILE)
 endmacro (LYX_AUTOMOC)
 
 
-# For all C++ sources a big source file which includes all the files
-# is created.
-# This is not done for the C sources, they are just gathered in a separate list
-# because they are usually not written by KDE and as such not intended to be
-# compiled all-in-one.
-macro (LYX_CREATE_FINAL_FILES _filenameCPP _filesExcludedFromFinalFile )
-   set(${_filesExcludedFromFinalFile})
-
-   set(_file_const ${CMAKE_CURRENT_BINARY_DIR}/${_filenameCPP}_const.C)
-   set(_file_touched ${CMAKE_CURRENT_BINARY_DIR}/${_filenameCPP}_touched.C)
+macro(lyx_const_touched_files _allinone_name _list)
+   set(_file_list ${_allinone_name}_files)
+   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()
+      FILE(READ ${_file_const} _file_content)
+      if (NOT _file_content)
+         set(_rebuild_file_const 1)
+      endif()
+   endif()
    
-   foreach (_current_FILE ${ARGN})
+   set(_rebuild_file_touched 0)
+   if (NOT EXISTS ${_file_touched})
+      set(_rebuild_file_touched 1)
+   else()
+      FILE(READ ${_file_touched} _file_content)
+      if (NOT _file_content)
+         set(_rebuild_file_touched 1)
+      endif()   
+   endif()
+   
+   if (merge_rebuild)
+      set(_rebuild_file_const 1)
+      set(_rebuild_file_touched 1)
+   endif()
+   
+   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()
+
+   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()
+   
+   set(${_file_list} ${_file_const} ${_file_touched})
+   
+   foreach (_current_FILE ${${_list}})
       get_filename_component(_abs_FILE ${_current_FILE} ABSOLUTE)
       # don't include any generated files in the final-file
       # because then cmake will not know the dependencies
       get_source_file_property(_isGenerated ${_abs_FILE} GENERATED)
       if (_isGenerated)
-         list(APPEND ${_filesExcludedFromFinalFile} ${_abs_FILE})
-      else (_isGenerated)
-         # don't include c-files in the final-file, because they usually come
-         # from a 3rd party and as such are not intended to be compiled all-in-one
-         string(REGEX MATCH ".+\\.c$" _isCFile ${_abs_FILE})
-         if (_isCFile)
-            list(APPEND ${_filesExcludedFromFinalFile} ${_abs_FILE})
-         else (_isCFile)
-            file(APPEND ${_filenameCPP} "#include \"${_abs_FILE}\"\n")
-            
-            GET_FILENAME_COMPONENT(_file_name ${_abs_FILE} NAME_WE)
-            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")
-            
-            file(APPEND ${_file_touched}  "#ifndef ${__macro_name}\n")
-            file(APPEND ${_file_touched}  "#include \"${_abs_FILE}\"\n")
-            file(APPEND ${_file_touched}  "#endif\n\n")
-            
-         endif (_isCFile)
-      endif (_isGenerated)
+         list(APPEND ${_file_list} ${_abs_FILE})
+      else()
+        GET_FILENAME_COMPONENT(_file_name ${_abs_FILE} NAME_WE)
+        STRING(REGEX REPLACE "-" "_" _file_name "${_file_name}" )
+        set(__macro_name ${_file_name}___ASSUME_CONST)
+        
+        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()
+        
+        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()
+      endif()
    endforeach (_current_FILE)
-endmacro (LYX_CREATE_FINAL_FILES)
-
+endmacro(lyx_const_touched_files)
 
-macro(lyx_merge_files _filename _list)
-       LYX_CREATE_FINAL_FILES(${_filename} _nix_nothing ${${_list}})
-endmacro(lyx_merge_files _list _filename)