Hi,
In order to use gdal library with msvc I used a windows installer from OSGeo4W. Though I couldn’t locate any cmake package files within the installation, it seemed to be correctly detected by find_package
. I put it to the credit of FindGDAL though I don’t know how it works.
Now I want to use also gdal with a gcc or clang compiler, provided by msys2. I installed the ucrt64 version of these compiler and they are functioning as expected.
I’ve just installed gdal again with msys2 in ucrt64 version and now find_package
is messed up. I can see within cmake
variables:
– GDAL_DIR=C:/Users/<userlogin>/<pathtomsys2>/ucrt64/lib/cmake/gdal
– GDAL_FOUND=1
– GDAL_INCLUDE_DIR=GDAL_INCLUDE_DIR-NOTFOUND
Here, again, I don’t know how the new gdal install could have been detected. (Yet my Path
is containing C:/Users/<userlogin>/<pathtomsys2>/ucrt64/lib
)
How can I switch between both versions, ie, if my compiler is msvc, rely on previous detection and when it is gcc or clang, detect, correctly, the msys2 version?
[EDIT] for msys2, cmake configuration files can be found within C:/Users/<userlogin>/<pathtomsys2>/ucrt64/lib/cmake/gdal
Regards,
A.
I tried that:
if(NOT(DEFINED ENV{GDAL_DIR}))
# On windows with 2 installs: an msvc-compiled and a gcc-compiled one.
if(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
# MSVC
if(DEFINED ENV{GDAL_DIR_msvc})
set(ENV{GDAL_DIR} $ENV{GDAL_DIR_msvc})
endif()
elseif(DEFINED ENV{GDAL_DIR_msys2})
# gcc with msys2
set(ENV{GDAL_DIR} $ENV{GDAL_DIR_msys2})
else()
message(WARNING "GDAL NOT FOUND OR NOT PROPERLY INSTALL")
endif()
endif()
And I set two user environment variables:
GDAL_DIR_msvc=C:/OSGeo4W/include
GDAL_DIR_msys2=C:/Users/<userlogin>/<pathtomsys2>/ucrt64/lib/cmake/gdal
GDAL_DIR_msvc
is pointing to the directory containing gdal.h
.
Yet, when using msvc, $ENV{GDAL_DIR}
is C:/OSGeo4W/include
as expected but msys2 is still detected thus compilation fails due to ABI discrepancies.
I don’t understand how find_package
could find again the msys2 version.
[EDIT] looking in debug mode, the issue is that find_package
is looking for a gdal-config.cmake
. In C:/OSGeo4W/
and its sub-directories there are no such files but FindGDAL module should be able to pick gdal.h
in the includes
folder. Yet, I’ve got C:/Users/<userlogin>/<pathtomsys2>/ucrt64/lib
in my user Path
, and find_package
starts by looking inside Path
and finds a gdal-config.cmake
.
How can I prevent, only for this library, when using MSVC find_package
to look for gdal there. The solution must not change find_package
behavior for other dependencies. For instance, I would have hope that having set GDAL_ENV
or GDAL_ROOT
would have give priority to this directory whatever the mode used (config or module). Is there a Package/CMake variable to tell wich mode to use?