@@ -130,23 +130,55 @@ endif()
130130
131131if (WIN32 )
132132
133+ set (_QT_DEPLOY_BIN_HINTS)
134+ foreach (_QT_PREFIX IN LISTS CMAKE_PREFIX_PATH )
135+ if (EXISTS "${_QT_PREFIX} /bin" )
136+ list (APPEND _QT_DEPLOY_BIN_HINTS "${_QT_PREFIX} /bin" )
137+ endif ()
138+ endforeach ()
139+
133140 find_program (
134- DEPLOYQT_EXECUTABLE
135- NAMES windeployqt
136- PATHS ${Qt6_DIR} /bin )
141+ _DEPLOYQT_EXECUTABLE_FROM_PREFIX
142+ NAMES windeployqt windeployqt.exe
143+ PATHS ${_QT_DEPLOY_BIN_HINTS}
144+ NO_DEFAULT_PATH )
145+
146+ if (_DEPLOYQT_EXECUTABLE_FROM_PREFIX)
147+ set (DEPLOYQT_EXECUTABLE
148+ "${_DEPLOYQT_EXECUTABLE_FROM_PREFIX} "
149+ CACHE FILEPATH "Path to the windeployqt executable matching the configured Qt prefix"
150+ FORCE )
151+ else ()
152+ find_program (DEPLOYQT_EXECUTABLE NAMES windeployqt windeployqt.exe )
153+ endif ()
137154
138- # look for Rtools from most newest to oldest
139- message (CHECK_START "Looking for Rtools $ENV{RTOOLS45_HOME} " )
155+ message (STATUS " ${DEPLOYQT_EXECUTABLE} " )
156+
157+ message (CHECK_START "Looking for Rtools $ENV{RTOOLS45_HOME} " )
140158 if (DEFINED ENV{RTOOLS45_HOME})
141- set (RTOOLS_PATH "$ENV{RTOOLS45_HOME} /ucrt64" CACHE PATH "Path to Rtools45 x64 folder, e.g., C:/rtools45/ucrt64" )
159+ file (TO_CMAKE_PATH "$ENV{RTOOLS45_HOME} " _RTOOLS45_HOME )
160+ set (RTOOLS_ROOT "${_RTOOLS45_HOME} " CACHE PATH "Path to Rtools45 installation root, e.g., C:/rtools45" )
142161 else ()
143- set (RTOOLS_PATH "C:/rtools45/ucrt64 " CACHE PATH "Path to Rtools45 x64 folder , e.g., C:/rtools45/ucrt64 " )
162+ set (RTOOLS_ROOT "C:/rtools45" CACHE PATH "Path to Rtools45 installation root , e.g., C:/rtools45" )
144163 endif ()
164+ set (RTOOLS_PATH "${RTOOLS_ROOT} /ucrt64" CACHE PATH "Path to Rtools45 UCRT64 package folder, e.g., C:/rtools45/ucrt64" )
165+
166+ get_filename_component (_RTOOLS_ROOT_FROM_UCRT "${RTOOLS_PATH} " DIRECTORY )
167+ set (RTOOLS_STATIC_TOOLCHAIN_PATH
168+ "${_RTOOLS_ROOT_FROM_UCRT} /x86_64-w64-mingw32.static.posix"
169+ CACHE PATH
170+ "Path to Rtools45 static.posix compiler toolchain, e.g., C:/rtools45/x86_64-w64-mingw32.static.posix" )
171+ set (RTOOLS_BUILD_TOOLS_PATH
172+ "${_RTOOLS_ROOT_FROM_UCRT} /usr"
173+ CACHE PATH
174+ "Path to Rtools45 MSYS build tools, e.g., C:/rtools45/usr" )
145175
146176 if (EXISTS ${RTOOLS_PATH} )
147177
148178 message (CHECK_PASS "found" )
149- message (STATUS " ${RTOOLS_PATH} " )
179+ message (STATUS " UCRT package path: ${RTOOLS_PATH} " )
180+ message (STATUS " static toolchain: ${RTOOLS_STATIC_TOOLCHAIN_PATH} " )
181+ message (STATUS " build tools: ${RTOOLS_BUILD_TOOLS_PATH} " )
150182
151183 message (CHECK_START
152184 "Looking for Rtools legacy and auto remove it, if not work please remove such `RTOOLS44_HOME` manually from Windows environment settings."
@@ -164,10 +196,23 @@ if(WIN32)
164196 else ()
165197 message (
166198 FATAL_ERROR
167- "Rtools not found. Rtools is required for building on Windows, please follow the build instruction before you continue. If you have installed the MINGW in a custom location, you can set the RTOOLS_PATH to your MinGW x64 path, e.g., C:/rtools45/ucrt64"
199+ "Rtools not found. Rtools is required for building on Windows, please follow the build instruction before you continue. If you have installed the MINGW in a custom location, you can set the RTOOLS_PATH to your UCRT64 package path, e.g., C:/rtools45/ucrt64"
168200 )
169201 endif ()
170202
203+ if (NOT EXISTS "${RTOOLS_STATIC_TOOLCHAIN_PATH} /bin/gcc.exe"
204+ OR NOT EXISTS "${RTOOLS_STATIC_TOOLCHAIN_PATH} /bin/g++.exe" )
205+ message (
206+ FATAL_ERROR
207+ "Rtools static.posix compiler toolchain not found. Set RTOOLS_STATIC_TOOLCHAIN_PATH to the Rtools static toolchain path, e.g., C:/rtools45/x86_64-w64-mingw32.static.posix" )
208+ endif ()
209+
210+ if (NOT EXISTS "${RTOOLS_BUILD_TOOLS_PATH} /bin/make.exe" )
211+ message (
212+ FATAL_ERROR
213+ "Rtools MSYS make not found. Set RTOOLS_BUILD_TOOLS_PATH to the Rtools build tools path, e.g., C:/rtools45/usr" )
214+ endif ()
215+
171216 if (DEFINED ENV{WIX})
172217 set (WIX_PATH "$ENV{WIX} /bin" CACHE PATH "Path to your WIX installation, e.g., C:\\ Program Files (x86)\\ WiX Toolset v3.11\\ bin" )
173218 else ()
@@ -207,9 +252,12 @@ if(WIN32)
207252 LIGHT_EXECUTABLE_NATIVE )
208253 message (STATUS " ${LIGHT_EXECUTABLE_NATIVE} " )
209254
210- set (RTOOLS_C_COMPILER "${RTOOLS_PATH} /bin/gcc.exe" )
211- set (RTOOLS_CXX_COMPILER "${RTOOLS_PATH} /bin/g++.exe" )
212- set (RTOOLS_MAKE_PROGRAM "${RTOOLS_PATH} /bin/mingw32-make.exe" )
255+ set (RTOOLS_STATIC_TOOLCHAIN_BIN "${RTOOLS_STATIC_TOOLCHAIN_PATH} /bin" )
256+ set (RTOOLS_BUILD_TOOLS_BIN "${RTOOLS_BUILD_TOOLS_PATH} /bin" )
257+ set (RTOOLS_C_COMPILER "${RTOOLS_STATIC_TOOLCHAIN_BIN} /gcc.exe" )
258+ set (RTOOLS_CXX_COMPILER "${RTOOLS_STATIC_TOOLCHAIN_BIN} /g++.exe" )
259+ set (RTOOLS_MAKE_PROGRAM "${RTOOLS_BUILD_TOOLS_BIN} /make.exe" )
260+ set (RTOOLS_R_INTERFACE_GENERATOR "Unix Makefiles" )
213261
214262endif ()
215263
0 commit comments