On Tuesday 25 November 2008 22:35:34 Alexander Neundorf wrote:
> The macro macro_add_file_dependencies() is only available in kdelibs/ and
> projects using kdelibs/, i.e. it shouldn't be used in automoc. The macro is
> in kdelibs/cmake/modules/MacroAddFileDependencies.cmake, you can just copy
> it.
Hmm, I found the macro also in the cmake installation dir as the FindQt4
shipping with cmake also uses it.
> But, why is this dependency required now ? Currently the source files don't
> depend on the automoc-generated file and it works ?
Yes it works most of the time except for make target/fast there's a race and
it breaks sometimes.
So actually this part of the patch is not directly related to the
automoc4_init change.
> About the add_custom_target(automoc4_init): this is done now
> unconditionally. I.e. if you do find_package(Automoc4) twice, it will be
> executed twice, cmake will then complain about the target being added
> twice.
Ah, I thought cmake would still read the automoc code only once.
> So you should test wether the target has already been added.
> With CMake >= 2.6.2 you can do
> if(NOT TARGET automoc4_init)
> ...
>
> With version before that you can do
> get_target_property(AUTOMOC4_INIT_TYPE automoc4_init TYPE)
> if the target has already been created, you will get "UTILITY" as result
> (which is TRUE if tested in an if()), and "AUTOMOC4_INIT_TYPE-NOTFOUND" if
> it hasn't been created yet (which is false if tested with if()).
I used if(AUTOMOC4_INIT_FILE) now, that should be suffiently safe and a bit
easier, ok?
> Is it still necessary to have different versions for Windows and
> non-Windows ?
I don't know. I'd like the Windows people to give the non-Windows code another
try and hopefully we can remove the special casing for Windows again.
> Instead of putting all files into automoc4_init.files on every cmake run,
> could you do it similar to as you did it before ?
> I.e. instead if touching the file in the add_custom_command(), add that
> filename to automoc4_init.files, so in the next make, the automoc4_init
> target will just touch these files and not all ?
> This could be done by adding that to the automoc4 executable or by
> executing an additional command in the same add_custom_command (echo should
> work)
It's hard to do that without creating new races. (Think of the user hitting
Ctrl+C at the most inconvenient point in time.) And what would happen if two
or more automoc4 processes write to the file at the same time?
Also the current implementation seems reasonably fast (kdelibs: 3ms, kdebase:
4ms, phonon: 0ms. After 'echo 3 > /proc/sys/vm/drop_caches': kdelibs: 77ms,
kdebase: 260ms, phonon: 27ms.)
--
________________________________________________________
Matthias Kretz (Germany) <><
http://Vir.homelinux.org/
Index: kde4automoc.cpp
===================================================================
--- kde4automoc.cpp (revision 886850)
+++ kde4automoc.cpp (working copy)
@@ -34,6 +34,7 @@
#include <QtCore/QRegExp>
#include <QtCore/QStringList>
#include <QtCore/QTextStream>
+//#include <QtCore/QTime>
#include <QtCore/QtDebug>
#include <cstdlib>
#include <sys/types.h>
@@ -60,7 +61,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 +87,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 +119,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 +163,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 +229,31 @@
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);
+ }
+ //QTime stopwatch;
+ //stopwatch.start();
+ 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();
+ }
+ //cerr << "automoc4_init took: " << stopwatch.elapsed() << "ms" << endl;
+ ::exit(0);
+ } else if (args.size() != 6) {
printUsage(args[0]);
::exit(EXIT_FAILURE);
}
@@ -514,38 +531,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 886850)
+++ Automoc4Config.cmake (working copy)
@@ -1,5 +1,5 @@
-
+include(MacroAddFileDependencies)
get_filename_component(_AUTOMOC4_CURRENT_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
# set the automoc version number
@@ -37,6 +37,20 @@
endif(_headers_to_moc)
endmacro (AUTOMOC4_MOC_HEADERS)
+if(NOT AUTOMOC4_INIT_FILE)
+ 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} "")
+endif(NOT AUTOMOC4_INIT_FILE)
macro(AUTOMOC4 _target_NAME _SRCS)
set(_moc_files)
@@ -78,12 +92,15 @@
${CMAKE_CURRENT_BINARY_DIR}
${QT_MOC_EXECUTABLE}
${CMAKE_COMMAND}
- --touch
DEPENDS ${_automoc_source}.files ${_AUTOMOC4_EXECUTABLE_DEP}
COMMENT ""
VERBATIM
)
+ foreach(_src ${${_SRCS}})
+ macro_add_file_dependencies(${_src} ${_automoc_source})
+ endforeach(_src)
set(${_SRCS} ${_automoc_source} ${${_SRCS}})
+ file(APPEND ${AUTOMOC4_INIT_FILE} "${_automoc_source}.files\n")
endif(_moc_files)
endmacro(AUTOMOC4)
@@ -171,6 +188,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 +213,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 886850)
+++ 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}")
_______________________________________________
Kde-buildsystem mailing list
[email protected]
https://mail.kde.org/mailman/listinfo/kde-buildsystem