Skip to content

Commit

Permalink
🧑‍💻 Support cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
Freed-Wu committed May 15, 2023
1 parent e15a010 commit e80efc9
Show file tree
Hide file tree
Showing 11 changed files with 329 additions and 48 deletions.
1 change: 1 addition & 0 deletions .cmakelintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
filter=-whitespace/indent
4 changes: 4 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ jobs:
sudo apt install check
- name: Test
# disable bashcov due to bug
# https://bugs.launchpad.net/ubuntu/+source/check/+bug/2019478
run: |
# cmake -Bbuild
# cmake --build build --target check_downsample
# ctest --test-dir build
bats -r .
make check
- uses: codecov/codecov-action@v3
Expand Down
30 changes: 30 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@
/x264
*.264

/build/
/.cache/

*.log
.dirstamp
/config.h
.deps/
*~

/*.cmake
*.ninja
DartConfiguration.tcl

# check
*.trs
*.gcno
Expand Down Expand Up @@ -137,3 +144,26 @@ m4/lt~obsolete.m4
# Generated source files
configure
Makefile

# create by https://github.com/iamcco/coc-gitignore (Fri May 12 2023 20:52:28 GMT+0800 (China Standard Time))
# CMake.gitignore:
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps

# CMake.patch:
# External projects
*-prefix/

# create by https://github.com/iamcco/coc-gitignore (Fri May 12 2023 20:52:35 GMT+0800 (China Standard Time))
# Ninja.gitignore:
.ninja_deps
.ninja_log
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ repos:
rev: v16.0.1
hooks:
- id: clang-format
- repo: https://github.com/cmake-lint/cmake-lint
rev: 1.4.2
hooks:
- id: cmakelint

ci:
skip:
Expand Down
120 changes: 120 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
cmake_minimum_required(VERSION 3.10)
project(
x264-dsp
VERSION 0.0.0.0
DESCRIPTION x264-dsp
HOMEPAGE_URL https://github.com/Freed-Wu/x264-dsp
LANGUAGES C ASM)
# https://discourse.cmake.org/t/how-to-compile-linear-assemble/8122/1
list(APPEND CMAKE_ASM_SOURCE_FILE_EXTENSIONS sa)
file(GLOB SRC *.c common/*.c encoder/*.c)
add_executable(x264 ${SRC} ${ASM_SRC})
install(TARGETS x264 RUNTIME)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
include(CheckLibraryExists)
check_library_exists(m logf "" HAVE_LIB_M)
if(HAVE_LIB_M)
target_link_libraries(x264 PUBLIC m)
endif()

set(_DOC_INPUT_FILENAME
"input filename"
CACHE STRING "")
set(INPUT_FILENAME
"352x288.yuv"
CACHE STRING ${_DOC_INPUT_FILENAME})

set(_DOC_BIN2C
"use bin2c"
CACHE STRING "")
option(BIN2C ${_DOC_BIN2C})
if(BIN2C)
find_program(bin2c REQUIRED NAMES bin2c)
if(NOT EXISTS ${INPUT_FILENAME})
message(FATAL_ERROR "${INPUT_FILENAME} doesn't exist!")
endif()
add_custom_target(yuv.h ALL COMMAND bin2c yuv < ${INPUT_FILENAME} >
${CMAKE_BINARY_DIR}/yuv.h)
add_dependencies(x264 yuv.h)
endif()

set(_DOC_DRY_RUN
"do not write any file"
CACHE STRING "")
option(DRY_RUN ${_DOC_DRY_RUN})

set(_DOC_HAVE_TIC6X
"enable TI C6X asm"
CACHE STRING "")
option(HAVE_TIC6X ${_DOC_HAVE_TIC6X} ON)

set(_DOC_DOWNSAMPLE
"downsample from 720p to 360p, 1, 2 means bilinear, bicubic"
CACHE STRING "")
set(DOWNSAMPLE
0
CACHE STRING ${_DOC_DOWNSAMPLE})
if(NOT (DOWNSAMPLE GREATER_EQUAL 0 AND DOWNSAMPLE LESS 3))
message(FATAL_ERROR "${DOWNSAMPLE} is an invalid DOWNSAMPLE!")
endif()

set(_DOC_PADDING
"padding method, 1..3 means edge, reflect, symmetric"
CACHE STRING "")
set(PADDING
3
CACHE STRING ${_DOC_PADDING})
if(NOT (PADDING GREATER 0 AND PADDING LESS 4))
message(FATAL_ERROR "${PADDING} is an invalid PADDING!")
endif()

set(_DOC_SCALE
"SCALE scale, a positive number"
CACHE STRING "")
set(SCALE
2
CACHE STRING ${_DOC_SCALE})
if(SCALE LESS_EQUAL 0)
message(FATAL_ERROR "${SCALE} is an invalid SCALE!")
endif()

set(_DOC_X264_BIT_DEPTH
"bit depth, can be 8 or 10"
CACHE STRING "")
set(X264_BIT_DEPTH
8
CACHE STRING ${_DOC_X264_BIT_DEPTH})
set(_LIST_X264_BIT_DEPTH 8 10)
if(NOT (X264_BIT_DEPTH IN_LIST _LIST_X264_BIT_DEPTH))
message(FATAL_ERROR "${X264_BIT_DEPTH} is an invalid X264_BIT_DEPTH!")
endif()

set(_DOC_X264_CHROMA_FORMAT
"chroma format, 0..3 means 400, 420, 422, 444"
CACHE STRING "")
set(X264_CHROMA_FORMAT
1
CACHE STRING ${_DOC_X264_CHROMA_FORMAT})
if(NOT (X264_CHROMA_FORMAT GREATER_EQUAL 0 AND X264_CHROMA_FORMAT LESS 4))
message(FATAL_ERROR "${X264_CHROMA_FORMAT} is an invalid X264_CHROMA_FORMAT!")
endif()

set(_DOC_X264_LOG_LEVEL
"log level, 0..3 means error, warning, info, debug"
CACHE STRING "")
set(X264_LOG_LEVEL
2
CACHE STRING ${_DOC_X264_LOG_LEVEL})
if(NOT (X264_LOG_LEVEL GREATER_EQUAL 0 AND X264_LOG_LEVEL LESS 4))
message(FATAL_ERROR "${X264_LOG_LEVEL} is an invalid X264_LOG_LEVEL!")
endif()

configure_file(configure.h.in config.h)

include(CTest)
add_subdirectory(tests EXCLUDE_FROM_ALL)

set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
set(CPACK_ARCHIVE_THREADS 0)
set(CPACK_THREADS 0)
128 changes: 80 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,13 @@ Inter-Predict, CABAC, etc.

Add an optional downsample module.

## Generate a Source Distribution
## Dependencies

In order to generate a source distribution, install:
## Build Systems

- [autoconf](https://www.gnu.org/software/autoconf)
- [automake](https://www.gnu.org/software/automake)
You have 2 methods to build this project:

Then:

```shell
autoreconf -vif
```

## Build
For `autotools`:

Download
[a source distribution](https://github.com/Freed-Wu/x264-dsp/releases), then
Expand All @@ -31,57 +24,61 @@ install:
- [make](https://www.gnu.org/software/make) (ccstudio contains a builtin
`/opt/ccstudio/ccs/utils/bin/gmake`)

Optional dependencies:
For `cmake`:

- [check](https://github.com/libcheck/check): for unit test
- [bin2c](https://github.com/adobe/bin2c): for
`./configure --with-bin2c=/the/path/of/WxH.yuv`
- [cmake](https://github.com/Kitware/CMake)
- [one generator of cmake](https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html)

### Toolchains

To compile this program for native platform or other platforms, install:
### Host Builds

One of the following:

- [gcc](https://gcc.gnu.org)
- [clang](https://clang.llvm.org/)
- [MSVC](https://visualstudio.microsoft.com/vs/features/cplusplus)

### Cross Compiling

- [gcc](https://gcc.gnu.org)/[clang](https://clang.llvm.org/): for native
building
- [mingw-w64](https://archlinux.org/packages/community/x86_64/mingw-w64-gcc):
for windows
- [android-ndk](https://aur.archlinux.org/packages/android-ndk): for android
- [ccstudio](https://aur.archlinux.org/packages/ccstudio): for TI DSP
- [TI C6000 toolchain \< 8.0.0](https://www.ti.com/tool/C6000-CGT): for TI DSP
DM6467

For OSs:
For TI C6000 toolchain > 8.0.0, refer <https://github.com/Freed-Wu/x264>.

```shell
# native build
./configure
# or for windows
./configure --build=x86_64-pc-linux-gnu --host=x86_64-w64-mingw32
# or for android, API version is 32
./configure --build=x86_64-pc-linux-gnu --host=aarch64-linux-android32
make
```
### Optional Dependencies

For TI DSP DM6467: (Refer
[ccs_projects-command-line](https://software-dl.ti.com/ccs/esd/documents/ccs_projects-command-line.html))
- [check](https://github.com/libcheck/check): for unit test
- `make check`
- `ctest`
- [bin2c](https://github.com/adobe/bin2c): use bin2c to convert a yuv to
a c array
- `./configure --with-bin2c=/the/path/of/WxH.yuv`
- `cmake -DBIN2C=ON -DINPUT_FILENAME=/the/path/of/WxH.yuv`

<!-- markdownlint-disable MD013 -->
## Build

```shell
# a large heap/stack size to avoid malloc failure
ccstudio -noSplash -data ~/workspace_v12 -application com.ti.ccstudio.apps.projectCreate -ccs.device TMS320C64XX.TMS320DM6467 -ccs.name x264-dsp -ccs.setCompilerOptions --gcc -ccs.setCompilerOptions -O3 @configurations Release -ccs.setCompilerOptions --program_level_compile @configurations Release -ccs.setCompilerOptions --call_assumptions=3 @configurations Release -ccs.setLinkerOptions -heap=0x1000000 -ccs.setLinkerOptions -stack=0x1000000
cd ~/workspace_v12/x264-dsp
git clone --bare --depth=1 https://github.com/Freed-Wu/x264-dsp .git
git config core.bare false
git reset --hard
autoreconf -vif
./configure --with-bin2c=/the/path/of/1280x720.yuv
ccstudio -noSplash -data ~/workspace_v12 -application com.ti.ccstudio.apps.projectBuild -ccs.projects x264-dsp -ccs.configuration Release
```
### autotools

<!-- markdownlint-enable MD013 -->
For OSs:

For TI C6000 toolchain > 8.0.0, refer <https://github.com/Freed-Wu/x264>.
```shell
mkdir build
cd build
# host build
../configure
# or cross compiling for windows
../configure --build=x86_64-pc-linux-gnu --host=x86_64-w64-mingw32
# or cross compiling for android with API 21
../configure --build=x86_64-pc-linux-gnu --host=aarch64-linux-android21
make -j$(nproc)
```

## Configure
See `--help` to know how to configure:

```shell
$ ./configure --help
Expand Down Expand Up @@ -115,6 +112,43 @@ $ ./configure --help
...
```

`autotools` doesn't support TI-CGT. So for TI DSP DM6467, we need `ccstudio`:
(Refer [ccs_projects-command-line](https://software-dl.ti.com/ccs/esd/documents/ccs_projects-command-line.html))

<!-- markdownlint-disable MD013 -->

```shell
# a large heap/stack size to avoid malloc failure
ccstudio -noSplash -data ~/workspace_v12 -application com.ti.ccstudio.apps.projectCreate -ccs.device TMS320C64XX.TMS320DM6467 -ccs.name x264-dsp -ccs.setCompilerOptions --gcc -ccs.setCompilerOptions -O3 @configurations Release -ccs.setCompilerOptions --program_level_compile @configurations Release -ccs.setCompilerOptions --call_assumptions=3 @configurations Release -ccs.setLinkerOptions -heap=0x1000000 -ccs.setLinkerOptions -stack=0x1000000
cd ~/workspace_v12/x264-dsp
git clone --bare --depth=1 https://github.com/Freed-Wu/x264-dsp .git
git config core.bare false
git reset --hard
autoreconf -vif
./configure --with-bin2c=/the/path/of/1280x720.yuv
ccstudio -noSplash -data ~/workspace_v12 -application com.ti.ccstudio.apps.projectBuild -ccs.projects x264-dsp -ccs.configuration Release
```

<!-- markdownlint-enable MD013 -->

### cmake

```shell
# host build
cmake -Bbuild
# or cross compiling for windows
cmake -Bbuild -DCMAKE_TOOLCHAIN_FILE=cmake/mingw.cmake
# or cross compiling for windows on x86
cmake -Bbuild -DCMAKE_TOOLCHAIN_FILE=cmake/mingw.cmake -DCMAKE_SYSTEM_PROCESSOR=i686
# or cross compiling for android with highest API
cmake -Bbuild -DCMAKE_TOOLCHAIN_FILE=cmake/android-ndk.cmake
# or cross compiling for TI DSP
cmake -Bbuild -DCMAKE_TOOLCHAIN_FILE=cmake/ti.cmake
cmake --build build
```

See `ccmake -Bbuild` to know how to configure.

## Usage

Download a test YUV from
Expand All @@ -123,12 +157,10 @@ Note the file name must respect
[YUView filename rules](https://github.com/IENT/YUView/wiki/YUV-File-Names)
to contain resolution.

[Build](#build) a `x264`.

For OSs:

```shell
./x264 /the/path/yuv/1280x720.yuv
build/x264 /the/path/yuv/1280x720.yuv
```

After running, `out.264` will occur in current directory.
Expand Down
7 changes: 7 additions & 0 deletions cmake/android-ndk.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
set(CMAKE_SYSTEM_NAME Android)
if(NOT DEFINED CMAKE_ANDROID_ARCH_ABI)
set(CMAKE_ANDROID_ARCH_ABI arm64-v8a)
endif()
if(NOT DEFINED CMAKE_ANDROID_NDK)
set(CMAKE_ANDROID_NDK /opt/android-ndk)
endif()
7 changes: 7 additions & 0 deletions cmake/mingw.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
set(CMAKE_SYSTEM_NAME Windows)
if(NOT DEFINED CMAKE_SYSTEM_PROCESSOR)
set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_HOST_SYSTEM_PROCESSOR})
endif()
set(TOOLCHAIN_PREFIX ${CMAKE_SYSTEM_PROCESSOR}-w64-mingw32)
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
Loading

0 comments on commit e80efc9

Please sign in to comment.