Skip to content

Commit

Permalink
[docs] Add EXAMPLE_fix_libpng into the main examples document outline
Browse files Browse the repository at this point in the history
  • Loading branch information
ras0219-msft committed Oct 7, 2016
1 parent 1a95b4a commit 91c7d69
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
1 change: 1 addition & 0 deletions docs/EXAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ For short description of available commands, run `vcpkg help`.
- <a href="#example-1-2-c">Option C: Other buildsystems</a>
- <a href="#example-1-2-d">Option D: VS Project (Individual Project integration)</a>
- <a href="#example-2">Example 2: Package a remote project (zlib)</a>
- <a href="example-3-patch-libpng.md">Example 3: Patching libpng to work for uwp-x86</a>

<a name="example-1"></a>
## Example 1: C++ REST SDK
Expand Down
27 changes: 14 additions & 13 deletions docs/EXAMPLE_fix_libpng.md → docs/example-3-patch-libpng.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Fixing libpng:x86-uwp
=====================
## Example 3: Patching libpng to work for uwp-x86

### Initial error logs
First, try building:

```
Expand Down Expand Up @@ -59,6 +59,9 @@ Next, looking at the above logs (build-...-out.log and build-...-err.log).
Time Elapsed 00:00:04.19
```

### Identify the problematic code

Taking a look at [MSDN](https://msdn.microsoft.com/en-us/library/windows/desktop/ms682658(v=vs.85).aspx) shows that `ExitProcess` is only available for desktop apps. Additionally, it's useful to see the surrounding context:

```c
Expand Down Expand Up @@ -107,7 +110,9 @@ This already gives us some great clues, but the full definition tells the comple
#endif
```

`abort()` is a standard CRT call and certainly available in UWP, so we just need to convince libpng to be more platform agnostic. The easiest and most reliable way to achive is to patch the code; while in this particular case we could pass in a compiler flag to override `PNG_ABORT` because this is a private header, in general it is more reliable to avoid adding more required compiler switches when possible (especially when it isn't already exposed as a CMake option).
`abort()` is a standard CRT call and certainly available in UWP, so we just need to convince libpng to be more platform agnostic. The easiest and most reliable way to achieve this is to patch the code; while in this particular case we could pass in a compiler flag to override `PNG_ABORT` because this is a private header, in general it is more reliable to avoid adding more required compiler switches when possible (especially when it isn't already exposed as a CMake option).

### Patching the code to improve compatibility

I recommend using git to create the patch file, since you'll already have it installed.
```
Expand Down Expand Up @@ -144,22 +149,18 @@ Finally, we need to apply the patch after extracting the source.
...
vcpkg_extract_source_archive(${ARCHIVE})
find_program(GIT git)
vcpkg_execute_required_process(
COMMAND ${GIT} init
WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR}/src/libpng-1.6.24
LOGNAME git-init
)
execute_process(
COMMAND ${GIT} apply "${CMAKE_CURRENT_LIST_DIR}/use-abort-on-all-platforms.patch" --ignore-whitespace --whitespace=nowarn
WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR}/src/libpng-1.6.24
vcpkg_apply_patches(
SOURCE_PATH ${CURRENT_BUILDTREES_DIR}/src/libpng-1.6.24
PATCHES "${CMAKE_CURRENT_LIST_DIR}/use-abort-on-all-platforms.patch"
)
vcpkg_configure_cmake(
...
```

To be completely sure this works from the top, we need to purge the package:
### Verification

To be completely sure this works from scratch, we need to purge the package:

```
PS D:\src\vcpkg> vcpkg remove --purge libpng:x86-uwp
Expand Down

0 comments on commit 91c7d69

Please sign in to comment.