Skip to content

Commit

Permalink
chore: Add cmake-format file to check code format of CMakeLists.txt (#…
Browse files Browse the repository at this point in the history
…836)

* add cmake-format

(cherry picked from commit 69d942f)

* check cmake-format

* fix
  • Loading branch information
karasusan authored Nov 1, 2022
1 parent 20a2721 commit 4ea6188
Show file tree
Hide file tree
Showing 20 changed files with 602 additions and 703 deletions.
9 changes: 9 additions & 0 deletions .yamato/upm-ci-webrtc-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,15 @@ codecoverage_{{ package.name }}_{{ platform.name }}_{{ editor.version }}:
{% endif %}
{% endfor %}

check_code_format_plugin:
name: Check code format for webrtc native plugin
agent:
type: Unity::VM
image: package-ci/ubuntu:v2.0.0-947481
flavor: b1.large
commands:
- BuildScripts~/format-plugin.sh

push_plugin:
name: Push to Github webrtc native plugin
agent:
Expand Down
14 changes: 14 additions & 0 deletions BuildScripts~/format-plugin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash -eu

export SOLUTION_DIR=$(pwd)/Plugin~

# Install cmake-lang
pip3 install cmakelang

pushd $SOLUTION_DIR

# Check format
find . -name CMakeLists.txt -not -path "*/glad/*" | \
xargs -I % cmake-format --check % -c .cmake-format

popd
146 changes: 146 additions & 0 deletions Plugin~/.cmake-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@

# --------------------------
# General Formatting Options
# --------------------------
# How wide to allow formatted cmake files
line_width = 80

# How many spaces to tab for indent
tab_size = 2

# If an argument group contains more than this many sub-groups (parg or kwarg
# groups), then force it to a vertical layout.
max_subgroups_hwrap = 2

# If a positional argument group contains more than this many arguments, then
# force it to a vertical layout.
max_pargs_hwrap = 6

# If true, separate flow control names from their parentheses with a space
separate_ctrl_name_with_space = False

# If true, separate function names from parentheses with a space
separate_fn_name_with_space = False

# If a statement is wrapped to more than one line, than dangle the closing
# parenthesis on it's own line.
dangle_parens = False

# If the trailing parenthesis must be 'dangled' on it's on line, then align it
# to this reference: `prefix`: the start of the statement, `prefix-indent`: the
# start of the statement, plus one indentation level, `child`: align to the
# column of the arguments
dangle_align = 'prefix'

min_prefix_chars = 4

# If the statement spelling length (including space and parenthesis) is larger
# than the tab width by more than this amount, then force reject un-nested
# layouts.
max_prefix_chars = 10

# If a candidate layout is wrapped horizontally but it exceeds this many lines,
# then reject the layout.
max_lines_hwrap = 2

# What style line endings to use in the output.
line_ending = 'unix'

# Format command names consistently as 'lower' or 'upper' case
command_case = 'canonical'

# Format keywords consistently as 'lower' or 'upper' case
keyword_case = 'unchanged'

# Specify structure for custom cmake functions
additional_commands = {
"foo": {
"flags": [
"BAR",
"BAZ"
],
"kwargs": {
"HEADERS": "*",
"SOURCES": "*",
"DEPENDS": "*"
}
}
}

# A list of command names which should always be wrapped
always_wrap = []

# If true, the argument lists which are known to be sortable will be sorted
# lexicographicall
enable_sort = True

# If true, the parsers may infer whether or not an argument list is sortable
# (without annotation).
autosort = False

# If a comment line starts with at least this many consecutive hash characters,
# then don't lstrip() them off. This allows for lazy hash rulers where the first
# hash char is not separated by space
hashruler_min_length = 10

# By default, if cmake-format cannot successfully fit everything into the
# desired linewidth it will apply the last, most agressive attempt that it made.
# If this flag is True, however, cmake-format will print error, exit with non-
# zero status code, and write-out nothing
require_valid_layout = False

# A dictionary containing any per-command configuration overrides. Currently
# only `command_case` is supported.
per_command = {}

# A dictionary mapping layout nodes to a list of wrap decisions. See the
# documentation for more information.
layout_passes = {}


# --------------------------
# Comment Formatting Options
# --------------------------
# What character to use for bulleted lists
bullet_char = '*'

# What character to use as punctuation after numerals in an enumerated list
enum_char = '.'

# enable comment markup parsing and reflow
enable_markup = True

# If comment markup is enabled, don't reflow the first comment block in each
# listfile. Use this to preserve formatting of your copyright/license
# statements.
first_comment_is_literal = False

