Merge topic 'dont-rewrite-moc-parameter-file'

17c31b8b Qt4: Extend the Qt4Targets test to cover dir and target moc parameters.
6a5bd7f0 Qt4: write moc parameter file only when content has changed
This commit is contained in:
Brad King 2014-05-06 13:48:40 -04:00 committed by CMake Topic Stage
commit 58557486db
3 changed files with 51 additions and 26 deletions

View File

@ -135,7 +135,9 @@ function (QT4_CREATE_MOC_COMMAND infile outfile moc_flags moc_options moc_target
set(targetincludes) set(targetincludes)
set(targetdefines) set(targetdefines)
else() else()
file(WRITE ${_moc_parameters_file} "${_moc_parameters}\n") set(CMAKE_CONFIGURABLE_FILE_CONTENT "${_moc_parameters}")
configure_file("${CMAKE_ROOT}/Modules/CMakeConfigurableFile.in"
"${_moc_parameters_file}" @ONLY)
endif() endif()
set(_moc_extra_parameters_file @${_moc_parameters_file}) set(_moc_extra_parameters_file @${_moc_parameters_file})

View File

@ -37,29 +37,44 @@ set_property(TARGET Qt4WrapMacroTest PROPERTY AUTOMOC OFF)
target_include_directories(Qt4WrapMacroTest PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/interface") target_include_directories(Qt4WrapMacroTest PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/interface")
target_link_libraries(Qt4WrapMacroTest Qt4::QtGui) target_link_libraries(Qt4WrapMacroTest Qt4::QtGui)
set(timeformat "%Y%j%H%M%S") macro(test_incremental def)
try_compile(RESULT set(timeformat "%Y%j%H%M%S")
"${CMAKE_CURRENT_BINARY_DIR}/IncrementalMocBuild" try_compile(RESULT
"${CMAKE_CURRENT_SOURCE_DIR}/IncrementalMoc" "${CMAKE_CURRENT_BINARY_DIR}/IncrementalMocBuild_${def}"
IncrementalMoc "${CMAKE_CURRENT_SOURCE_DIR}/IncrementalMoc"
CMAKE_FLAGS -DADD_DEF=0 "-DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}") IncrementalMoc
file(TIMESTAMP "${CMAKE_CURRENT_BINARY_DIR}/IncrementalMocBuild/moc_foo.cpp" tsvar_before "${timeformat}") CMAKE_FLAGS -D${def}=0 "-DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}"
if (NOT tsvar_before) OUTPUT_VARIABLE output
message(SEND_ERROR "Unable to read timestamp from moc file from first build!") )
endif() file(TIMESTAMP "${CMAKE_CURRENT_BINARY_DIR}/IncrementalMocBuild_${def}/moc_foo.cpp" tsvar_before "${timeformat}")
if (NOT tsvar_before)
message(SEND_ERROR
"Unable to read timestamp from moc file from first build with -D${def}!\n"
"try_compile output:\n${output}"
)
endif()
execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 2) # Ensure that the timestamp will change. execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 2) # Ensure that the timestamp will change.
try_compile(RESULT try_compile(RESULT
"${CMAKE_CURRENT_BINARY_DIR}/IncrementalMocBuild" "${CMAKE_CURRENT_BINARY_DIR}/IncrementalMocBuild_${def}"
"${CMAKE_CURRENT_SOURCE_DIR}/IncrementalMoc" "${CMAKE_CURRENT_SOURCE_DIR}/IncrementalMoc"
IncrementalMoc IncrementalMoc
CMAKE_FLAGS -DADD_DEF=1 "-DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}") CMAKE_FLAGS -D${def}=1 "-DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}"
file(TIMESTAMP "${CMAKE_CURRENT_BINARY_DIR}/IncrementalMocBuild/moc_foo.cpp" tsvar_after "${timeformat}") OUTPUT_VARIABLE output
if (NOT tsvar_after) )
message(SEND_ERROR "Unable to read timestamp from moc file from second build!") file(TIMESTAMP "${CMAKE_CURRENT_BINARY_DIR}/IncrementalMocBuild_${def}/moc_foo.cpp" tsvar_after "${timeformat}")
endif() if (NOT tsvar_after)
message(SEND_ERROR
"Unable to read timestamp from moc file from second build!\n"
"try_compile output:\n${output}"
)
endif()
if (NOT tsvar_after GREATER tsvar_before) if (NOT tsvar_after GREATER tsvar_before)
message(SEND_ERROR "Rebuild did not re-create moc file. Before: ${tsvar_before}. After: ${tsvar_after}") message(SEND_ERROR "Rebuild did not re-create moc file with -D${def}. Before: ${tsvar_before}. After: ${tsvar_after}")
endif() endif()
endmacro()
test_incremental(ADD_TARGET_DEF)
test_incremental(ADD_DIR_DEF)

View File

@ -4,10 +4,18 @@ project(IncrementalMoc)
find_package(Qt4 REQUIRED) find_package(Qt4 REQUIRED)
qt4_generate_moc(foo.h moc_foo.cpp) if (ADD_TARGET_DEF)
set(target_args TARGET testlib)
endif()
if (ADD_DIR_DEF)
add_definitions(-DNEW_DEF)
endif()
qt4_generate_moc(foo.h moc_foo.cpp ${target_args})
add_library(testlib foo.cpp moc_foo.cpp) add_library(testlib foo.cpp moc_foo.cpp)
target_link_libraries(testlib Qt4::QtCore) target_link_libraries(testlib Qt4::QtCore)
if (ADD_DEF) if (ADD_TARGET_DEF)
target_compile_definitions(testlib PRIVATE NEW_DEF) target_compile_definitions(testlib PRIVATE NEW_DEF)
endif() endif()