Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build for windows under Debian/Ubuntu #802

Merged
merged 1 commit into from
May 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ set(STLINK_SOURCE

if (WIN32 OR MSYS OR MINGW)
set (STLINK_SOURCE "${STLINK_SOURCE};src/mmap.c;src/mingw/mingw.c")
set (STLINK_HEADERS "${STLINK_HEADERS};src/mingw/mingw.h")
endif ()

include_directories(${LIBUSB_INCLUDE_DIR})
Expand Down
25 changes: 25 additions & 0 deletions cmake/linux-mingw32.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Sample toolchain file for building for Windows from an Debian/Ubuntu Linux system.
#
# Typical usage:
# *) install cross compiler: `sudo apt-get install mingw-w64`
# *) cd build
# *) cmake -DCMAKE_TOOLCHAIN_FILE=./cmake/linux-mingw32.cmake ..

set(CMAKE_SYSTEM_NAME Windows)
set(TOOLCHAIN_PREFIX i686-w64-mingw32)

# cross compilers to use for C and C++
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres)

# target environment on the build host system
# set 1st to dir with the cross compiler's C/C++ headers/libs
set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX})

# modify default behavior of FIND_XXX() commands to
# search for headers/libs in the target environment and
# search for programs in the build 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)
25 changes: 25 additions & 0 deletions cmake/linux-mingw64.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Sample toolchain file for building for Windows from an Ubuntu Linux system.
#
# Typical usage:
# *) install cross compiler: `sudo apt-get install mingw-w64`
# *) cd build
# *) cmake -DCMAKE_TOOLCHAIN_FILE=./cmake/linux-mingw64.cmake ..

set(CMAKE_SYSTEM_NAME Windows)
set(TOOLCHAIN_PREFIX x86_64-w64-mingw32)

# cross compilers to use for C and C++
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres)

# target environment on the build host system
# set 1st to dir with the cross compiler's C/C++ headers/libs
set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX})

# modify default behavior of FIND_XXX() commands to
# search for headers/libs in the target environment and
# search for programs in the build 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)
2 changes: 1 addition & 1 deletion cmake/modules/Find7Zip.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
find_program(ZIP_EXECUTABLE NAMES 7z.exe
find_program(ZIP_EXECUTABLE NAMES 7z.exe p7zip
HINTS
"C:\\Program Files\\7-Zip\\"
"C:\\Program Files (x86)\\7-Zip\\"
Expand Down
29 changes: 24 additions & 5 deletions cmake/modules/FindLibUSB.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -82,28 +82,47 @@ if(NOT LIBUSB_FOUND)
)
endif()
file(MAKE_DIRECTORY ${LIBUSB_WIN_OUTPUT_FOLDER})
execute_process(COMMAND ${ZIP_EXECUTABLE} x -y ${LIBUSB_WIN_ARCHIVE_PATH} -o${LIBUSB_WIN_OUTPUT_FOLDER})

if(${ZIP_EXECUTABLE} MATCHES "p7zip")
execute_process(COMMAND ${ZIP_EXECUTABLE} -d --keep -f ${LIBUSB_WIN_ARCHIVE_PATH} WORKING_DIRECTORY ${LIBUSB_WIN_OUTPUT_FOLDER})
else()
execute_process(COMMAND ${ZIP_EXECUTABLE} x -y ${LIBUSB_WIN_ARCHIVE_PATH} -o${LIBUSB_WIN_OUTPUT_FOLDER})
endif()

FIND_PATH(LIBUSB_INCLUDE_DIR NAMES libusb.h
HINTS ${LIBUSB_WIN_OUTPUT_FOLDER}/include
PATH_SUFFIXES libusb-1.0
NO_DEFAULT_PATH
NO_CMAKE_FIND_ROOT_PATH
)

if (MSYS OR MINGW)
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
find_library(LIBUSB_LIBRARY NAMES ${LIBUSB_NAME}
HINTS ${LIBUSB_WIN_OUTPUT_FOLDER}/MinGW64/static)
HINTS ${LIBUSB_WIN_OUTPUT_FOLDER}/MinGW64/static
NO_DEFAULT_PATH
NO_CMAKE_FIND_ROOT_PATH
)
else ()
find_library(LIBUSB_LIBRARY NAMES ${LIBUSB_NAME}
HINTS ${LIBUSB_WIN_OUTPUT_FOLDER}/MinGW32/static)
HINTS ${LIBUSB_WIN_OUTPUT_FOLDER}/MinGW32/static
NO_DEFAULT_PATH
NO_CMAKE_FIND_ROOT_PATH
)
endif ()
elseif(MSVC)
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
find_library(LIBUSB_LIBRARY NAMES ${LIBUSB_NAME}
HINTS ${LIBUSB_WIN_OUTPUT_FOLDER}/MS64/dll)
HINTS ${LIBUSB_WIN_OUTPUT_FOLDER}/MS64/dll
NO_DEFAULT_PATH
NO_CMAKE_FIND_ROOT_PATH
)
else ()
find_library(LIBUSB_LIBRARY NAMES ${LIBUSB_NAME}
HINTS ${LIBUSB_WIN_OUTPUT_FOLDER}/MS32/dll)
HINTS ${LIBUSB_WIN_OUTPUT_FOLDER}/MS32/dll
NO_DEFAULT_PATH
NO_CMAKE_FIND_ROOT_PATH
)
endif ()
endif ()
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Libusb DEFAULT_MSG LIBUSB_LIBRARY LIBUSB_INCLUDE_DIR)
Expand Down
21 changes: 21 additions & 0 deletions doc/compiling.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,24 @@ NOTES: This solution will link to the dll version of libusb-1.0. To debug or ru
be either on the path, or in the same folder as the executable. It can be copied from here:
`build\3thparty\libusb-1.0.21\MS32\dll\libusb-1.0.dll`.

## Linux (MinGW64)

### Prequistes

* 7Zip
* CMake 2.8 or higher
* MinGW64 GCC toolchain (5.3.0)

### Installation (Debian / Ubuntu)

sudo apt install p7zip mingw-w64

### Building

These instructions are for a 32bit version.

```sh
cd <source-dir>
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=./cmake/linux-mingw32.cmake -S . -B ./build/linux-mingw32
cmake --build ./build/linux-mingw32 --target all
```
2 changes: 1 addition & 1 deletion src/mingw/mingw.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#endif

#include <io.h>
#include <WinSock2.h>
#include <winsock2.h>
#if defined(_MSC_VER)
#pragma comment(lib, "ws2_32.lib")
#endif
Expand Down