# If comment markup is enabled, don't reflow any comment block which matches
# this (regex) pattern. Default is `None` (disabled).
literal_comment_pattern = None

# Regular expression to match preformat fences in comments
# default=r'^\s*([`~]{3}[`~]*)(.*)$'
fence_pattern = '^\\s*([`~]{3}[`~]*)(.*)$'

# Regular expression to match rulers in comments
# default=r'^\s*[^\w\s]{3}.*[^\w\s]{3}$'
ruler_pattern = '^\\s*[^\\w\\s]{3}.*[^\\w\\s]{3}$'

# If true, then insert a space between the first hash char and remaining hash
# chars in a hash ruler, and normalize it's length to fill the column
canonicalize_hashrulers = True


# ---------------------------------
# Miscellaneous Options
# ---------------------------------
# If true, emit the unicode byte-order mark (BOM) at the start of the file
emit_byteorder_mark = False

# Specify the encoding of the input file. Defaults to utf-8.
input_encoding = 'utf-8'

# Specify the encoding of the output file. Defaults to utf-8. Note that cmake
# only claims to support utf-8 so be careful when using anything else
output_encoding = 'utf-8'
45 changes: 25 additions & 20 deletions Plugin~/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
cmake_minimum_required(VERSION 3.18)

set(CMAKE_XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET "10.0" CACHE STRING "Minimum iOS deployment version")
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.12" CACHE STRING "Minimum OS X deployment version")

project(webrtc
set(CMAKE_XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET
"10.0"
CACHE STRING "Minimum iOS deployment version")
set(CMAKE_OSX_DEPLOYMENT_TARGET
"10.12"
CACHE STRING "Minimum OS X deployment version")

project(
webrtc
VERSION 2.4.0
LANGUAGES C CXX ASM
)
LANGUAGES C CXX ASM)

cmake_policy(SET CMP0076 NEW)

# Enable unit testing
enable_testing()

# Define flags to determine the build target platform
# Windows, Linux, macOS, iOS, Android
# Define flags to determine the build target platform Windows, Linux, macOS,
# iOS, Android
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(Windows TRUE)
endif()
Expand All @@ -36,17 +40,19 @@ set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if(XCODE)
if(${XCODE_VERSION} VERSION_GREATER_EQUAL 12.0.0 AND
${XCODE_VERSION} VERSION_LESS 11.0.0
)
message(FATAL_ERROR
"The required Xcode version is 11.0 or higher and 12.0 or higher is not supported.")
if(${XCODE_VERSION} VERSION_GREATER_EQUAL 12.0.0 AND ${XCODE_VERSION}
VERSION_LESS 11.0.0)
message(
FATAL_ERROR
"The required Xcode version is 11.0 or higher and 12.0 or higher is not supported."
)
endif()
endif()

if(Linux)
option(USE_CUSTOM_LIBCXX_STATIC "Use custom libc++" OFF)
option(CUSTOM_LIBCXX_DIR "Set filepath for custom libc++" "${CMAKE_SOURCE_DIR}")
option(CUSTOM_LIBCXX_DIR "Set filepath for custom libc++"
"${CMAKE_SOURCE_DIR}")

if(USE_CUSTOM_LIBCXX_STATIC)
add_compile_options(-nostdinc++)
Expand All @@ -57,20 +63,19 @@ if(Linux)
endif()
endif()

# enable debug output
# enable debug output
set(CMAKE_VERBOSE_MAKEFILE ON)

# set iterator debug level
if(Windows)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_ITERATOR_DEBUG_LEVEL=0 /Zi /Od")
set(CMAKE_CXX_FLAGS_DEBUG
"${CMAKE_CXX_FLAGS_DEBUG} -D_ITERATOR_DEBUG_LEVEL=0 /Zi /Od")
endif()

set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
find_package(Threads REQUIRED)

list(APPEND CMAKE_MODULE_PATH
"${CMAKE_SOURCE_DIR}/cmake"
)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")

find_package(WebRTC REQUIRED)

Expand All @@ -85,4 +90,4 @@ if(Windows OR Linux)
endif()

add_subdirectory(WebRTCPlugin)
add_subdirectory(WebRTCPluginTest)
add_subdirectory(WebRTCPluginTest)
57 changes: 18 additions & 39 deletions Plugin~/NvCodec/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,10 @@ set(NVENC_DIR ${NVCODEC_DIR}/NvCodec/NvEncoder)
set(NVDEC_DIR ${NVCODEC_DIR}/NvCodec/NvDecoder)

