Skip to content

Commit

Permalink
Finish platform-independent CMake support
Browse files Browse the repository at this point in the history
  • Loading branch information
ckormanyos committed Mar 14, 2023
1 parent 21e7ab2 commit 8536739
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 3 deletions.
40 changes: 39 additions & 1 deletion .github/workflows/xxd.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ------------------------------------------------------------------------------
# Copyright Christopher Kormanyos 2022.
# Copyright Christopher Kormanyos 2022 - 2023.
# Distributed under the Boost Software License,
# Version 1.0. (See accompanying file LICENSE_1_0.txt
# or copy at http://www.boost.org/LICENSE_1_0.txt)
Expand Down Expand Up @@ -53,6 +53,44 @@ jobs:
echo 'create a 3-byte abc-file'
echo "0:61 1:62 2:63" | xxd -r > abc.bin
sha1sum abc.bin | grep a9993e364706816aba3e25717850c26c9cd0d89d
gcc-clang-native-cmake-ninja:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v3
with:
fetch-depth: '0'
- name: install tools
run: sudo apt install dos2unix ninja-build
- name: gcc-clang-native-cmake-ninja
run: |
echo "query GCC version"
g++ -v
echo "build xxd"
echo build xxd
mkdir build
cd build
cmake .. -G Ninja && ninja
echo 'ls -la ./xxd'
ls -la ./xxd
echo 'create zero_a.bin'
echo "010000: 41" | xxd -r > zero_a.bin
echo 'sha1sum zero_a.bin | grep e534caeb1e149b6bc61ea48cf59861c7e15caa63'
sha1sum zero_a.bin | grep e534caeb1e149b6bc61ea48cf59861c7e15caa63
echo 'test with doc/xxd.1'
xxd -l 120 -c 12 ./doc/xxd.1 | grep 'Tony Nugent'
xxd -l 120 -c 12 ./doc/xxd.1 > xxd.1.txt
echo 'unix2dos xxd.1.txt'
unix2dos xxd.1.txt
echo 'sha1sum xxd.1.txt | grep b271bc7fc3716a44830bc33ee3a8313c0d3ab7f7'
sha1sum xxd.1.txt | grep b271bc7fc3716a44830bc33ee3a8313c0d3ab7f7
echo 'test2 with doc/xxd.1'
xxd -s 0x36 -l 13 -c 13 ./doc/xxd.1 | grep '21st May 1996'
echo 'create a 3-byte abc-file'
echo "0:61 1:62 2:63" | xxd -r > abc.bin
sha1sum abc.bin | grep a9993e364706816aba3e25717850c26c9cd0d89d
windows-latest-cmake-ninja:
runs-on: windows-latest
steps:
Expand Down
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ set(EXE xxd)

add_executable(${EXE} ${SOURCES})

if (WIN32)

add_custom_command(
TARGET xxd POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_BINARY_DIR}/xxd.exe
${CMAKE_CURRENT_BINARY_DIR}/xxd.exe
${CMAKE_SOURCE_DIR}
)

endif (WIN32)
24 changes: 24 additions & 0 deletions LICENSE_1_0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

Boost Software License - Version 1.0 - August 17th, 2003

Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:

The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ as a part of the [vim-project](https://www.vim.org).
The version of `xxd` in this repository has been adapted
for MSVC/GCC/clang standalone build.

Build artifacts (i.e., the executable xxd program) are created in CI for both
`Win*` as well as `*nix`. These can be readily found and downloaded for
convenient use without the need to build `ckormanyos/xxd`

## Build

This version of the source code has been adapted for build on both `Win*`
Expand Down Expand Up @@ -36,6 +40,17 @@ cd xxd
g++ -x c -std=c11 -O3 -Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion src/xxd.c -o xxd
```

### Platform-independent build with CMake (and ninja)

Build on the command line with platform-independent CMake (and ninja) is also supported.

```sh
cd xxd
mkdir build
cd build
cmake .. -G Ninja && ninja
```

## Adaptions

The following adaptions have been undertaken.
Expand Down
1 change: 0 additions & 1 deletion xxd.sln
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_doc", "_doc", "{6ABAF5A8-FEB9-467B-8DBC-88F8BC8CFDEC}"
ProjectSection(SolutionItems) = preProject
LICENSE = LICENSE
README.md = README.md
EndProjectSection
EndProject
Expand Down
7 changes: 7 additions & 0 deletions xxd.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@
<ItemGroup>
<ClCompile Include="src\xxd.c" />
</ItemGroup>
<ItemGroup>
<Text Include="CMakeLists.txt" />
<Text Include="LICENSE_1_0.txt" />
</ItemGroup>
<ItemGroup>
<None Include="LICENSE" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
Expand Down
7 changes: 7 additions & 0 deletions xxd.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,11 @@
<Filter>Source Files\src</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Text Include="CMakeLists.txt" />
<Text Include="LICENSE_1_0.txt" />
</ItemGroup>
<ItemGroup>
<None Include="LICENSE" />
</ItemGroup>
</Project>

0 comments on commit 8536739

Please sign in to comment.