Skip to content

Commit

Permalink
docs: Update MinGW + MSYS2 documentation and setup (#239)
Browse files Browse the repository at this point in the history
  • Loading branch information
Amphaal authored May 5, 2020
1 parent 4c22116 commit c3fbaf1
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 2 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,26 @@ or use it on the command line.
[cmake]: https://cmake.org/cmake/help/latest/
[cmake guide]: https://developer.android.com/ndk/guides/cmake

**MinGW**:

64-bits is the only platform supported for now.
LLVM + Clang are mandatory here : they are required to generate .pdb files, used by Crashpad for the report generation.

For your application to generate the appropriate .pdb output, you need to activate CodeView file format generation on your application target. To do so, update your own CMakeLists.txt with something like `target_compile_options(${yourApplicationTarget} PRIVATE -gcodeview)`.

If you use a MSYS2 environement to compile with MinGW, make sure to :

- Create an environement variable `MINGW_ROOT` (ex : `C:/msys64/mingw64`)
- Run from `mingw64.exe` : `pacman -S --needed - < ./toolchains/msys2-mingw64-pkglist.txt`
- Build as :

```sh
# Configure with Ninja as generator and use the MSYS2 toolchain file
$ cmake -GNinja -Bbuild -H. -DCMAKE_TOOLCHAIN_FILE=toolchains/msys2.cmake
# build with Ninja
$ ninja -C build
```

### Compile-Time Options

The following options can be set when running the cmake generator, for example
Expand Down
2 changes: 1 addition & 1 deletion external/crashpad
Submodule crashpad updated 1 files
+7 −0 util/CMakeLists.txt
3 changes: 2 additions & 1 deletion tests/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ target_link_libraries(sentry_test_unit PRIVATE

if(MINGW)
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_link_options(sentry_test_unit PRIVATE -Wl,-pdb=) # IMPORTANT ! MUST generate pdb files
target_link_options(sentry_test_unit PRIVATE -Wl,-pdb=) # IMPORTANT ! LLD must generate pdb files
target_compile_options(sentry_test_unit PRIVATE -gcodeview) # IMPORTANT ! Clang must generate pdb to CodeView format
else()
message(FATAL_ERROR "Tests will not pass on MinGW if your compiler cannot generate .pdb files ! Please use Clang instead")
endif()
Expand Down
5 changes: 5 additions & 0 deletions toolchains/msys2-mingw64-pkglist.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mingw64/mingw-w64-x86_64-uasm
mingw64/mingw-w64-x86_64-clang
mingw64/mingw-w64-x86_64-lld
mingw64/mingw-w64-x86_64-ninja
mingw64/mingw-w64-x86_64-cmake
33 changes: 33 additions & 0 deletions toolchains/msys2.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
if(NOT DEFINED MINGW_ROOT)
if(DEFINED ENV{MINGW_ROOT})
SET(MINGW_ROOT $ENV{MINGW_ROOT})
elseif(DEFINED ENV{MINGW64_ROOT})
SET(MINGW_ROOT $ENV{MINGW64_ROOT})
elseif(DEFINED ENV{MINGW32_ROOT})
SET(MINGW_ROOT $ENV{MINGW32_ROOT})
else()
message(FATAL_ERROR "Required variable MINGW_ROOT is not defined. Please check README.md for more details !")
endif()
endif()

# search for programs in the build host directories
set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)

# for libraries and headers in the target directories
set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set (CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

list(APPEND CMAKE_PREFIX_PATH
${MINGW_ROOT}
)

SET (CMAKE_ASM_MASM_COMPILER "uasm")
SET (CMAKE_C_COMPILER "clang")
SET (CMAKE_CXX_COMPILER "clang++")

SET (CMAKE_C_FLAGS "-fuse-ld=lld")
SET (CMAKE_CXX_FLAGS ${CMAKE_C_FLAGS})

SET (CMAKE_C_FLAGS_DEBUG "-O0 -g")
SET (CMAKE_CXX_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})

0 comments on commit c3fbaf1

Please sign in to comment.