Skip to content

Commit

Permalink
Project init
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaozhuai committed Jan 19, 2024
0 parents commit 3c24fd6
Show file tree
Hide file tree
Showing 56 changed files with 1,926 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
BasedOnStyle: 'Google'

AlignConsecutiveMacros:
Enabled: true
AcrossEmptyLines: true
AcrossComments: true
AlignCompound: false
PadOperators: false
AccessModifierOffset: -4
#AlignAfterOpenBracket: AlwaysBreak
AlignArrayOfStructures: Right
ColumnLimit: 120
QualifierAlignment: Left
FixNamespaceComments: true
IndentWidth: 4
JavaScriptQuotes: Single
NamespaceIndentation: None
ObjCBlockIndentWidth: 4
PointerAlignment: Right
SpaceBeforeRangeBasedForLoopColon: true
SpacesInContainerLiterals: false
InsertNewlineAtEOF: true
91 changes: 91 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: ci

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
code-style:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive
- name: Install clang-format-17
run: |
sudo apt-get remove clang-format*
sudo apt-get autoremove
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
echo "deb https://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main" | sudo tee -a /etc/apt/sources.list
echo "deb-src https://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main" | sudo tee -a /etc/apt/sources.list
sudo apt-get update
sudo apt-get install clang-format-17
sudo ln -s -f /usr/bin/clang-format-17 /usr/bin/clang-format
clang-format --version
- name: Check code style
run: |
cmake -B build .
cmake --build build -- check-format
linux:
needs: code-style
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive
- name: Build
run: |
cmake -B build .
cmake --build build -- all
cmake --build build -- check
macos:
needs: code-style
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive
- name: Build
run: |
cmake -B build .
cmake --build build -- all
cmake --build build -- check
windows-x64:
needs: code-style
runs-on: windows-2019
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive
- name: Build
shell: cmd
run: |
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
cmake -GNinja -B build .
cmake --build build -- all
cmake --build build -- check
windows-x86:
needs: code-style
runs-on: windows-2019
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive
- name: Build
shell: cmd
run: |
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars32.bat"
cmake -GNinja -B build .
cmake --build build -- all
cmake --build build -- check
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.idea
.DS_Store
cmake-build-*/
build/
83 changes: 83 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
cmake_minimum_required(VERSION 3.15)
project(imageinfo)

set(CMAKE_CXX_STANDARD 11)

set(IMAGEINFO_IS_MASTER_PROJECT OFF)
if (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
set(IMAGEINFO_IS_MASTER_PROJECT ON)
endif ()

option(IMAGEINFO_BUILD_TOOLS "Build tool" ${IMAGEINFO_IS_MASTER_PROJECT})
option(IMAGEINFO_BUILD_TESTS "Build tests" ${IMAGEINFO_IS_MASTER_PROJECT})
option(IMAGEINFO_BUILD_INSTALL "Build install" ${IMAGEINFO_IS_MASTER_PROJECT})

add_library(imageinfo INTERFACE)
add_library(imageinfo::imageinfo ALIAS imageinfo)

include(GNUInstallDirs)

target_include_directories(imageinfo INTERFACE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
)

if (IMAGEINFO_BUILD_TOOLS)
add_executable(imageinfo_cli cli/main.cpp)
target_link_libraries(imageinfo_cli PRIVATE imageinfo)
set_target_properties(imageinfo_cli PROPERTIES OUTPUT_NAME "imageinfo")
endif ()

if (IMAGEINFO_BUILD_TESTS)
enable_testing()

add_executable(imageinfo_tests tests/tests.cpp)
target_link_libraries(imageinfo_tests PRIVATE imageinfo)
target_compile_definitions(imageinfo_tests PRIVATE
-DIMAGES_DIR="${CMAKE_CURRENT_SOURCE_DIR}/images/"
)
add_test(NAME imageinfo_tests COMMAND imageinfo_tests)

if (CMAKE_CONFIGURATION_TYPES)
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}
--force-new-ctest-process --output-on-failure
--build-config "$<CONFIGURATION>")
else ()
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}
--force-new-ctest-process --output-on-failure)
endif ()
endif ()

if (IMAGEINFO_BUILD_INSTALL)
install(TARGETS imageinfo EXPORT imageinfo)
install(
FILES "${CMAKE_CURRENT_SOURCE_DIR}/include/imageinfo.hpp"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
install(
EXPORT imageinfo
FILE imageinfo-config.cmake
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/imageinfo"
NAMESPACE imageinfo::
)
if (IMAGEINFO_BUILD_TOOLS)
install(TARGETS imageinfo_cli)
endif ()
endif ()

if (IMAGEINFO_IS_MASTER_PROJECT)
find_program(CLANG_FORMAT clang-format)
if (CLANG_FORMAT)
set(ALL_SOURCES include/imageinfo.hpp cli/main.cpp tests/tests.cpp)
add_custom_target(
format
COMMAND "${CLANG_FORMAT}" -i -verbose ${ALL_SOURCES}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
)
add_custom_target(
check-format
COMMAND "${CLANG_FORMAT}" --dry-run --Werror ${ALL_SOURCES}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
)
endif ()
endif ()
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 xiaozhuai

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Loading

0 comments on commit 3c24fd6

Please sign in to comment.