51 lines
2.1 KiB
CMake
51 lines
2.1 KiB
CMake
# Copyright © 2024 Nicole O'Connor
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
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}) |