From e2a1c2a8172fb5c9babda62cc0adb367434a16f5 Mon Sep 17 00:00:00 2001 From: Ivan Tatarinov Date: Thu, 15 Apr 2021 19:21:10 +0300 Subject: [PATCH] sdk: improve `cmake` usage for cross-compilation for Windows platform --- sdk/src/Toolchain-mingw32.cmake | 23 +++++++++++++++++++++++ sdk/src/Toolchain-mingw64.cmake | 23 +++++++++++++++++++++++ sdk/src/sjasmplus.mk | 16 ++++------------ 3 files changed, 50 insertions(+), 12 deletions(-) create mode 100644 sdk/src/Toolchain-mingw32.cmake create mode 100644 sdk/src/Toolchain-mingw64.cmake diff --git a/sdk/src/Toolchain-mingw32.cmake b/sdk/src/Toolchain-mingw32.cmake new file mode 100644 index 0000000..542fd31 --- /dev/null +++ b/sdk/src/Toolchain-mingw32.cmake @@ -0,0 +1,23 @@ +# SPDX-FileCopyrightText: 2021 Ivan Tatarinov +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +# From https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/cross_compiling/Mingw + +# the name of the target operating system +SET(CMAKE_SYSTEM_NAME Windows) + +SET(MINGW_VER i686-w64-mingw32) +# which compilers to use for C and C++ +SET(CMAKE_C_COMPILER ${MINGW_VER}-gcc) +SET(CMAKE_CXX_COMPILER ${MINGW_VER}-g++) +SET(CMAKE_RC_COMPILER ${MINGW_VER}-windres) +# here is the target environment located +SET(CMAKE_FIND_ROOT_PATH /usr/${MINGW_VER} ) + +# adjust the default behaviour of the FIND_XXX() commands: +# search headers and libraries in the target environment, search +# programs in the host environment +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) diff --git a/sdk/src/Toolchain-mingw64.cmake b/sdk/src/Toolchain-mingw64.cmake new file mode 100644 index 0000000..a0af88c --- /dev/null +++ b/sdk/src/Toolchain-mingw64.cmake @@ -0,0 +1,23 @@ +# SPDX-FileCopyrightText: 2021 Ivan Tatarinov +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +# From https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/cross_compiling/Mingw + +# the name of the target operating system +SET(CMAKE_SYSTEM_NAME Windows) + +SET(MINGW_VER x86_64-w64-mingw32) +# which compilers to use for C and C++ +SET(CMAKE_C_COMPILER ${MINGW_VER}-gcc) +SET(CMAKE_CXX_COMPILER ${MINGW_VER}-g++) +SET(CMAKE_RC_COMPILER ${MINGW_VER}-windres) +# here is the target environment located +SET(CMAKE_FIND_ROOT_PATH /usr/${MINGW_VER} ) + +# adjust the default behaviour of the FIND_XXX() commands: +# search headers and libraries in the target environment, search +# programs in the host environment +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) diff --git a/sdk/src/sjasmplus.mk b/sdk/src/sjasmplus.mk index 0fce22c..35cc03b 100644 --- a/sdk/src/sjasmplus.mk +++ b/sdk/src/sjasmplus.mk @@ -20,20 +20,12 @@ include ../../common.mk -CMAKEFLAGS := - ifeq ($(BUILD),mingw32) -CMAKEFLAGS += CMAKE_SYSTEM_NAME=Windows -CMAKEFLAGS += CMAKE_SYSTEM_PROCESSOR=x86 -CMAKEFLAGS += CMAKE_C_COMPILER=i686-w64-mingw32-gcc -CMAKEFLAGS += CMAKE_CXX_COMPILER=i686-w64-mingw32-g++ -CMAKEFLAGS := $(patsubst %,-D%,$(CMAKEFLAGS)) +CMAKEFLAGS := -DCMAKE_TOOLCHAIN_FILE=../Toolchain-mingw32.cmake else ifeq ($(BUILD),mingw64) -CMAKEFLAGS += CMAKE_SYSTEM_NAME=Windows -CMAKEFLAGS += CMAKE_SYSTEM_PROCESSOR=AMD64 -CMAKEFLAGS += CMAKE_C_COMPILER=x86_64-w64-mingw32-gcc -CMAKEFLAGS += CMAKE_CXX_COMPILER=x86_64-w64-mingw32-g++ -CMAKEFLAGS := $(patsubst %,-D%,$(CMAKEFLAGS)) +CMAKEFLAGS := -DCMAKE_TOOLCHAIN_FILE=../Toolchain-mingw64.cmake +else +CMAKEFLAGS := endif SJASMPLUS := sjasmplus$(EXECEXT)