From a20fe51cf15922331125ed30bfbfcc926b6c5e47 Mon Sep 17 00:00:00 2001
From: Even Rouault <even.rouault@spatialys.com>
Date: Tue, 14 Jan 2025 15:09:24 +0100
Subject: [PATCH] CMake: avoid issue with MSBuild and 'GDAL' vs 'gdal' target
 names (master only)

---
 apps/CMakeLists.txt | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt
index 47492b836e30..1494802f1818 100644
--- a/apps/CMakeLists.txt
+++ b/apps/CMakeLists.txt
@@ -70,7 +70,12 @@ target_public_header(TARGET ${GDAL_LIB_TARGET_NAME} HEADERS gdal_utils.h)
 
 if (BUILD_APPS)
   # Default Apps
-  add_executable(gdal gdal_utils_priv.h gdal.cpp)
+
+  # MSBuild has case-insensitive target names, so as GDAL is used as the
+  # target name for the library, we cannot reuse it for the "gdal" binary.
+  add_executable(gdal_app gdal_utils_priv.h gdal.cpp)
+  set_target_properties(gdal_app PROPERTIES OUTPUT_NAME gdal)
+
   add_executable(gdalinfo gdal_utils_priv.h gdalinfo_bin.cpp)
   add_executable(gdalbuildvrt gdal_utils_priv.h gdalbuildvrt_bin.cpp)
   add_executable(gdaladdo gdal_utils_priv.h gdaladdo.cpp)
@@ -111,7 +116,7 @@ if (BUILD_APPS)
   add_dependencies(utils_common generate_gdal_version_h)
 
   set(APPS_TARGETS
-      gdal
+      gdal_app
       gdalinfo
       gdalbuildvrt
       gdaladdo