Regression: FindGLUT ignores the sysroot and adds the /usr/include from host system
Hello. While working on !7743 (closed) I suddenly got an error about the conflicting declarations:
In file included from /usr/include/stdlib.h:395,
from /usr/lib/gcc/x86_64-w64-mingw32/11.2.1/include/mm_malloc.h:27,
from /usr/lib/gcc/x86_64-w64-mingw32/11.2.1/include/xmmintrin.h:34,
from /usr/lib/gcc/x86_64-w64-mingw32/11.2.1/include/immintrin.h:31,
from /usr/lib/gcc/x86_64-w64-mingw32/11.2.1/include/x86intrin.h:32,
from /usr/x86_64-w64-mingw32/sys-root/mingw/include/winnt.h:1555,
from /usr/x86_64-w64-mingw32/sys-root/mingw/include/minwindef.h:163,
from /usr/x86_64-w64-mingw32/sys-root/mingw/include/windef.h:9,
from /usr/x86_64-w64-mingw32/sys-root/mingw/include/windows.h:69,
from /usr/include/GL/freeglut_std.h:63,
from /usr/include/GL/glut.h:17,
from /home/afails/Документы/proj/light_repo/src/light_fonts.cpp:3:
/usr/include/sys/types.h:108:19: error: conflicting declaration 'typedef __ssize_t ssize_t'
108 | typedef __ssize_t ssize_t;
| ^~~~~~~
In file included from /usr/x86_64-w64-mingw32/sys-root/mingw/include/crtdefs.h:10,
from /usr/x86_64-w64-mingw32/sys-root/mingw/include/stddef.h:7,
from /usr/lib/gcc/x86_64-w64-mingw32/11.2.1/include/stddef.h:1,
from /home/afails/Документы/proj/light_repo/include/light_fonts.h:6,
from /home/afails/Документы/proj/light_repo/src/light_fonts.cpp:2:
/usr/x86_64-w64-mingw32/sys-root/mingw/include/corecrt.h:50:35: note: previous declaration as 'typedef long long int ssize_t'
50 | __MINGW_EXTENSION typedef __int64 ssize_t;
| ^~~~~~~
After digging I found that the GLUT has the INTERFACE_SYSTEM_INCLUDES with /usr/include:
-- GLUT includes: _incl-NOTFOUND
-- GLUT interface includes: /usr/include
-- GLUT interface system includes: /usr/include
That is disallowed by my toolchain:
set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_CROSSCOMPILING 1)
set(_arch x86_64)
set(CMAKE_SYSROOT "/usr/${_arch}-w64-mingw32/sys-root/")
list(APPEND CMAKE_FIND_ROOT_PATH "${CMAKE_SYSROOT}/mingw/")
# set(CMAKE_AR "${_arch}-w64-mingw32-ar")
# set(CMAKE_RANLIB "x86_64-w64-mingw32-ranlib")
# set(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres)
set(CMAKE_C_COMPILER "/usr/bin/${_arch}-w64-mingw32-gcc")
set(CMAKE_CXX_COMPILER "/usr/bin/${_arch}-w64-mingw32-g++")
#set(CMAKE_C_LINK_EXECUTABLE "${_arch}-w64-mingw32-ld")
#set(CMAKE_CXX_LINK_EXECUTABLE "${_arch}-w64-mingw32-ld")
# Use only CMAKE_FIND_ROOT_PATH for find_library(), find_file(), find_path()
# find_package() may be used not only from root_path
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
# programs are NEVER used from host
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
I think that this regression approached after the 8041ca5d commit and !7252 (merged) as I don't saw this error on (my system) CMake 3.22.
And the proper (but ad-hoc) fix will be is checking the CMAKE_FIND_ROOT_PATH_MODE_INCLUDE
and don't set the env PKG_CONFIG_ALLOW_SYSTEM_CFLAGS here: 8041ca5d - if the CMAKE_FIND_ROOT_PATH_MODE_INCLUDE is set on ONLY
.
Edited by Alex