Compare commits

...

42 Commits

Author SHA1 Message Date
tastytea 9070f154a4
Version bump 0.7.3.
continuous-integration/drone/push Build is passing Details
2020-10-24 11:30:43 +02:00
tastytea b172c3cb3c
Generate package for Debian buster.
continuous-integration/drone/push Build was killed Details
2020-10-24 11:29:50 +02:00
tastytea e73a7625a6
Disable automatic RPM generation. 2020-10-24 10:26:12 +02:00
tastytea d283e1ebc9
Version bump 0.7.2. 2020-10-24 10:22:05 +02:00
tastytea 23f8f69e0e
Fix Debian package generation.
continuous-integration/drone/push Build was killed Details
2020-10-24 10:14:45 +02:00
tastytea 941f272f60
Remove copyright from readme. 2020-10-24 09:59:21 +02:00
tastytea 051cc273b7
Put name of distribution and version in generated packages.
continuous-integration/drone/push Build is passing Details
2020-10-24 09:54:01 +02:00
tastytea 9ed41d6ac8
Clarify that the binary packages are for Debian and CentOS. 2020-10-24 09:49:20 +02:00
tastytea 319a432309
Update editorconfig.
continuous-integration/drone/push Build is passing Details
2020-10-24 09:44:56 +02:00
tastytea 4d9dc6d8a7
Merge branch 'develop'
continuous-integration/drone/push Build is passing Details
2019-09-27 07:38:11 +02:00
tastytea 6e5eb38ed6
Fixed RPM dependencies.
continuous-integration/drone/push Build is passing Details
2019-09-27 07:26:32 +02:00
tastytea 27f95a25b2
Replaced README.md with README.adoc. 2019-09-27 07:26:26 +02:00
tastytea d4e325d75f
Make more use of variables in contribution guidelines.
continuous-integration/drone/push Build is passing Details
2019-09-27 04:09:08 +02:00
tastytea 81a4e335bb
Fix coc contact. 2019-09-27 04:08:20 +02:00
tastytea 341a0844f6
Add email to contributing guidelines, link to them in readme.
continuous-integration/drone/push Build is passing Details
2019-09-23 19:22:04 +02:00
tastytea f125f5e5d6
Merge branch 'develop' 2019-09-23 19:16:10 +02:00
tastytea c97d0f6307
Add COC, contributing guidelines and EditorConfig.
continuous-integration/drone/push Build is passing Details
2019-09-23 19:14:17 +02:00
tastytea 607e238698
Version bump 0.7.1.
continuous-integration/drone/push Build is passing Details
2019-09-23 19:02:33 +02:00
tastytea 7f99945719
Merge branch 'develop' 2019-09-23 19:02:13 +02:00
tastytea f7b2c22c23
Install header.
continuous-integration/drone/push Build was killed Details
2019-09-23 19:00:52 +02:00
tastytea 62542e4230
CI: Rename step clang6 → clang7.
continuous-integration/drone/push Build is passing Details
2019-09-13 19:15:10 +02:00
tastytea 1724c6d944
Version bump 0.7.0.
continuous-integration/drone/push Build is passing Details
2019-09-13 19:10:22 +02:00
tastytea acfc65c442
Merge branch 'develop'
* Modernize CMake recipes.
* Move files around.
* Install identiconppConfig.cmake.
2019-09-13 19:08:06 +02:00
tastytea b1e25041d9
Added include dir for BUILD_INTERFACE.
continuous-integration/drone/push Build is passing Details
2019-09-13 18:57:48 +02:00
tastytea 8af793ac6a
CI: Test with clang-7 on buster.
continuous-integration/drone/push Build is failing Details
2019-09-13 18:54:06 +02:00
tastytea 752ebfface
Add include dir to library. 2019-09-13 18:53:05 +02:00
tastytea 2d1bac9c3f
Moved identiconpp.hpp to include/. 2019-09-13 18:48:47 +02:00
tastytea d6c640698c
Modernized CMake recipes and moved files around. 2019-09-13 18:45:30 +02:00
tastytea 7e1dad0cf7
Add 2019 to copyright notice.
continuous-integration/drone/push Build is failing Details
2019-09-13 17:26:30 +02:00
tastytea 2477483517
Fix description in pkg-config recipe. 2019-09-13 17:19:32 +02:00
tastytea 74f55707f8
Remove unnecessary includes in CMake recipe.
continuous-integration/drone/push Build is failing Details
2019-09-13 16:59:15 +02:00
tastytea 4afee87285
Remove C support.
I'm not willing to invest the time to make it good.
2019-09-13 16:45:40 +02:00
tastytea 34eedfe6d1
Fix rpm package generation.
continuous-integration/drone/push Build is passing Details
* Set CXX for CentOS in CI correctly.
* Install the right ImageMagick.
* Fix gpg call.
* Fixed signature path.
2019-07-30 14:50:37 +02:00
tastytea 904313abd9
Version bump 0.6.1.
continuous-integration/drone/push Build is passing Details
2019-07-30 13:51:58 +02:00
tastytea 6f92a3625f
Updated readme.
continuous-integration/drone/push Build is passing Details
2019-07-30 13:41:16 +02:00
tastytea eb493d5c00
Whitesapace cleanup.
continuous-integration/drone/push Build is passing Details
2019-07-30 13:07:45 +02:00
tastytea 1f23390623
Added pkg-config file. 2019-07-30 13:04:08 +02:00
tastytea e5e4524947
Fixed header locations in cmake recipe.
continuous-integration/drone/push Build is passing Details
2019-07-30 12:27:17 +02:00
tastytea 04ccca4658
Updated drone config. 2019-07-30 12:26:35 +02:00
tastytea f6c82a321c
Simplyfied doxygen config. 2019-07-30 11:33:35 +02:00
tastytea 0ca6906cb5
Updated and modularized cmake recipes. 2019-07-30 11:32:57 +02:00
tastytea e6b5de0118
Moved tests. 2019-07-30 11:32:34 +02:00
34 changed files with 700 additions and 1058 deletions

View File

