diff --git a/CMakeLists.txt b/CMakeLists.txt index a36803e..b0eef11 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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}) diff --git a/cmake/linux-mingw32.cmake b/cmake/linux-mingw32.cmake new file mode 100644 index 0000000..2044a7e --- /dev/null +++ b/cmake/linux-mingw32.cmake @@ -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) \ No newline at end of file diff --git a/cmake/linux-mingw64.cmake b/cmake/linux-mingw64.cmake new file mode 100644 index 0000000..db4bd70 --- /dev/null +++ b/cmake/linux-mingw64.cmake @@ -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) \ No newline at end of file diff --git a/cmake/modules/Find7Zip.cmake b/cmake/modules/Find7Zip.cmake index 3448a28..e4d33df 100644 --- a/cmake/modules/Find7Zip.cmake +++ b/cmake/modules/Find7Zip.cmake @@ -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\\" diff --git a/cmake/modules/FindLibUSB.cmake b/cmake/modules/FindLibUSB.cmake index e9a5944..5233e48 100644 --- a/cmake/modules/FindLibUSB.cmake +++ b/cmake/modules/FindLibUSB.cmake @@ -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) diff --git a/doc/compiling.md b/doc/compiling.md index 74a8a34..555dce4 100644 --- a/doc/compiling.md +++ b/doc/compiling.md @@ -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 +cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=./cmake/linux-mingw32.cmake -S . -B ./build/linux-mingw32 +cmake --build ./build/linux-mingw32 --target all +``` diff --git a/src/mingw/mingw.h b/src/mingw/mingw.h index 2efd1ab..4fe07e6 100644 --- a/src/mingw/mingw.h +++ b/src/mingw/mingw.h @@ -8,7 +8,7 @@ #endif #include -#include +#include #if defined(_MSC_VER) #pragma comment(lib, "ws2_32.lib") #endif