set(NVCODEC_INCLUDE_DIR
${NVCODEC_DIR}/include
${NVCODEC_DIR}/NvCodec
${NVCODEC_DIR}/Utils
CACHE PATH
"NVCODEC INCLUDE PATH"
)
${NVCODEC_DIR}/include ${NVCODEC_DIR}/NvCodec ${NVCODEC_DIR}/Utils
CACHE PATH "NVCODEC INCLUDE PATH")

file(GLOB sources
${NVCODEC_UTIL_DIR}/*
${NVENC_DIR}/*
${NVDEC_DIR}/*
)
file(GLOB sources ${NVCODEC_UTIL_DIR}/* ${NVENC_DIR}/* ${NVDEC_DIR}/*)

add_library(NvCodec STATIC ${sources})

Expand All @@ -24,13 +16,9 @@ if(Linux)
add_subdirectory(implib)
endif()

target_include_directories(NvCodec
PRIVATE
${CUDA_INCLUDE_DIRS}
${Vulkan_INCLUDE_DIR}
${GLEW_INCLUDE_DIRS}
${NVCODEC_INCLUDE_DIR}
)
target_include_directories(
NvCodec PRIVATE ${CUDA_INCLUDE_DIRS} ${Vulkan_INCLUDE_DIR}
${GLEW_INCLUDE_DIRS} ${NVCODEC_INCLUDE_DIR})

if(Windows)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
Expand All @@ -40,41 +28,32 @@ if(Windows)
set(CUVID_LIB ${CMAKE_CURRENT_SOURCE_DIR}/lib/Win32/nvcuvid.lib)
set(NVENCODEAPI_LIB ${CMAKE_CURRENT_SOURCE_DIR}/lib/Win32/nvencodeapi.lib)
endif()
else ()
else()
find_library(CUVID_LIB nvcuvid)
find_library(NVENCODEAPI_LIB nvidia-encode)
endif()

if(Windows)
# Select runtime library (MT, MTD) on windows platform
set_target_properties(NvCodec
PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>"
)
set_target_properties(
NvCodec PROPERTIES MSVC_RUNTIME_LIBRARY
"MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()

if(Linux)
# enable -fPIC option
set_target_properties(NvCodec
PROPERTIES
POSITION_INDEPENDENT_CODE ON
)
set_target_properties(NvCodec PROPERTIES POSITION_INDEPENDENT_CODE ON)
endif()

if(Windows)
# Use delayload linker option for nvEncodeAPI64.dll and nvcuvid.dll
set(NVCODEC_LIBRARIES
NvCodec
${CUVID_LIB}
${NVENCODEAPI_LIB}
CACHE PATH
"NVCODEC LIBRARIES PATH"
)
NvCodec ${CUVID_LIB} ${NVENCODEAPI_LIB}
CACHE PATH "NVCODEC LIBRARIES PATH")
elseif(Linux)
# Use implib.so for delayload on Linux
# If you don't use implib, need to link libnvcuvid.so and libnvidia-encode.so
# Use implib.so for delayload on Linux If you don't use implib, need to link
# libnvcuvid.so and libnvidia-encode.so
set(NVCODEC_LIBRARIES
NvCodec
CACHE PATH
"NVCODEC LIBRARIES PATH"
)
endif()
NvCodec
CACHE PATH "NVCODEC LIBRARIES PATH")
endif()
14 changes: 5 additions & 9 deletions Plugin~/NvCodec/implib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
target_sources(NvCodec
PRIVATE
libcuda.so.init.c
libcuda.so.tramp.S
libnvcuvid.so.init.c
libnvcuvid.so.tramp.S
libnvidia-encode.so.init.c
libnvidia-encode.so.tramp.S
)
target_sources(
NvCodec
PRIVATE libcuda.so.init.c libcuda.so.tramp.S libnvcuvid.so.init.c
libnvcuvid.so.tramp.S libnvidia-encode.so.init.c
libnvidia-encode.so.tramp.S)
9 changes: 2 additions & 7 deletions Plugin~/WebRTCPlugin/Android/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
target_sources(WebRTCLib
PRIVATE
AndroidCodecFactoryHelper.cpp
AndroidCodecFactoryHelper.h
Jni.cpp
Jni.h
)
target_sources(WebRTCLib PRIVATE AndroidCodecFactoryHelper.cpp
AndroidCodecFactoryHelper.h Jni.cpp Jni.h)
Loading

0 comments on commit 4ea6188

Please sign in to comment.