On Wednesday 19 November 2008 14:49:10 Matthias Kretz wrote:
> On Tuesday 18 November 2008 20:55:11 Alexander Neundorf wrote:
> > What do you think about the idea with the one global helper target ?
>
> Sounds like a good idea but I have two problems with it:
> a) it won't get called on make target/fast
> b) there are still race conditions in your proposal such that in the end
> _automoc.cpp is newer than _automoc.cpp.files and the helper target will
> not be instructed to touch _automoc.cpp.files.
I now have a patch that creates an automoc4_init target globally and all other
targets using automoc depend on it.
This target runs
autmoc4 --touch ${CMAKE_BINARY_DIR}/automoc4_init.files
The file it opens contains a list of all the filepaths to the
*_automoc.cpp.files of the project.
So when automoc4_init is executed all automoc custom commands are made out-of-
date. There's also no race with this anymore.
make target/fast will work most of the time. Until _automoc.cpp gets changed
and has a newer timestamp than _automoc.cpp.files. Then you need to run a
non-/fast make and it'll work again.
Now, for some reason qt4_generate_moc stopped working for me. I don't see how
that could be related, if it is and you have an idea please take a look.
Patch attached.
--
________________________________________________________
Matthias Kretz (Germany) <><
http://Vir.homelinux.org/
Index: kde4automoc.cpp
===================================================================
--- kde4automoc.cpp (revision 886566)
+++ kde4automoc.cpp (working copy)
@@ -60,7 +60,6 @@
void dotFilesCheck(bool);
void lazyInitMocDefinitions();
void lazyInit();
- bool touch(const QString &filename);
bool generateMoc(const QString &sourceFile, const QString &mocFileName);
void printUsage(const QString &);
void printVersion();
@@ -87,12 +86,12 @@
bool failed;
bool automocCppChanged;
bool generateAll;
- bool doTouch;
};
void AutoMoc::printUsage(const QString &path)
{
- cout << "Usage: " << path << " <outfile> <srcdir> <builddir> <moc executable> <cmake executable> [--touch]" << endl;
+ cout << "Usage: " << path << " <outfile> <srcdir> <builddir> <moc executable> <cmake executable>" << endl;
+ cout << "or: " << path << " --touch <file containing filepaths to touch>" << endl;
}
void AutoMoc::printVersion()
@@ -119,7 +118,7 @@
AutoMoc::AutoMoc()
: verbose(!qgetenv("VERBOSE").isEmpty()), cerr(stderr), cout(stdout), failed(false),
- automocCppChanged(false), generateAll(false), doTouch(false)
+ automocCppChanged(false), generateAll(false)
{
const QByteArray colorEnv = qgetenv("COLOR");
cmakeEchoColorArgs << QLatin1String("-E") << QLatin1String("cmake_echo_color")
@@ -163,12 +162,6 @@
mocExe = args[4];
cmakeExecutable = args[5];
- if (args.size() > 6) {
- if (args[6] == QLatin1String("--touch")) {
- doTouch = true;
- }
- }
-
lazyInitMocDefinitions();
QByteArray line = dotFiles.readLine();
@@ -235,8 +228,28 @@
printUsage(args[0]);
::exit(EXIT_FAILURE);
}
- }
- else if (args.size() < 5) {
+ } else if (args.size() == 3) {
+ if (args[1] != "--touch") {
+ printUsage(args[0]);
+ ::exit(EXIT_FAILURE);
+ }
+ QFile filesFile(args[2]);
+ filesFile.open(QIODevice::ReadOnly | QIODevice::Text);
+ QByteArray line = filesFile.readLine().trimmed();
+ while (!line.isEmpty()) {
+#ifdef Q_OS_WIN
+ _wutime(reinterpret_cast<const wchar_t *>(QString::fromLocal8Bit(line).utf16()), 0);
+#else
+ int err = utime(line.constData(), NULL);
+ if (err == -1) {
+ err = errno;
+ cerr << strerror(err) << "\n";
+ }
+#endif
+ line = filesFile.readLine().trimmed();
+ }
+ ::exit(0);
+ } else if (args.size() != 6) {
printUsage(args[0]);
::exit(EXIT_FAILURE);
}
@@ -514,38 +527,11 @@
outfile.write(automocSource);
outfile.close();
- // update the timestamp on the _automoc.cpp.files file to make sure we get called again
dotFiles.close();
- if (doTouch && !touch(dotFiles.fileName())) {
- return false;
- }
return true;
}
-bool AutoMoc::touch(const QString &_filename)
-{
- // sleep for 1s in order to make the modification time greater than the modification time of
- // the files written before. Equal modification time is not good enough. Just using utime with
- // time(NULL) + 1 is also not a good solution as then make will complain about clock skew.
-#ifdef Q_OS_WIN
- Sleep(1000);
- _wutime(reinterpret_cast<const wchar_t *>(_filename.utf16()), 0);
-#else
- const QByteArray &filename = QFile::encodeName(_filename);
- const struct timespec sleepDuration = { 1, 0 };
- nanosleep(&sleepDuration, NULL);
-
- int err = utime(filename.constData(), NULL);
- if (err == -1) {
- err = errno;
- cerr << strerror(err) << "\n";
- return false;
- }
-#endif
- return true;
-}
-
bool AutoMoc::generateMoc(const QString &sourceFile, const QString &mocFileName)
{
//qDebug() << Q_FUNC_INFO << sourceFile << mocFileName;
Index: Automoc4Config.cmake
===================================================================
--- Automoc4Config.cmake (revision 886566)
+++ Automoc4Config.cmake (working copy)
@@ -37,6 +37,18 @@
endif(_headers_to_moc)
endmacro (AUTOMOC4_MOC_HEADERS)
+set(AUTOMOC4_INIT_FILE "${CMAKE_BINARY_DIR}/automoc4_init.files")
+add_custom_target(automoc4_init
+ ${AUTOMOC4_EXECUTABLE}
+ --touch
+ ${AUTOMOC4_INIT_FILE}
+ COMMENT "initialize automoc4"
+ VERBATIM
+ )
+if(_AUTOMOC4_EXECUTABLE_DEP)
+ add_dependencies("automoc4_init" "automoc4")
+endif(_AUTOMOC4_EXECUTABLE_DEP)
+file(WRITE ${AUTOMOC4_INIT_FILE} "")
macro(AUTOMOC4 _target_NAME _SRCS)
set(_moc_files)
@@ -78,12 +90,13 @@
${CMAKE_CURRENT_BINARY_DIR}
${QT_MOC_EXECUTABLE}
${CMAKE_COMMAND}
- --touch
DEPENDS ${_automoc_source}.files ${_AUTOMOC4_EXECUTABLE_DEP}
COMMENT ""
VERBATIM
)
+ set_source_files_properties(${${_SRCS}} PROPERTIES OBJECT_DEPENDS ${_automoc_source})
set(${_SRCS} ${_automoc_source} ${${_SRCS}})
+ file(APPEND ${AUTOMOC4_INIT_FILE} "${_automoc_source}.files\n")
endif(_moc_files)
endmacro(AUTOMOC4)
@@ -171,6 +184,8 @@
add_executable(${_target_NAME} ${_add_executable_param} ${_SRCS})
if(MSVC)
add_dependencies(${_target_NAME} "${_target_NAME}_automoc")
+ else(MSVC)
+ add_dependencies(${_target_NAME} "automoc4_init")
endif(MSVC)
endmacro(AUTOMOC4_ADD_EXECUTABLE)
@@ -194,5 +209,7 @@
add_library(${_target_NAME} ${_add_executable_param} ${_SRCS})
if(MSVC)
add_dependencies(${_target_NAME} "${_target_NAME}_automoc")
+ else(MSVC)
+ add_dependencies(${_target_NAME} "automoc4_init")
endif(MSVC)
endmacro(AUTOMOC4_ADD_LIBRARY)
Index: Automoc4Version.cmake
===================================================================
--- Automoc4Version.cmake (revision 886566)
+++ Automoc4Version.cmake (working copy)
@@ -1,7 +1,7 @@
# set the current version number
set(AUTOMOC4_VERSION_MAJOR "0")
set(AUTOMOC4_VERSION_MINOR "9")
-set(AUTOMOC4_VERSION_PATCH "87")
+set(AUTOMOC4_VERSION_PATCH "88")
set(AUTOMOC4_VERSION "${AUTOMOC4_VERSION_MAJOR}.${AUTOMOC4_VERSION_MINOR}.${AUTOMOC4_VERSION_PATCH}")
Index: cmake/modules/FindKDE4Internal.cmake
===================================================================
--- cmake/modules/FindKDE4Internal.cmake (revision 886449)
+++ cmake/modules/FindKDE4Internal.cmake (working copy)
@@ -290,7 +290,7 @@
# the version macro was added for 0.9.84
set(AUTOMOC4_VERSION "0.9.83")
endif (NOT AUTOMOC4_VERSION)
-macro_ensure_version("0.9.87" "${AUTOMOC4_VERSION}" _automoc4_version_ok)
+macro_ensure_version("0.9.88" "${AUTOMOC4_VERSION}" _automoc4_version_ok)
# for compatibility with KDE 4.0.x
set(KDE4_AUTOMOC_EXECUTABLE "${AUTOMOC4_EXECUTABLE}" )
Index: cmake/modules/KDE4Macros.cmake
===================================================================
--- cmake/modules/KDE4Macros.cmake (revision 886449)
+++ cmake/modules/KDE4Macros.cmake (working copy)
@@ -571,6 +571,8 @@
endif (KDE4_ENABLE_FINAL)
if(MSVC)
add_dependencies(${_target_NAME} "${_target_NAME}_automoc")
+ else(MSVC)
+ add_dependencies(${_target_NAME} "automoc4_init")
endif(MSVC)
if (_first_SRC)
@@ -838,6 +840,8 @@
endif (KDE4_ENABLE_FINAL)
if(MSVC)
add_dependencies(${_target_NAME} "${_target_NAME}_automoc")
+ else(MSVC)
+ add_dependencies(${_target_NAME} "automoc4_init")
endif(MSVC)
if (_test)
@@ -886,6 +890,8 @@
endif (KDE4_ENABLE_FINAL)
if(MSVC)
add_dependencies(${_target_NAME} "${_target_NAME}_automoc")
+ else(MSVC)
+ add_dependencies(${_target_NAME} "automoc4_init")
endif(MSVC)
kde4_handle_rpath_for_library(${_target_NAME})
_______________________________________________
Kde-buildsystem mailing list
[email protected]
https://mail.kde.org/mailman/listinfo/kde-buildsystem