From 6c818f6e8a631c0e85e474104cc47cc0abe2ec5a Mon Sep 17 00:00:00 2001
From: Tim Stahlhut <stahta01@gmail.com>
Date: Wed, 5 Nov 2025 13:14:48 -0500
Subject: Guard WXWIN and other stuff with FOR_MSYS2_PACKAGE

---
 CMakeLists.txt                  | 20 +++++++++++---------
 CodeFormatter/CMakeLists.txt    |  2 +-
 DatabaseExplorer/CMakeLists.txt |  4 ++--
 LanguageServer/CMakeLists.txt   |  2 +-
 4 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 45c7f8502..bedc6c69d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -77,13 +77,15 @@ endif()
 if(MINGW)
   set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install")
   set(CL_PREFIX "${CMAKE_INSTALL_PREFIX}")
-  if(NOT DEFINED ENV{MSYS2_BASE})
-    message(
-      FATAL_ERROR
-        "Set the environment variable MSYS2_BASE to point to the installation of your MSYS2. e.g. export MSYS2_BASE=C:/msys64"
-    )
+  if(NOT FOR_MSYS2_PACKAGE)
+    if(NOT DEFINED ENV{MSYS2_BASE})
+      message(
+        FATAL_ERROR
+          "Set the environment variable MSYS2_BASE to point to the installation of your MSYS2. e.g. export MSYS2_BASE=C:/msys64"
+      )
+    endif()
+    set(MSYS2_BASE $ENV{MSYS2_BASE})
   endif()
-  set(MSYS2_BASE $ENV{MSYS2_BASE})
 elseif(UNIX AND NOT APPLE)
   if(CL_PREFIX)
     # user provided CL_PREFIX -> use it instead of CMAKE_INSTALL_PREFIX
@@ -467,7 +469,7 @@ if(UNIX AND NOT APPLE)
 endif(UNIX AND NOT APPLE)
 
 # find wxWidgets once
-if(MINGW)
+if(MINGW AND NOT FOR_MSYS2_PACKAGE)
   if(NOT WXWIN)
     message(FATAL_ERROR "Missing -DWXWIN=<wxWidgets/root/install/dir>")
   endif()
@@ -1136,7 +1138,7 @@ if(NOT WXC_APP)
 
 endif()
 
-if(MINGW)
+if(MINGW AND NOT FOR_MSYS2_PACKAGE)
   # determine MSYS2 path
   write_file(${CMAKE_BINARY_DIR}/msys2-environment "export WXWIN=${WXWIN}")
   write_file(${CMAKE_BINARY_DIR}/msys2-environment
@@ -1218,7 +1220,7 @@ if(MINGW)
 
 endif()
 
-if(MINGW AND NOT WXC_APP)
+if(MINGW AND NOT WXC_APP AND NOT FOR_MSYS2_PACKAGE)
   # configure the innosetup file
   configure_file(${CL_SRC_ROOT}/InnoSetup/codelite64_mingw.iss.in
                  ${BUILD_DIRECTORY}/codelite64_mingw.iss)
diff --git a/CodeFormatter/CMakeLists.txt b/CodeFormatter/CMakeLists.txt
index 35443f1f5..d9331c834 100644
--- a/CodeFormatter/CMakeLists.txt
+++ b/CodeFormatter/CMakeLists.txt
@@ -33,7 +33,7 @@ target_link_libraries(${PLUGIN_NAME} ${LINKER_OPTIONS} libcodelite plugin)
 
 cl_install_plugin(${PLUGIN_NAME})
 
-if(MINGW)
+if(MINGW AND NOT FOR_MSYS2_PACKAGE)
     # install clang-format
     msys_install_clang64_tool(clang-format.exe ${CL_INSTALL_BIN})
 endif()
diff --git a/DatabaseExplorer/CMakeLists.txt b/DatabaseExplorer/CMakeLists.txt
index f0d5fea50..17f065041 100644
--- a/DatabaseExplorer/CMakeLists.txt
+++ b/DatabaseExplorer/CMakeLists.txt
@@ -18,7 +18,7 @@ if(WITH_MYSQL)
     endif(${LIBMYSQLCLIENT} STREQUAL "LIBMYSQLCLIENT-NOTFOUND")
     add_compile_definitions(DBL_USE_MYSQL=1)
 
-    if(MINGW)
+    if(MINGW AND NOT FOR_MSYS2_PACKAGE)
         install(FILES "${MSYS2_BASE}/clang64/bin/libmariadb.dll" DESTINATION "${CL_INSTALL_BIN}")
         msys_list_deps(${MSYS2_BASE}/clang64/bin/libmariadb.dll LIBMARIA_DEPS)
         foreach(DEP ${LIBMARIA_DEPS})
@@ -33,7 +33,7 @@ if(WITH_POSTGRES)
 
     add_compile_definitions(DBL_USE_POSTGRES=1)
 
-    if(MINGW)
+    if(MINGW AND NOT FOR_MSYS2_PACKAGE)
         install(FILES "${MSYS2_BASE}/clang64/bin/libpq.dll" DESTINATION "${CL_INSTALL_BIN}")
         msys_list_deps(${MSYS2_BASE}/clang64/bin/libpq.dll LIBPOSTGRES_DEPS)
         foreach(DEP ${LIBPOSTGRES_DEPS})
diff --git a/LanguageServer/CMakeLists.txt b/LanguageServer/CMakeLists.txt
index 0b6c27802..dee9919a2 100644
--- a/LanguageServer/CMakeLists.txt
+++ b/LanguageServer/CMakeLists.txt
@@ -52,7 +52,7 @@ if(APPLE)
         PERMISSIONS ${EXE_PERM})
 endif()
 
-if(MINGW)
+if(MINGW AND NOT FOR_MSYS2_PACKAGE)
     # install clangd
     msys_install_clang64_tool(clangd.exe ${CL_INSTALL_BIN})
 endif()
-- 
2.48.1.windows.1

