37 lines
1.6 KiB
CMake
37 lines
1.6 KiB
CMake
|
set(QT_VERSION_STR "5.15.2")
|
||
|
set(CMAKE_PREFIX_PATH "C:\\Qt\\${QT_VERSION_STR}\\msvc2019_64")
|
||
|
find_package(Qt5 COMPONENTS Core Widgets REQUIRED)
|
||
|
set(QT_UIC_EXECUTABLE "C:\\Qt\\${QT_VERSION_STR}\\msvc2019_64\\bin\\uic.exe")
|
||
|
|
||
|
file(STRINGS "${CMAKE_SOURCE_DIR}/res/moc.txt" mocfiles)
|
||
|
|
||
|
set(mocdeps)
|
||
|
|
||
|
foreach(moctgt ${mocfiles})
|
||
|
string(REPLACE "include/" "include/moc/" outfile ${moctgt})
|
||
|
add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${outfile}"
|
||
|
COMMAND moc ${CMAKE_SOURCE_DIR}/${moctgt} -o ${CMAKE_CURRENT_BINARY_DIR}/${outfile}
|
||
|
COMMENT "Running moc for ${outfile}..."
|
||
|
DEPENDS "${CMAKE_SOURCE_DIR}/${moctgt}")
|
||
|
set (mocdeps ${mocdeps} ${outfile})
|
||
|
endforeach()
|
||
|
|
||
|
file(GLOB_RECURSE uilist RELATIVE "${CMAKE_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}/res/ui/*.ui")
|
||
|
set(uicsources)
|
||
|
foreach(uifile ${uilist})
|
||
|
string(REGEX REPLACE "res/ui/" "" uiname ${uifile})
|
||
|
string(REGEX REPLACE ".ui\$" "" uiname ${uiname})
|
||
|
string(REGEX REPLACE "/" "_" uiname ${uiname})
|
||
|
# res/ui/dlg/license.ui should result in ${uiname} being "dlg_license" at this point
|
||
|
|
||
|
set(headerfile "${CMAKE_CURRENT_BINARY_DIR}/include/ui_${uiname}.h")
|
||
|
|
||
|
add_custom_command(OUTPUT "${headerfile}" PRE_BUILD
|
||
|
COMMAND ${QT_UIC_EXECUTABLE} -o "${headerfile}" "${CMAKE_SOURCE_DIR}/${uifile}"
|
||
|
DEPENDS "${CMAKE_SOURCE_DIR}/${uifile}"
|
||
|
COMMENT "Qt UIC: ${BoldCyan}${uifile}${ColourReset}")
|
||
|
|
||
|
set(uicsources ${uicsources} "${headerfile}")
|
||
|
endforeach()
|
||
|
|
||
|
add_custom_target(qtgenerated DEPENDS ${mocdeps} ${uicsources})
|