I have a simple setup with main.cpp, mainwindows.cpp, mainwindow.h, and mainwindow.ui with this cmake file :
cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)
project(test_qt_with_cmake)
set(CMAKE_CXX_STANDARD 11) # use c++11
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_PREFIX_PATH "C:/Qt/5.8/msvc2015_64")
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
find_package(Qt5Widgets)
set(PROJECT_INCLUDE_DIR "${PROJECT_SOURCE_DIR}")
######## PROJECT DEPENDENCIES #########
if(WIN32)
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${PROJECT_SOURCE_DIR}/windows)
endif()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake")
#=====================================
include_directories(
${PROJECT_INCLUDE_DIR}
)
add_executable(test_qt WIN32 main.cpp mainwindow.cpp mainwindow.h)
target_link_libraries(test_qt Qt5::Widgets)
add_custom_command(TARGET test_qt POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${PROJECT_SOURCE_DIR}/windows/bin"
$<TARGET_FILE_DIR:test_qt>)
The ui_xxx.h is generated the first time i build the project and regenerated if the .ui file and one of source file is changed. What i would like is to get the ui_xxx.h to get regenerated everytime .ui file is changed with or without source change.
I've taken a look at https://github.com/euler0/mini-cmake-qt but the example_automoc project is always out of date and vs always ask to rebuild the project.
Is there something wrong in my cmake file? or is it a bug in cmake?
note: i'm using qt 5.8 with cmake 3.6 on windows 10 using visual studio 14 2015 generator
update : removing set(CMAKE_AUTOUIC ON) and specifying the ui file with :
qt5_wrap_ui(UI_HEADERS mainwindow.ui)
seems to solve the problem. The original question is still valid, which is how to make this work without specifying the .ui file (by calling qt5_wrap_ui) ?