kopia lustrzana https://github.com/stlink-org/stlink
build wor windows under Debian/Ubuntu (#802)
rodzic
189f253ce3
commit
a3cb1a1569
|
@ -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})
|
||||
|
|
|
@ -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)
|
|
@ -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)
|
|
@ -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\\"
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
```
|
||||
|
|
|
@ -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
|
||||
|
|
Ładowanie…
Reference in New Issue