Skip to content

Commit

Permalink
Improve toolchain for cross compiling.
Browse files Browse the repository at this point in the history
This relates to the problem discussed on PR #3631.

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
  • Loading branch information
micheleCTDE committed Jun 18, 2022
1 parent 8af3b9b commit 6b46c52
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 24 deletions.
15 changes: 3 additions & 12 deletions cmake/Toolchain-mingw32.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,15 @@
set(CMAKE_SYSTEM_NAME Windows)

if(NOT COMPILER_PREFIX)
if(EXISTS /usr/i686-w64-mingw32)
# mingw-w64
set(COMPILER_PREFIX "i686-w64-mingw32")
elseif(EXISTS /usr/i586-mingw32msvc)
if(EXISTS /usr/i586-mingw32msvc)
# mingw
set(COMPILER_PREFIX "i586-mingw32msvc")
else()
message(FATAL_ERROR "Unable to detect cross-compiler prefix (COMPILER_PREFIX)")
# default to mingw-w64
set(COMPILER_PREFIX "i686-w64-mingw32")
endif()
endif()

find_program(CMAKE_C_COMPILER NAMES ${COMPILER_PREFIX}-gcc)
find_program(CMAKE_CXX_COMPILER NAMES ${COMPILER_PREFIX}-g++)
find_program(CMAKE_RC_COMPILER NAMES ${COMPILER_PREFIX}-windres)

set(CMAKE_FIND_ROOT_PATH /usr/${COMPILER_PREFIX})

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
15 changes: 3 additions & 12 deletions cmake/Toolchain-mingw64.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,15 @@
set(CMAKE_SYSTEM_NAME Windows)

if(NOT COMPILER_PREFIX)
if(EXISTS /usr/x86_64-w64-mingw32)
# mingw-w64
set(COMPILER_PREFIX "x86_64-w64-mingw32")
elseif(EXISTS /usr/amd64-mingw32msvc-gcc)
if(EXISTS /usr/amd64-mingw32msvc-gcc)
# mingw
set(COMPILER_PREFIX "amd64-mingw32msvc-gcc")
else()
message(FATAL_ERROR "Unable to detect cross-compiler prefix (COMPILER_PREFIX)")
# default to mingw-w64
set(COMPILER_PREFIX "x86_64-w64-mingw32")
endif()
endif()

find_program(CMAKE_C_COMPILER NAMES ${COMPILER_PREFIX}-gcc)
find_program(CMAKE_CXX_COMPILER NAMES ${COMPILER_PREFIX}-g++)
find_program(CMAKE_RC_COMPILER NAMES ${COMPILER_PREFIX}-windres)

set(CMAKE_FIND_ROOT_PATH /usr/${COMPILER_PREFIX})

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

0 comments on commit 6b46c52

Please sign in to comment.