@ -1,199 +1,211 @@
pipeline:
gcc5:
image: debian:stretch-slim
pull: true
when:
event: [push, pull_request]
environment:
- LANG=C.utf8
- CXX=g++-5
- CXXFLAGS=-pipe -O2
commands:
- rm /etc/apt/apt.conf.d/docker-clean
- apt-get update -q
- echo "APT::Default-Release \"stretch\";" >> /etc/apt/apt.conf.d/00default_release
- echo "deb http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu xenial main" >> /etc/apt/sources.list.d/ubuntu-toolchain-r.list
- apt-get install -qy gnupg
- gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys 0x60c317803a41ba51845e371a1e9377a2ba9ef27f
- gpg --armor --export 0x60c317803a41ba51845e371a1e9377a2ba9ef27f | apt-key add -
- apt-get update -q
- apt-get install -qy -t xenial g++-5
- apt-get install -qy cmake pkg-config
- apt-get install -qy libmagick++-dev
- rm -rf build && mkdir -p build && cd build
- cmake -DCMAKE_INSTALL_PREFIX=/usr ..
- make VERBOSE=1
volumes:
- /var/cache/debian-package-cache:/var/cache/apt/archives
# -*- fill-column: 1000 -*-
kind: pipeline
name: build x86_64
gcc6:
image: debian:stretch-slim
pull: true
environment:
- LANG=C.utf8
- CXX=g++-6
- CXXFLAGS=-pipe -O2
commands:
- rm /etc/apt/apt.conf.d/docker-clean
- apt-get update -q
- apt-get install -qy g++-6 cmake pkg-config
- apt-get install -qy libmagick++-dev catch
- apt-get install -qy dpkg-dev d-shlibs rpm file wget
- gpg --no-tty --import /var/autosign_gpg.key
- rm -rf build && mkdir -p build && cd build
- cmake -DCMAKE_INSTALL_PREFIX=/usr -DWITH_TESTS=1 ..
- make VERBOSE=1
- ctest ..
- make install DESTDIR=install
- make package
- cmake -DWITH_DEB=ON ..
- make package
- cmake -DWITH_DEB=OFF -DWITH_RPM=ON ..
- make package
- gpg --verbose --detach-sign *.tar.gz
- gpg --verbose --detach-sign *.deb
- gpg --verbose --detach-sign *.rpm
volumes:
- /var/cache/debian-package-cache:/var/cache/apt/archives
- /home/tastytea/misc/autosign_gpg.key:/var/autosign_gpg.key
volumes:
- name: debian-package-cache
host:
path: /var/cache/debian-package-cache
gcc7:
image: debian:stretch-slim
pull: true
when:
event: [push, pull_request]
environment:
- LANG=C.utf8
- CXX=g++-7
- CXXFLAGS=-pipe -O2
commands:
- rm /etc/apt/apt.conf.d/docker-clean
- apt-get update -q
- echo "APT::Default-Release \"stretch\";" >> /etc/apt/apt.conf.d/00default_release
- echo "deb http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu xenial main" >> /etc/apt/sources.list.d/ubuntu-toolchain-r.list
- apt-get install -qy gnupg
- gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys 0x60c317803a41ba51845e371a1e9377a2ba9ef27f
- gpg --armor --export 0x60c317803a41ba51845e371a1e9377a2ba9ef27f | apt-key add -
- apt-get update -q
- apt-get install -qy -t xenial g++-7
- apt-get install -qy cmake pkg-config
- apt-get install -qy libmagick++-dev
- rm -rf build && mkdir -p build && cd build
- cmake -DCMAKE_INSTALL_PREFIX=/usr ..
- make VERBOSE=1
volumes:
- /var/cache/debian-package-cache:/var/cache/apt/archives
trigger:
event:
exclude:
- tag
gcc8:
image: debian:stretch-slim
pull: true
when:
event: [push, pull_request]
environment:
- LANG=C.utf8
- CXX=g++-8
- CXXFLAGS=-pipe -O2
commands:
- rm /etc/apt/apt.conf.d/docker-clean
- apt-get update -q
- echo "APT::Default-Release \"stretch\";" >> /etc/apt/apt.conf.d/00default_release
- echo "deb http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu xenial main" >> /etc/apt/sources.list.d/ubuntu-toolchain-r.list
- apt-get install -qy gnupg
- gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys 0x60c317803a41ba51845e371a1e9377a2ba9ef27f
- gpg --armor --export 0x60c317803a41ba51845e371a1e9377a2ba9ef27f | apt-key add -
- apt-get update -q
- apt-get install -qy -t xenial g++-8
- apt-get install -qy cmake pkg-config
- apt-get install -qy libmagick++-dev
- rm -rf build && mkdir -p build && cd build
- cmake -DCMAKE_INSTALL_PREFIX=/usr ..
- make VERBOSE=1
volumes:
- /var/cache/debian-package-cache:/var/cache/apt/archives
steps:
- name: gcc6
image: debian:stretch-slim
pull: always
environment:
CXX: g++-6
CXXFLAGS: -pipe -O2
LANG: en_US.utf-8
commands:
- rm /etc/apt/apt.conf.d/docker-clean
- alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get'
- apt-get update -q
- apt-get install -qy g++-6 cmake pkg-config libmagick++-dev catch
- rm -rf build && mkdir -p build && cd build
- cmake -DWITH_TESTS=YES ..
- cmake --build .
- make install DESTDIR=install
- cd tests && ctest -V
volumes:
- name: debian-package-cache
path: /var/cache/apt/archives
clang5:
image: debian:stretch-slim
pull: true
when:
event: [push, pull_request]
environment:
- LANG=C.utf8
- CXX=clang++-5.0
- CXXFLAGS=-pipe -O2
commands:
- rm /etc/apt/apt.conf.d/docker-clean
- echo "APT::Default-Release \"stretch\";" >> /etc/apt/apt.conf.d/00default_release
- echo "deb http://deb.debian.org/debian stretch-backports main" >> /etc/apt/sources.list.d/stretch.list
- apt-get update -q
- apt-get install -qy -t stretch-backports clang-5.0
- apt-get install -qy cmake pkg-config
- apt-get install -qy libmagick++-dev
- rm -rf build && mkdir -p build && cd build
- cmake -DCMAKE_INSTALL_PREFIX=/usr ..
- make VERBOSE=1
volumes:
- /var/cache/debian-package-cache:/var/cache/apt/archives
- name: gcc9
image: debian:stretch-slim
pull: always
environment:
CXX: g++-9
CXXFLAGS: -pipe -O2
LANG: en_US.utf-8
commands:
- rm /etc/apt/apt.conf.d/docker-clean
- alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get'
- apt-get update -q
- echo "APT::Default-Release \"stretch\";" >> /etc/apt/apt.conf.d/00default_release
- echo "deb http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu xenial main" >> /etc/apt/sources.list.d/ubuntu-toolchain-r.list
- apt-get install -qy gnupg
- gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys 0x60c317803a41ba51845e371a1e9377a2ba9ef27f
- gpg --armor --export 0x60c317803a41ba51845e371a1e9377a2ba9ef27f | apt-key add -
- apt-get update -q
- apt-get install -qy -t xenial g++-9
- apt-get install -qy cmake pkg-config libmagick++-dev
- rm -rf build && mkdir -p build && cd build
- cmake ..
- cmake --build .
volumes:
- name: debian-package-cache
path: /var/cache/apt/archives
clang6:
image: debian:stretch-slim
pull: true
when:
event: [push, pull_request]
environment:
- LANG=C.utf8
- CXX=clang++-6.0
- CXXFLAGS=-pipe -O2
commands:
- rm /etc/apt/apt.conf.d/docker-clean
- echo "APT::Default-Release \"stretch\";" >> /etc/apt/apt.conf.d/00default_release
- echo "deb http://deb.debian.org/debian stretch-backports main" >> /etc/apt/sources.list.d/stretch.list
- apt-get update -q
- apt-get install -qy -t stretch-backports clang-6.0
- apt-get install -qy cmake pkg-config
- apt-get install -qy libmagick++-dev
- rm -rf build && mkdir -p build && cd build
- cmake -DCMAKE_INSTALL_PREFIX=/usr ..
- make VERBOSE=1
volumes:
- /var/cache/debian-package-cache:/var/cache/apt/archives
- name: clang7
image: debian:buster-slim
pull: always
environment:
CXX: clang++
CXXFLAGS: -pipe -O2
LANG: en_US.utf-8
commands:
- rm /etc/apt/apt.conf.d/docker-clean
- alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get'
- apt-get update -q
- apt-get install -qy clang cmake pkg-config libmagick++-dev
- rm -rf build && mkdir -p build && cd build
- cmake ..
- cmake --build .
volumes:
- name: debian-package-cache
path: /var/cache/apt/archives
prepare_release:
image: debian:stretch-slim
pull: true
when:
event: tag
commands:
- cp -v build/identiconpp-${DRONE_TAG}_x86_64.tar.gz .
- cp -v build/identiconpp-${DRONE_TAG}_x86_64.tar.gz.sig .
- cp -v build/identiconpp_${DRONE_TAG}-0_amd64.deb .
- cp -v build/identiconpp_${DRONE_TAG}-0_amd64.deb.sig .
- cp -v build/identiconpp-${DRONE_TAG}-0.x86_64.rpm .
- cp -v build/identiconpp-${DRONE_TAG}-0.x86_64.rpm.sig .
---
kind: pipeline
name: packages x86_64
gitea_release:
image: plugins/gitea-release
pull: true
when:
event: tag
volumes:
- name: debian-package-cache
host:
path: /var/cache/debian-package-cache
- name: centos-package-cache
host:
path: /var/cache/centos-package-cache
- name: gpg-key
host:
path: /home/tastytea/misc/autosign_gpg.key
trigger:
event:
- tag
steps:
- name: Debian stretch
image: debian:stretch-slim
pull: always
environment:
CXX: g++-6
CXXFLAGS: -pipe -O2
LANG: en_US.utf-8
commands:
- rm /etc/apt/apt.conf.d/docker-clean
- alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get'
- apt-get update -q
- apt-get install -qy g++-6 cmake pkg-config libmagick++-dev gnupg dpkg-dev d-shlibs lsb-release
- rm -rf build && mkdir -p build && cd build
- cmake -DWITH_DEB=YES ..
- make package
- gpg --import /var/autosign_gpg.key
- gpg --verbose --detach-sign *.deb
- cp -v identiconpp_${DRONE_TAG}-0_amd64_stretch.deb ..
- cp -v identiconpp_${DRONE_TAG}-0_amd64_stretch.deb.sig ..
volumes:
- name: debian-package-cache
path: /var/cache/apt/archives
- name: gpg-key
path: /var/autosign_gpg.key
- name: Debian buster
image: debian:buster-slim
pull: always
environment:
CXX: g++-8
CXXFLAGS: -pipe -O2
LANG: en_US.utf-8
commands:
- rm /etc/apt/apt.conf.d/docker-clean
- alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get'
- apt-get update -q
- apt-get install -qy build-essential cmake pkg-config libmagick++-dev gnupg dpkg-dev d-shlibs lsb-release
- rm -rf build && mkdir -p build && cd build
- cmake -DWITH_DEB=YES ..
- make package
- gpg --import /var/autosign_gpg.key
- gpg --verbose --detach-sign *.deb
- cp -v identiconpp_${DRONE_TAG}-0_amd64_buster.deb ..
- cp -v identiconpp_${DRONE_TAG}-0_amd64_buster.deb.sig ..
volumes:
- name: debian-package-cache
path: /var/cache/apt/archives
- name: gpg-key
path: /var/autosign_gpg.key
# - name: CentOS 7
# image: centos:7
# pull: always
# environment:
# CXX: /opt/rh/devtoolset-6/root/usr/bin/g++
# CXXFLAGS: -pipe -O2
# LANG: en_US.utf-8
# commands:
# - sed -i 's/keepcache=0/keepcache=1/' /etc/yum.conf
# - curl -s -o /var/cache/yum/epel-release-latest-7.noarch.rpm http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# - rpm -i /var/cache/yum/epel-release-latest-7.noarch.rpm
# - yum install -qy centos-release-scl
# - yum install -qy devtoolset-6
# - scl enable devtoolset-6 bash
# - yum install -qy rpm-build ImageMagick-c++-devel gnupg redhat-lsb-core
# - yum --enablerepo=epel install -qy cmake3
# - rm -rf build && mkdir -p build && cd build
# - cmake3 -DWITH_RPM=YES ..
# - make package
# - gpg --import /var/autosign_gpg.key
# - gpg --verbose --detach-sign *.rpm
# - cp -v identiconpp-${DRONE_TAG}-0.x86_64.centos7.rpm ..
# - cp -v identiconpp-${DRONE_TAG}-0.x86_64.centos7.rpm.sig ..
# volumes:
# - name: centos-package-cache
# path: /var/cache/yum
# - name: gpg-key
# path: /var/autosign_gpg.key
- name: release
image: plugins/gitea-release
pull: always
settings:
base_url: https://schlomp.space
secrets: [ gitea_token ]
api_key:
from_secret: gitea_token
title: ${DRONE_TAG}
prerelease: true
files:
- identiconpp-${DRONE_TAG}_x86_64.tar.gz
- identiconpp-${DRONE_TAG}_x86_64.tar.gz.sig
- identiconpp_${DRONE_TAG}-0_amd64.deb
- identiconpp_${DRONE_TAG}-0_amd64.deb.sig
- identiconpp-${DRONE_TAG}-0.x86_64.rpm
- identiconpp-${DRONE_TAG}-0.x86_64.rpm.sig
- identiconpp_${DRONE_TAG}-0_amd64_stretch.deb
- identiconpp_${DRONE_TAG}-0_amd64_stretch.deb.sig
- identiconpp_${DRONE_TAG}-0_amd64_buster.deb
- identiconpp_${DRONE_TAG}-0_amd64_buster.deb.sig
# - identiconpp-${DRONE_TAG}-0.x86_64.centos7.rpm
# - identiconpp-${DRONE_TAG}-0.x86_64.centos7.rpm.sig
checksum:
- sha512
notify:
image: drillster/drone-email
pull: true
- name: notify
image: drillster/drone-email
pull: always
settings:
host: cryptoparty-celle.de
secrets: [ email_username, email_password ]
from: drone@tzend.de
when:
status: [ changed, failure ]
username:
from_secret: email_username
password:
from_secret: email_password
when:
status: [ changed, failure ]

20
.editorconfig Normal file
View File

@ -0,0 +1,20 @@
# Configuration file for EditorConfig.
# More information is available under <https://editorconfig.org/>.
root = true
[*]
indent_style = space
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 80
[*.?pp]
indent_size = 4
tab_width = 4
[{CMakeLists.txt,*.cmake}]
indent_size = 2
tab_width = 2

View File

@ -1,45 +1,57 @@
cmake_minimum_required (VERSION 3.2)
project(identiconpp
VERSION 0.6.0
LANGUAGES CXX
)
# Support version 3.6 and above, but use policy settings up to 3.14.
# 3.6 is needed because of IMPORTED_TARGET in pkg_check_modules().
cmake_minimum_required(VERSION 3.6...3.14)
# Ranges are supported from 3.12, set policy to current for < 3.12.
if(${CMAKE_VERSION} VERSION_LESS 3.12)
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
endif()
include(GNUInstallDirs)
find_package(PkgConfig REQUIRED)
pkg_check_modules(MAGICPP REQUIRED Magick++)
project(identiconpp
VERSION 0.7.3
LANGUAGES CXX)
# DESCRIPTION was introduced in version 3.9.
if(NOT (${CMAKE_VERSION} VERSION_LESS 3.9))
set(PROJECT_DESCRIPTION
"Library to generate identicons for C++.")
endif()
option(WITH_TESTS "Enable Tests" NO)
option(BUILD_SHARED_LIBS "Build shared libraries." YES)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
string(REPLACE ";" " " MAGICPP_CFLAGS_STRING "${MAGICPP_CFLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MAGICPP_CFLAGS_STRING}")
set(CMAKE_CXX_FLAGS_DEBUG
"${CMAKE_CXX_FLAGS_DEBUG} -Wall -pedantic -Wextra -g -Og -fno-omit-frame-pointer")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_definitions(-DDEBUG=1)
set(DEBUG_CXXFLAGS
"-Wall"
"-Wextra"
"-Wpedantic"
"-ftrapv"
"-fsanitize=undefined"
"-g"
"-Og"
"-fno-omit-frame-pointer")
set(DEBUG_LDFLAGS
"-fsanitize=undefined")
add_compile_options("$<$<CONFIG:Debug>:${DEBUG_CXXFLAGS}>")
# add_link_options was introduced in version 3.13.
if(${CMAKE_VERSION} VERSION_LESS 3.13)
set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${DEBUG_LDFLAGS}")
else()
add_link_options("$<$<CONFIG:Debug>:${DEBUG_LDFLAGS}>")
endif()
include_directories(${PROJECT_SOURCE_DIR}/src)
include_directories(${PROJECT_BINARY_DIR})
include_directories(${MAGICPP_INCLUDE_DIRS})
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_definitions(-DDEBUG=1)
endif()
link_directories(${MAGICPP_LIBRARY_DIRS})
add_subdirectory(src)
add_subdirectory(include)
add_subdirectory(cmake)
add_subdirectory(pkg-config)
file(GLOB sources src/*.cpp)
add_library(${CMAKE_PROJECT_NAME} SHARED "${sources}")
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${${CMAKE_PROJECT_NAME}_VERSION_MAJOR})
target_link_libraries(${CMAKE_PROJECT_NAME} "${MAGICPP_LDFLAGS}")
add_executable(example "example.cpp")
target_link_libraries(example ${CMAKE_PROJECT_NAME})
install(TARGETS ${CMAKE_PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(FILES src/${CMAKE_PROJECT_NAME}.hpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(FILES src/${CMAKE_PROJECT_NAME}_c.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(FILES README.md DESTINATION ${CMAKE_INSTALL_DOCDIR})
if(WITH_TESTS)
add_subdirectory(tests)
endif()
include(packages.CMakeLists.txt)
include(tests.CMakeLists.txt)

49
CODE_OF_CONDUCT.adoc Normal file
View File

@ -0,0 +1,49 @@
:contact-coc: tastytea@tastytea.de
== Code of Conduct
In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, education, ethnicity, gender identity and expression, level of
experience, nationality, personal appearance, race, religion, sex
characteristics, sexual identity and orientation or socio-economic status.
=== Examples
Examples of behavior that contributes to creating a positive environment
include:
* Using welcoming and inclusive language.
* Being respectful of differing viewpoints and experiences.
* Gracefully accepting constructive criticism.
* Focusing on what is best for the community.
* Showing empathy towards other community members.
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or
advances.
* Trolling, insulting/derogatory comments, and personal attacks.
* Public or private harassment.
* Publishing others private information, such as a physical or electronic
address, without explicit permission.
=== Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at {contact-coc}.
All complaints will be reviewed and investigated and will result in a response
that is deemed necessary and appropriate to the circumstances. The project team
is obligated to maintain confidentiality with regard to the reporter of an
incident.
=== Attribution
This Code of Conduct is adapted from the Contributor Covenant, version 1.4,
available at
https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq

29
CONTRIBUTING.adoc Normal file
View File

@ -0,0 +1,29 @@
:project: identiconpp
:uri-base: https://schlomp.space/tastytea/{project}
:uri-coc: {uri-base}/src/branch/master/CODE_OF_CONDUCT.adoc
:contact-email: tastytea@tastytea.de
:contact-xmpp: {contact-email}
:contact-fediverse: https://likeable.space/users/tastytea
== How to contribute
Read the link:{uri-coc}[Code of Conduct].
=== Reporting bugs or suggesting enhancements
Before reporting a bug, please
https://schlomp.space/tastytea/{project}/issues[perform a search] to see if the
problem has already been reported. If it has, add a comment to the existing
issue instead of opening a new one. Same for enhancements.
You can also contact me via mailto:{contact-email}[E-Mail],
link:xmpp:{contact-xmpp}[XMPP] or the {contact-fediverse}[Fediverse] if you
don't want to open an account.
=== Pull requests
Please use similar coding conventions as the rest of the project. The basic rule
to remember is to write code in the same style as the existing/surrounding code.
You can also send me your patches via mailto:{contact-email}[E-Mail], ideally
using `git format-patch` or `git send-email`.

192
Doxyfile
View File

@ -1,198 +1,28 @@
DOXYFILE_ENCODING = UTF-8
# -*- mode: conf-unix -*-
PROJECT_NAME = "identiconpp"
PROJECT_NUMBER = 0.0.0
INPUT = README.md src/
USE_MDFILE_AS_MAINPAGE = README.md
CREATE_SUBDIRS = NO
EXAMPLE_PATH = ./
EXAMPLE_RECURSIVE = YES
GENERATE_HTML = YES
HTML_OUTPUT = doc/html
GENERATE_LATEX = NO
ALLOW_UNICODE_NAMES = YES
OUTPUT_LANGUAGE = English
BRIEF_MEMBER_DESC = YES
REPEAT_BRIEF = YES
ALWAYS_DETAILED_SEC = NO
ALWAYS_DETAILED_SEC = YES
INLINE_INHERITED_MEMB = NO
FULL_PATH_NAMES = YES
SHORT_NAMES = NO
JAVADOC_AUTOBRIEF = NO
QT_AUTOBRIEF = NO
MULTILINE_CPP_IS_BRIEF = NO
INHERIT_DOCS = YES
SEPARATE_MEMBER_PAGES = NO
TAB_SIZE = 4
OPTIMIZE_OUTPUT_FOR_C = NO
OPTIMIZE_OUTPUT_JAVA = NO
OPTIMIZE_FOR_FORTRAN = NO
OPTIMIZE_OUTPUT_VHDL = NO
MARKDOWN_SUPPORT = YES
AUTOLINK_SUPPORT = YES
BUILTIN_STL_SUPPORT = NO
CPP_CLI_SUPPORT = NO
SIP_SUPPORT = NO
IDL_PROPERTY_SUPPORT = YES
DISTRIBUTE_GROUP_DOC = NO
GROUP_NESTED_COMPOUNDS = NO
SUBGROUPING = YES
INLINE_GROUPED_CLASSES = NO
INLINE_SIMPLE_STRUCTS = NO
TYPEDEF_HIDES_STRUCT = NO
LOOKUP_CACHE_SIZE = 0
EXTRACT_ALL = NO
EXTRACT_PRIVATE = NO
EXTRACT_PACKAGE = NO
EXTRACT_STATIC = NO
EXTRACT_LOCAL_CLASSES = YES
EXTRACT_LOCAL_METHODS = NO
EXTRACT_ANON_NSPACES = NO
HIDE_UNDOC_MEMBERS = NO
HIDE_UNDOC_CLASSES = NO
HIDE_FRIEND_COMPOUNDS = NO
HIDE_IN_BODY_DOCS = NO
INTERNAL_DOCS = NO
CASE_SENSE_NAMES = YES
HIDE_SCOPE_NAMES = NO
HIDE_COMPOUND_REFERENCE= NO
SHOW_INCLUDE_FILES = YES
SHOW_GROUPED_MEMB_INC = NO
FORCE_LOCAL_INCLUDES = NO
INLINE_INFO = YES
SORT_MEMBER_DOCS = YES
SORT_BRIEF_DOCS = NO
SORT_MEMBERS_CTORS_1ST = NO
SORT_GROUP_NAMES = NO
SORT_BY_SCOPE_NAME = NO
STRICT_PROTO_MATCHING = NO
GENERATE_TODOLIST = YES
GENERATE_TESTLIST = YES
GENERATE_BUGLIST = YES
GENERATE_DEPRECATEDLIST= YES
MAX_INITIALIZER_LINES = 30
SHOW_USED_FILES = YES
SHOW_FILES = YES
SHOW_NAMESPACES = YES
QUIET = NO
WARNINGS = YES
WARN_IF_UNDOCUMENTED = YES
WARN_IF_DOC_ERROR = YES
WARN_NO_PARAMDOC = NO
WARN_FORMAT = "$file:$line: $text"
INPUT_ENCODING = UTF-8
RECURSIVE = NO
EXCLUDE_SYMLINKS = NO
EXAMPLE_PATH = ./
EXAMPLE_RECURSIVE = YES
FILTER_SOURCE_FILES = NO
SOURCE_BROWSER = NO
INLINE_SOURCES = YES
STRIP_CODE_COMMENTS = YES
REFERENCED_BY_RELATION = NO
REFERENCES_RELATION = NO
REFERENCES_LINK_SOURCE = YES
SOURCE_TOOLTIPS = YES
USE_HTAGS = NO
BUILTIN_STL_SUPPORT = YES
VERBATIM_HEADERS = YES
CLANG_ASSISTED_PARSING = NO
ALPHABETICAL_INDEX = YES
COLS_IN_ALPHA_INDEX = 5
GENERATE_HTML = YES
HTML_OUTPUT = doc/html
HTML_FILE_EXTENSION = .html
HTML_COLORSTYLE_HUE = 220
HTML_COLORSTYLE_SAT = 100
HTML_COLORSTYLE_GAMMA = 80
HTML_TIMESTAMP = NO
HTML_DYNAMIC_SECTIONS = NO
HTML_INDEX_NUM_ENTRIES = 100
GENERATE_DOCSET = NO
DOCSET_FEEDNAME = "Doxygen generated docs"
DOCSET_BUNDLE_ID = org.doxygen.Project
DOCSET_PUBLISHER_ID = org.doxygen.Publisher
DOCSET_PUBLISHER_NAME = Publisher
GENERATE_HTMLHELP = NO
GENERATE_CHI = NO
BINARY_TOC = NO
TOC_EXPAND = NO
GENERATE_QHP = NO
QHP_NAMESPACE = org.doxygen.Project
QHP_VIRTUAL_FOLDER = doc
GENERATE_ECLIPSEHELP = NO
ECLIPSE_DOC_ID = org.doxygen.Project
DISABLE_INDEX = NO
GENERATE_TREEVIEW = NO
ENUM_VALUES_PER_LINE = 4
TREEVIEW_WIDTH = 250
EXT_LINKS_IN_WINDOW = NO
FORMULA_FONTSIZE = 10
FORMULA_TRANSPARENT = YES
USE_MATHJAX = NO
MATHJAX_FORMAT = HTML-CSS
MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest
SEARCHENGINE = NO
SERVER_BASED_SEARCH = NO
EXTERNAL_SEARCH = NO
SEARCHDATA_FILE = searchdata.xml
GENERATE_LATEX = NO
LATEX_OUTPUT = latex
LATEX_CMD_NAME = latex
MAKEINDEX_CMD_NAME = makeindex
COMPACT_LATEX = NO
PAPER_TYPE = a4
PDF_HYPERLINKS = YES
USE_PDFLATEX = YES
LATEX_BATCHMODE = NO
LATEX_HIDE_INDICES = NO
LATEX_SOURCE_CODE = NO
LATEX_BIB_STYLE = plain
GENERATE_RTF = NO
RTF_OUTPUT = rtf
COMPACT_RTF = NO
RTF_HYPERLINKS = NO
RTF_SOURCE_CODE = NO
GENERATE_MAN = NO
MAN_OUTPUT = man
MAN_EXTENSION = .3
MAN_SUBDIR =
MAN_LINKS = NO
GENERATE_XML = NO
XML_OUTPUT = xml
XML_PROGRAMLISTING = YES
GENERATE_DOCBOOK = NO
DOCBOOK_OUTPUT = docbook
DOCBOOK_PROGRAMLISTING = NO
GENERATE_AUTOGEN_DEF = NO
GENERATE_PERLMOD = NO
PERLMOD_LATEX = NO
PERLMOD_PRETTY = YES
ENABLE_PREPROCESSING = YES
MACRO_EXPANSION = NO
EXPAND_ONLY_PREDEF = NO
SEARCH_INCLUDES = YES
SKIP_FUNCTION_MACROS = YES
ALLEXTERNALS = NO
EXTERNAL_GROUPS = YES
EXTERNAL_PAGES = YES
PERL_PATH = /usr/bin/perl
CLASS_DIAGRAMS = YES
HIDE_UNDOC_RELATIONS = YES
HAVE_DOT = NO
DOT_NUM_THREADS = 0
DOT_FONTNAME = Helvetica
DOT_FONTSIZE = 10
CLASS_GRAPH = YES
COLLABORATION_GRAPH = YES
GROUP_GRAPHS = YES
UML_LOOK = NO
UML_LIMIT_NUM_FIELDS = 10
TEMPLATE_RELATIONS = NO
INCLUDE_GRAPH = YES
INCLUDED_BY_GRAPH = YES
CALL_GRAPH = NO
CALLER_GRAPH = NO
GRAPHICAL_HIERARCHY = YES
DIRECTORY_GRAPH = YES
DOT_IMAGE_FORMAT = png
INTERACTIVE_SVG = NO
DOT_GRAPH_MAX_NODES = 50
MAX_DOT_GRAPH_DEPTH = 0
DOT_TRANSPARENT = NO
DOT_MULTI_TARGETS = NO
GENERATE_LEGEND = YES
DOT_CLEANUP = YES
INLINE_SOURCES = YES
SEARCHENGINE = YES
SHOW_FILES = YES

194
README.adoc Normal file
View File

@ -0,0 +1,194 @@
= identiconpp
:toc: preamble
:project: identiconpp
:uri-base: https://schlomp.space/tastytea/{project}
:uri-branch-master: {uri-base}/src/branch/master
:uri-reference-base: https://doc.schlomp.space/{project}
:uri-images-base: {uri-reference-base}
:uri-sigil: https://github.com/cupcake/sigil/
:uri-pydenticon: https://github.com/azaghal/pydenticon/
:uri-overlay: https://schlomp.space/tastytea/overlay
:uri-pgpkey: https://tastytea.de/tastytea_autosign.asc
:uri-gcc: https://gcc.gnu.org/
:uri-clang: https://clang.llvm.org/
:uri-cmake: https://cmake.org/
:uri-imagemagick: https://www.imagemagick.org/
:uri-asciidoc: http://asciidoc.org/
:uri-catch: https://github.com/catchorg/Catch2
*identiconpp* is a library to generate identicons for C++.
You get the images as `Magick::Image`. This allows you to make all kinds of
modifications.
.Used algorithms, left to right: 4x4 ltr_symmetric, 20px padding; 5x5 sigil; 5x5 ltr_asymmetric; 6x4 ltr_symmetric, 10px padding
====
image:{uri-images-base}/identicon1.png[]
image:{uri-images-base}/identicon2.png[]
image:{uri-images-base}/identicon3.png[]
image:{uri-images-base}/identicon4.png[]
The example images above are generated using
link:{uri-branch-master}/examples/example.cpp[example.cpp].
====
== Features
* [x] Symmetric identicons
* [x] sigil identicons
* [x] Asymmetric identicons
* [x] Padding
== Usage
The HTML reference can be generated with `build_doc.sh`, if doxygen is
installed. It is also available at
link:{uri-reference-base}/classIdenticonpp.html[doc.schlomp.space/identiconpp/].
You need to generate hashes yourself, any hexadecimal string will do. Make sure
to use a safe hashing algorithm for sensitive data (*not MD5*). You can select
as many columns and rows as you like, but make sure you have enough entropy.
If something seems to be wrong, exceptions will be thrown.
The "sigil" algorithm generates the same results as link:{uri-sigil}[sigil] and
link:{uri-pydenticon}[pydenticon].
=== Example
[source,c++]
----
// Compile with g++ $(pkg-config --libs --cflags identiconpp)
#include <iostream>
#include <identiconpp.hpp>
#include <Magick++/Image.h>
int main()
{
Identiconpp identicon(5, 5, Identiconpp::algorithm::ltr_symmetric,
"ffffff80", { "800000ff" }, { 10, 10 });
Magick::Image img;
img = identicon.generate("55502f40dc8b7c769880b10874abc9d0", 200);
img.write("identicon.png");
std::cout << identicon.generate_base64("png", "5550", 200) << std::endl;
}
----
== Install
=== Gentoo
Gentoo ebuilds are available via my link:{uri-overlay}[repository].
=== Automatically generated packages
Binary packages are generated automatically for each
link:{uri-base}/releases[release]. They are signed with my
link:{uri-pgpkey}[automatic signing key].
=== From source
==== Dependencies
* C++ compiler (tested: link:{uri-gcc}[gcc] 6/8/9, link:{uri-clang}[clang] 7)
* {uri-cmake}[cmake] (at least 3.6)
* link:{uri-imagemagick}[imagemagick] (tested: 7.0 / 6.7)
* Optional:
** Manpage: {uri-asciidoc}[asciidoc] (tested: 8.6)
** Tests: {uri-catch}[catch] (tested: 2.5 / 1.2)
On a Debian system, install the packages:
`build-essential cmake libmagick++-dev`.
==== Compile
[source,shell]
----
mkdir build
cd build
cmake ..
cmake --build .
make install
----
.cmake options:
* `-DCMAKE_BUILD_TYPE=Debug` for a debug build
* `-DWITH_TESTS=YES` to build tests
* One of:
** `-DWITH_DEB=YES` to generate a deb-package
** `-DWITH_RPM=YES` to generate an rpm-package
To generate a binary package, run `make package`.
include::{uri-base}/raw/branch/master/CONTRIBUTING.adoc[]
== Algorithms
=== ltr_symmetric
* Create image with width=columns, height=rows.
* Set background color.
* Select half of the columns, or half of the columns + 1 if uneven.
** `columns / 2 + columns % 2`
* Pixels are drawn from left to right, top to bottom.
* Use bits from digest to determine if a pixel is painted(1) or not(0).
* Mirror the pixels vertically.
* Use the following bits to pick the foreground color.
** You need `floor(log2(n_colors)) + 1` bits.
* Scale image proportionally to requested width.
----
0111 0011 1101 1100 […] 1111 0111 0101 0111
^ ^
+----------------------------+-------------->
| |
pixel matrix foreground color
----
Implemented in
link:{uri-branch-master}/src/ltr_symmetric.cpp[ltr_symmetric.cpp].
=== ltr_asymmetric
* Create image with width=columns, height=rows.
* Set background color.
* Pixels are drawn from left to right, top to bottom.
* Use bits from digest to determine if a pixel is painted(1) or not(0).
* Use the following bits to pick the foreground color.
** You need `floor(log2(n_colors)) + 1` bits.
* Scale image proportionally to requested width.
----
0111 0011 1101 1100 […] 1111 0111 0101 0111
^ ^
+----------------------------+-------------->
| |
pixel matrix foreground color
----
Implemented in
link:{uri-branch-master}/src/ltr_asymmetric.cpp[ltr_asymmetric.cpp].
=== sigil
* Create image with width=columns, height=rows.
* Set background color.
* Select half of the columns, or half of the columns + 1 if uneven.
** `columns / 2 + columns % 2`
* Pixels are drawn from top to bottom, left to right.
* Use the first 8 bits to pick the foreground color.
* Use the following bits to determine if a pixel is painted(1) or not(0).
* Mirror the pixels vertically.
* Scale image proportionally to requested width.
----
0111 0011 1101 1100
^ ^
+---------+--------->
| |
foreground color |
pixel matrix
----
Implemented in link:{uri-branch-master}/src/sigil.cpp[sigil.cpp].

212
README.md
View File

@ -1,212 +0,0 @@
**identiconpp** is a library to generate identicons for C++ and C.
You get the images as `Magick::Image`. This allows you to make all kinds of
modifications.
![](https://doc.schlomp.space/identiconpp/identicon1.png
"4x4 identicon, ltr_symmetric, 20px padding")
![](https://doc.schlomp.space/identiconpp/identicon2.png
"5x5 identicon, sigil")
![](https://doc.schlomp.space/identiconpp/identicon3.png
"5x5 identicon, ltr_asymmetric")
![](https://doc.schlomp.space/identiconpp/identicon4.png
"6x4 identicon, ltr_symmetric, 10px padding")
The example images above are generated using [example.cpp]
(https://schlomp.space/tastytea/identiconpp/src/branch/master/example.cpp).
## Features
* [x] Symmetric identicons
* [x] sigil identicons
* [x] Asymmetric identicons
* [x] Padding
## Usage
The HTML reference can be generated with build_doc.sh, if doxygen is installed.
It is also available at [doc.schlomp.space/identiconpp/]
(https://doc.schlomp.space/identiconpp/classIdenticonpp.html).
You need to generate hashes yourself, any hexadecimal string will do. Make sure
to use a safe hashing algorithm for sensitive data (**not MD5**). You can select
as many columns and rows as you like, but make sure you have enough entropy.
If something seems to be wrong, exceptions will be thrown.
The "sigil" algorithm generates the same results as
[sigil](https://github.com/cupcake/sigil/) and
[pydenticon](https://github.com/azaghal/pydenticon/).
### Example
```C++
// Compile with g++ $(Magick++-config --cppflags --ldflags) -lidenticonpp
#include <iostream>
#include <identiconpp.hpp>
#include <Magick++/Image.h>
int main()
{
Identiconpp identicon(5, 5, Identiconpp::algorithm::ltr_symmetric,
"ffffff80", { "800000ff" }, { 10, 10 });
Magick::Image img;
img = identicon.generate("55502f40dc8b7c769880b10874abc9d0", 200);
img.write("identicon.png");
std::cout << identicon.generate_base64("png", "5550", 200) << std::endl;
}
```
### C interface
This is somewhat experimental. Have a look at [example.c]
(https://schlomp.space/tastytea/identiconpp/src/branch/master/example.c) and
[identiconpp_c.h](https://doc.schlomp.space/identiconpp/identiconpp__c_8h.html).
It seems to be impossible to use `Magick++` and `MagickWand` in the same
library, so the images are returned as base64-encoded strings.
## Install
### Gentoo
Gentoo ebuilds are available via my
[repository](https://schlomp.space/tastytea/overlay).
### Automatically generated packages
Binary packages are generated automatically for each
[release](https://schlomp.space/tastytea/identiconpp/releases) in the
formats:
* deb
* rpm
* tar.gz
They are generated on Debian Stretch 64 bit and signed with my
[automatic signing key](https://tastytea.de/tastytea_autosign.asc).
### From source
#### Dependencies
* C++ compiler (tested: [gcc](https://gcc.gnu.org/) 5/6/7/8,
[clang](https://llvm.org/) 5/6)
* [cmake](https://cmake.org/) (at least 3.2)
* [imagemagick](https://www.imagemagick.org/) (tested: 7.0 / 6.7)
* Optional:
* Tests: [Catch](https://github.com/catchorg/Catch2) (tested: 2.3 / 1.2)
On a Debian system, install the packages:
`build-essential cmake libmagick++-dev`.
#### Compile
```SH
mkdir build
cd build
cmake ..
make
make install
```
##### cmake options
* `-DCMAKE_BUILD_TYPE=Debug` for a debug build
* `-DWITH_TESTS=YES` to build tests
* One of:
* `-DWITH_DEB=YES` to generate a deb-package
* `-DWITH_RPM=YES` to generate an rpm-package
To generate a binary package, execute `make package`
## Contributing
Contributions are always welcome. You can submit them as pull requests on
schlomp.space or via email to `tastytea`@`tastytea.de` (ideally using
`git format-patch` or `git send-email`). Please do not submit them via GitHub,
it is just a mirror.
## Contact
See https://tastytea.de/
## License & Copyright
```PLAIN
Copyright © 2018 tastytea <tastytea@tastytea.de>.
License GPLv3: GNU GPL version 3 <https://www.gnu.org/licenses/gpl-3.0.html>.
This program comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
```
## Algorithms
### ltr_symmetric
* Create image with width=columns, height=rows.
* Set background color.
* Select half of the columns, or half of the columns + 1 if uneven.
* `columns / 2 + columns % 2`
* Pixels are drawn from left to right, top to bottom.
* Use bits from digest to determine if a pixel is painted(1) or not(0).
* Mirror the pixels vertically.
* Use the following bits to pick the foreground color.
* You need `floor(log2(n_colors)) + 1` bits.
* Scale image proportionally to requested width.
```PLAIN
0111 0011 1101 1100 […] 1111 0111 0101 0111
^ ^
+----------------------------+-------------->
| |
pixel matrix foreground color
```
Implemented in [ltr_symmetric.cpp]
(https://schlomp.space/tastytea/identiconpp/src/branch/master/src/ltr_symmetric.cpp)
### ltr_asymmetric
* Create image with width=columns, height=rows.
* Set background color.
* Pixels are drawn from left to right, top to bottom.
* Use bits from digest to determine if a pixel is painted(1) or not(0).
* Use the following bits to pick the foreground color.
* * You need `floor(log2(n_colors)) + 1` bits.
* Scale image proportionally to requested width.
```PLAIN
0111 0011 1101 1100 […] 1111 0111 0101 0111
^ ^
+----------------------------+-------------->
| |
pixel matrix foreground color
```
Implemented in [ltr_asymmetric.cpp]
(https://schlomp.space/tastytea/identiconpp/src/branch/master/src/ltr_asymmetric.cpp)
### sigil
* Create image with width=columns, height=rows.
* Set background color.
* Select half of the columns, or half of the columns + 1 if uneven.
* `columns / 2 + columns % 2`
* Pixels are drawn from top to bottom, left to right.
* Use the first 8 bits to pick the foreground color.
* Use the following bits to determine if a pixel is painted(1) or not(0).
* Mirror the pixels vertically.
* Scale image proportionally to requested width.
```PLAIN
0111 0011 1101 1100
^ ^
+---------+--------->
| |
foreground color |
pixel matrix
```
Implemented in [sigil.cpp]
(https://schlomp.space/tastytea/identiconpp/src/branch/master/src/sigil.cpp)

View File

@ -1,8 +1,7 @@
#!/bin/sh
#!/bin/bash
if [ -f Doxyfile ]; then
if [[ -f Doxyfile ]]; then
mkdir -p doc
(cat Doxyfile && echo -n "PROJECT_NUMBER = " &&
grep -Eo '[0-9]+.[0-9]+.[0-9]+$' CMakeLists.txt) \
| doxygen -
(doxygen -s -g - && cat Doxyfile && echo -n "PROJECT_NUMBER = " &&
grep -Eo '[0-9]+.[0-9]+.[0-9]+$' CMakeLists.txt) | doxygen -
fi

19
cmake/CMakeLists.txt Normal file
View File

@ -0,0 +1,19 @@
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
write_basic_package_version_file("${PROJECT_NAME}ConfigVersion.cmake"
VERSION ${PACKAGE_VERSION}
COMPATIBILITY ExactVersion) # NOTE: Set to SameMajorVersion when stable.
install(EXPORT ${PROJECT_NAME}Targets
FILE "${PROJECT_NAME}Targets.cmake"
NAMESPACE "${PROJECT_NAME}::"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
configure_file("${PROJECT_NAME}Config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" @ONLY)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")

View File

@ -0,0 +1,7 @@
include(CMakeFindDependencyMacro)
include(GNUInstallDirs)
find_dependency(PkgConfig REQUIRED)
pkg_check_modules(Magick++ REQUIRED IMPORTED_TARGET Magick++)
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")

104
example.c
View File

@ -1,104 +0,0 @@
/* This file is part of identiconpp.
* Public Domain / CC-0
*
* Compile with gcc --std=c99 $(pkg-config --cflags --libs MagickWand) \
* $(pkg-config --cflags --libs openssl) -lidenticonpp
*/
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include "identiconpp_c.h"
#include <MagickWand/MagickWand.h>
#include <openssl/evp.h>
#include <openssl/bio.h>
char *b64decode(char *input, int length)
{
BIO *b64, *bmem;
char *buffer = (char *)malloc(length);
memset(buffer, 0, length);
b64 = BIO_new(BIO_f_base64());
BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
bmem = BIO_new_mem_buf(input, length);
bmem = BIO_push(b64, bmem);
BIO_read(bmem, buffer, length);
BIO_free_all(bmem);
return buffer;
}
int main(int argc, char *argv[])
{
char digest[65] = "973dfe463ec85785f5f95af5ba3906ee"
"db2d931c24e69824a89ea65dba4e813b";
const char colors[6][9] =
{
"800000ff",
"008000ff",
"000080ff",
"808000ff",
"008080ff",
"800080ff"
};
if (argc > 1)
{
strncpy(digest, argv[1], 64);
}
MagickWand *mw = NULL;
MagickWandGenesis();
mw = NewMagickWand();
{
const uint8_t padding[2] = { 20, 20 };
identiconpp_setup(4, 4, identiconpp_ltr_symmetric,
"ffffffff", colors, 6, padding);
uint64_t len = identiconpp_generate("png", digest, 200);
char base64[len];
strcpy(base64, identiconpp_base64());
MagickReadImageBlob(mw, b64decode(base64, len), len);
MagickWriteImage(mw, "identicon1.png");
}
{
const uint8_t padding[2] = { 0, 0 };
identiconpp_setup(5, 5, identiconpp_sigil,
"00000080", colors, 6, padding);
uint64_t len = identiconpp_generate("png", digest, 200);
char base64[len];
strcpy(base64, identiconpp_base64());
MagickReadImageBlob(mw, b64decode(base64, len), len);
MagickWriteImage(mw, "identicon2.png");
}
{
const uint8_t padding[2] = { 0, 0 };
identiconpp_setup(5, 5, identiconpp_ltr_asymmetric,
"000000ff", colors, 6, padding);
uint64_t len = identiconpp_generate("png", digest, 200);
char base64[len];
strcpy(base64, identiconpp_base64());
MagickReadImageBlob(mw, b64decode(base64, len), len);
MagickWriteImage(mw, "identicon3.png");
}
{
const uint8_t padding[2] = { 10, 10 };
identiconpp_setup(6, 4, identiconpp_ltr_symmetric,
"000000c0", colors, 6, padding);
uint64_t len = identiconpp_generate("png", digest, 200);
char base64[len];
strcpy(base64, identiconpp_base64());
MagickReadImageBlob(mw, b64decode(base64, len), len);
MagickWriteImage(mw, "identicon4.png");
}
DestroyMagickWand(mw);
MagickWandTerminus();
}

4
examples/CMakeLists.txt Normal file
View File

@ -0,0 +1,4 @@
# You need to install identiconpp first so that CMake can find it.
find_package(identiconpp REQUIRED CONFIG)
add_executable(example example.cpp)
target_link_libraries(example PRIVATE identiconpp::identiconpp)

View File

@ -1,7 +1,7 @@
/* This file is part of identiconpp.
* Public Domain / CC-0
*
* Compile with g++ $(Magick++-config --cppflags --ldflags) -lidenticonpp
* Compile with g++ $(pkg-config --libs --cflags identiconpp)
*/
#include <string>

4
include/CMakeLists.txt Normal file
View File

@ -0,0 +1,4 @@
include(GNUInstallDirs)
install(FILES "identiconpp.hpp"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")

View File

@ -73,7 +73,7 @@ public:
* @param background Background color, hexadecimal, rrggbbaa
* @param foreground vector of foreground colors
* @param padding Padding in pixels { left & right, top & down }
*
*
* @since before 0.5.0
*/
explicit Identiconpp(const uint8_t columns, const uint8_t rows,
@ -126,7 +126,7 @@ private:
* @param digest The pre-computed digest
*
* @return The image
*
*
* @since before 0.5.0
*/
Magick::Image generate_ltr_symmetric(const string &digest);
@ -141,7 +141,7 @@ private:
* @param digest The pre-computed digest
*
* @return The image
*
*
* @since before 0.5.0
*/
Magick::Image generate_ltr_asymmetric(const string &digest);
@ -156,7 +156,7 @@ private:
* @param digest The pre-computed digest
*
* @return The image
*
*
* @since before 0.5.0
*/
Magick::Image generate_sigil(const string &digest);
@ -168,7 +168,7 @@ private:
*
* @param digest The pre-computed digest
* @param type The type of identicon
*
*
* @since before 0.5.0
*/
void check_entropy(const string &digest, algorithm type);
@ -180,7 +180,7 @@ private:
* @param digest The digest
*
* @return The bit.
*
*
* @since before 0.5.0
*/
bool get_bit(const uint16_t bit, const string &digest);
@ -194,7 +194,7 @@ private:
* @param digest The digest
*
* @return A foreground color.
*
*
* @since before 0.5.0
*/
Magick::Color get_color(const uint16_t firstbit, const string &digest);
@ -205,7 +205,7 @@ private:
* @param c Character to check
*
* @return true if not hex.
*
*
* @since before 0.5.0
*/
static bool not_hex(const char c);
@ -214,7 +214,7 @@ private:
* @brief Performs checks on a color definition in a string.
*
* @param color The color as string
*
*
* @since before 0.5.0
*/
void check_color(const string &color);

View File

@ -4,42 +4,58 @@ set(CPACK_PACKAGE_VERSION_MAJOR ${${CMAKE_PROJECT_NAME}_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${${CMAKE_PROJECT_NAME}_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${${CMAKE_PROJECT_NAME}_VERSION_PATCH})
set(CPACK_PACKAGE_VERSION ${${CMAKE_PROJECT_NAME}_VERSION})
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Library to generate identicons. Written in C++.")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY
"Library to generate identicons for C++ and C.")
set(CPACK_PACKAGE_CONTACT "tastytea <tastytea@tastytea.de>")
set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
set(CPACK_RESOURCE_FILE_README "${PROJECT_SOURCE_DIR}/README.md")
set(CPACK_RESOURCE_FILE_README "${PROJECT_SOURCE_DIR}/README.adoc")
list(APPEND CPACK_SOURCE_IGNORE_FILES "/\\\\.git"
"/.gitignore"
"/build/"
"/doc/"
"\\\\.sublime-"
"/.drone.yml")
"/.gitignore"
"/build/"
"/doc/"
"/.drone.yml"
"/.dir-locals.el")
execute_process(COMMAND uname -m
OUTPUT_VARIABLE CPACK_PACKAGE_ARCHITECTURE
OUTPUT_STRIP_TRAILING_WHITESPACE)
OUTPUT_VARIABLE CPACK_PACKAGE_ARCHITECTURE
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(CPACK_PACKAGE_FILE_NAME
"${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}_${CPACK_PACKAGE_ARCHITECTURE}")
"${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}_${CPACK_PACKAGE_ARCHITECTURE}")
set(CPACK_GENERATOR "TGZ")
set(CPACK_SOURCE_GENERATOR "TGZ")
if (WITH_DEB)
set(CPACK_GENERATOR "DEB")
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://schlomp.space/tastytea/${CMAKE_PROJECT_NAME}")
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
execute_process(COMMAND dpkg --print-architecture
OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(CPACK_PACKAGE_FILE_NAME
"${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}-0_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}")
set(CPACK_GENERATOR "DEB")
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE
"https://schlomp.space/tastytea/${CMAKE_PROJECT_NAME}")
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
execute_process(COMMAND dpkg --print-architecture
OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND lsb_release --codename --short
OUTPUT_VARIABLE DEBIAN_CODENAME
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(CPACK_PACKAGE_FILE_NAME
"${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}-0_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}_${DEBIAN_CODENAME}")
endif()
if (WITH_RPM)
set(CPACK_GENERATOR "RPM")
set(CPACK_RPM_PACKAGE_LICENSE "GPL-3")
set(CPACK_RPM_PACKAGE_URL "https://schlomp.space/tastytea/${CMAKE_PROJECT_NAME}")
set(CPACK_RPM_PACKAGE_REQUIRES "libMagick++, libxdg-basedir >= 1.2.0")
set(CPACK_GENERATOR "RPM")
set(CPACK_RPM_PACKAGE_LICENSE "GPL-3")
set(CPACK_RPM_PACKAGE_URL
"https://schlomp.space/tastytea/${CMAKE_PROJECT_NAME}")
set(CPACK_RPM_PACKAGE_REQUIRES "libMagick++")
set(CPACK_PACKAGE_FILE_NAME
"${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-0.${CPACK_PACKAGE_ARCHITECTURE}")
execute_process(COMMAND lsb_release --id --short
OUTPUT_VARIABLE OS
OUTPUT_STRIP_TRAILING_WHITESPACE)
if("${OS}" STREQUAL "CentOS")
execute_process(COMMAND rpm -E %{rhel}
OUTPUT_VARIABLE OS_RELEASE
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(CPACK_PACKAGE_FILE_NAME
"${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-0.${CPACK_PACKAGE_ARCHITECTURE}")
"${CPACK_PACKAGE_FILE_NAME}.centos${OS_RELEASE}")
endif()
endif()
include(CPack)

View File

@ -0,0 +1,7 @@
include(GNUInstallDirs)
configure_file("${PROJECT_NAME}.pc.in"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc" @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")

View File

@ -0,0 +1,12 @@
name=@PROJECT_NAME@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
Name: ${name}
Description: @PROJECT_DESCRIPTION@
Version: @PROJECT_VERSION@
Libs: -L${libdir} -l${name}
Cflags: -I${includedir}
Requires: Magick++

25
src/CMakeLists.txt Normal file
View File

@ -0,0 +1,25 @@
include(GNUInstallDirs)
find_package(PkgConfig REQUIRED)
pkg_check_modules(Magick++ REQUIRED IMPORTED_TARGET Magick++)
file(GLOB sources *.cpp)
add_library(${PROJECT_NAME}
${sources} ${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME}.hpp)
set_target_properties(${PROJECT_NAME} PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${${PROJECT_NAME}_VERSION_MAJOR})
target_include_directories(${PROJECT_NAME}
PUBLIC
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
target_link_libraries(${PROJECT_NAME} PUBLIC PkgConfig::Magick++)
install(TARGETS ${PROJECT_NAME}
EXPORT "${PROJECT_NAME}Targets"
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})

View File

@ -1,103 +0,0 @@
/* This file is part of identiconpp.
* Copyright © 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <vector>
#include <memory>
#include <exception>
#include <iostream>
#include <Magick++/Image.h>
#include <Magick++/Blob.h>
#include "identiconpp.hpp"
#include "debug.hpp"
#include "identiconpp_c.h"
using std::cerr;
using std::endl;
static std::unique_ptr<Identiconpp> identicon;
static string base64;
bool identiconpp_setup(const uint8_t columns, const uint8_t rows,
identiconpp_algorithm type,
const char background[9],
const char foreground[][9],
const uint8_t foreground_len,
const uint8_t padding[2])
{
Identiconpp::algorithm algo = Identiconpp::algorithm::ltr_symmetric;
switch (type)
{
case identiconpp_ltr_symmetric:
{
algo = Identiconpp::algorithm::ltr_symmetric;
break;
}
case identiconpp_ltr_asymmetric:
{
algo = Identiconpp::algorithm::ltr_asymmetric;
break;
}
case identiconpp_sigil:
{
algo = Identiconpp::algorithm::sigil;
break;
}
}
std::vector<string> vforeground;
for (uint8_t i = 0; i < foreground_len; ++i)
{
vforeground.push_back(foreground[i]);
}
try
{
identicon = std::make_unique<Identiconpp>(
Identiconpp(columns, rows, algo, background, vforeground,
{ padding[0], padding[1] }));
}
catch (const std::exception &e)
{
cerr << e.what() << endl;
return false;
}
return true;
}
uint64_t identiconpp_generate(const char magick[],
const char digest[], const uint16_t width)
{
try
{
Magick::Image img = identicon->generate(digest, width);
Magick::Blob blob;
img.magick(magick);
img.write(&blob);
base64 = blob.base64();
return blob.base64().length();
}
catch (const std::exception &e)
{
cerr << e.what() << endl;
return 0;
}
}
const char *identiconpp_base64()
{
return base64.c_str();
}

View File

@ -1,6 +1,6 @@
/* This file is part of identiconpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.

View File

@ -145,7 +145,7 @@ Magick::Color Identiconpp::get_color(const uint16_t firstbit,
// std::stringstream does not support writing into uint16_t
unsigned short bits;
ss >> bits;
// Shift an one $colorbits times to the left, substract 1. This leaves us
// with $colorbits ones. Then AND bits and our ones to keep only as many
// bits as we need.

View File

@ -1,99 +0,0 @@
/* This file is part of identiconpp.
* Copyright © 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef IDENTICONPP_C_H
#define IDENTICONPP_C_H
#ifdef __cplusplus
extern "C"
{
#endif
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
/*!
* @brief C interface for identiconpp.
* @file identiconpp_c.h
* @example example.c
*/
/*!
* @brief List of identicon algorithms
*/
typedef enum
{
//! Generates symmetric (vertically mirrored) identicons.
identiconpp_ltr_symmetric,
//! Generates asymmetric identicons.
identiconpp_ltr_asymmetric,
/*!
* Generates the same results as
* [sigil](https://github.com/cupcake/sigil/) and
* [pydenticon](https://github.com/azaghal/pydenticon/).
*/
identiconpp_sigil
} identiconpp_algorithm;
/*!
* @brief Setup identicon parameters.
*
* @param columns Number of columns
* @param rows Number of rows
* @param type The algorithm to use
* @param background Background color, hexadecimal, rrggbbaa
* @param foreground Array of foreground colors
* @param foreground_len Length of the array of foreground colors
* @param padding Padding in pixels { left & right, top & down }
*
* @return false on error, true otherwise.
*
* @since before 0.5.0
*/
bool identiconpp_setup(const uint8_t columns, const uint8_t rows,
identiconpp_algorithm type,
const char background[9],
const char foreground[][9],
const uint8_t foreground_len,
const uint8_t padding[2]);
/*!
* @brief Generates identicon from digest.
*
* @param magick See http://imagemagick.org/script/formats.php
* @param digest The pre-computed digest
* @param width The width of the identicon
*
* @return Length of the generated base64-string, or 0 on error.
*
* @since before 0.5.0
*/
uint64_t identiconpp_generate(const char magick[],
const char digest[], const uint16_t width);
/*!
* @brief Return base64-encoded string of the image generated with
* identiconpp_generate().
*
* @since before 0.5.0
*/
const char *identiconpp_base64();
#ifdef __cplusplus
}
#endif
#endif // IDENTICONPP_C_H

View File

@ -1,76 +0,0 @@
#include <catch.hpp>
#include <string>
#include <exception>
#include <vector>
#include <cstdint>
#include <Magick++/Image.h>
#include "identiconpp_c.h"
using std::string;
using std::uint8_t;
using std::uint64_t;
SCENARIO("C interface", "[C]")
{
GIVEN("The digest: sha256(test@example.com)")
{
char digest[65] = "973dfe463ec85785f5f95af5ba3906ee"
"db2d931c24e69824a89ea65dba4e813b";
const uint8_t padding[2] = { 20, 40 };
bool success = false;
WHEN("256 bits of entropy is required")
{
const char colors[15][9] =
{
"000000ff", "000000ff", "000000ff", "000000ff", "000000ff",
"000000ff", "000000ff", "000000ff", "000000ff", "000000ff",
"000000ff", "000000ff", "000000ff", "000000ff", "000000ff"
};
success = identiconpp_setup(18, 28,
identiconpp_ltr_symmetric,
"ffffffff",
colors, 15, padding);
uint64_t len = identiconpp_generate("png", digest, 50);
if (len == 0)
{
success = false;
}
if (string(identiconpp_base64()).length() != len)
{
success = false;
}
THEN("Does not crash")
{
REQUIRE(success == true);
}
}
WHEN("257 bits of entropy is required")
{
const char colors[16][9] =
{
"000000ff", "000000ff", "000000ff", "000000ff", "000000ff",
"000000ff", "000000ff", "000000ff", "000000ff", "000000ff",
"000000ff", "000000ff", "000000ff", "000000ff", "000000ff",
"000000ff"
};
success = identiconpp_setup(18, 28,
identiconpp_ltr_symmetric,
"ffffffff",
colors, 16, padding);
if (identiconpp_generate("png", digest, 50) == 0)
{
success = false;
}
THEN("Crashes")
{
REQUIRE(success == false);
}
}
}
}

View File

@ -1,27 +0,0 @@
if(WITH_TESTS)
include(CTest)
file(GLOB sources_tests src/tests/test_*.cpp)
find_package(Catch2)
if(Catch2_FOUND) # Catch 2.x
include(Catch)
add_executable(all_tests src/tests/main.cpp ${sources_tests})
target_link_libraries(all_tests ${CMAKE_PROJECT_NAME} Catch2::Catch2)
target_include_directories(all_tests PRIVATE "/usr/include/catch2")
catch_discover_tests(all_tests)
else() # Catch 1.x
if(EXISTS "/usr/include/catch.hpp")
message(STATUS "Catch 1.x found.")
foreach(src ${sources_tests})
get_filename_component(bin ${src} NAME_WE)
add_executable(${bin} src/tests/main.cpp ${src})
target_link_libraries(${bin} ${CMAKE_PROJECT_NAME})
target_include_directories(${bin} PRIVATE "/usr/include/catch2")
add_test(${bin} ${bin})
endforeach()
else()
message(FATAL_ERROR
"Neither Catch 2.x nor Catch 1.x could be found.")
endif()
endif()
endif()

24
tests/CMakeLists.txt Normal file
View File

@ -0,0 +1,24 @@
include(CTest)
file(GLOB sources_tests test_*.cpp)
find_package(Catch2)
if(Catch2_FOUND) # Catch 2.x
include(Catch)
add_executable(all_tests main.cpp ${sources_tests})
target_link_libraries(all_tests Catch2::Catch2 ${PROJECT_NAME})
target_include_directories(all_tests PRIVATE "/usr/include/catch2")
catch_discover_tests(all_tests EXTRA_ARGS "${EXTRA_TEST_ARGS}")
else() # Catch 1.x
if(EXISTS "/usr/include/catch.hpp")
message(STATUS "Catch 1.x found.")
foreach(src ${sources_tests})
get_filename_component(bin ${src} NAME_WE)
add_executable(${bin} main.cpp ${src})
target_link_libraries(${bin} ${PROJECT_NAME})
add_test(${bin} ${bin} "${EXTRA_TEST_ARGS}")
endforeach()
else()
message(FATAL_ERROR
"Neither Catch 2.x nor Catch 1.x could be found.")
endif()
endif()