Skip to content

Commit

Permalink
C++20 modules (#37)
Browse files Browse the repository at this point in the history
* C++20 modules

Signed-off-by: Alexander Diemand <codieplusplus@apax.net>

* fini; sha1-256 deprecated

Signed-off-by: Alexander Diemand <codieplusplus@apax.net>

* compilation as submodule of elykseer-cpp

Signed-off-by: Alexander Diemand <codieplusplus@apax.net>

* remove literate c++ code

Signed-off-by: Alexander Diemand <codieplusplus@apax.net>

* update CI

Signed-off-by: Alexander Diemand <codieplusplus@apax.net>

---------

Signed-off-by: Alexander Diemand <codieplusplus@apax.net>
  • Loading branch information
CodiePP authored Jan 25, 2025
1 parent 25e6586 commit 44a29f5
Show file tree
Hide file tree
Showing 155 changed files with 3,940 additions and 3,254 deletions.
14 changes: 10 additions & 4 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,25 @@ jobs:
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ubuntu-latest

env:
CC: clang
CXX: clang++

steps:
- uses: actions/checkout@v2

- name: Install dependencies
run: |
sudo apt update
sudo apt-get -y install cmake gcc swig opam m4 busybox pandoc libdigest-sha3-perl libboost-all-dev libboost-contract-dev gettext pkg-config automake autoconf libtool
sudo apt-get -y install cmake ninja-build clang swig opam m4 busybox libdigest-sha3-perl libboost-all-dev libboost-contract-dev gettext pkg-config automake autoconf libtool
gpg --keyserver hkp://keyserver.ubuntu.com --recv E2DFCA9AA83BA568AF39280999283F5327C5D38F
- name: Update submodules
shell: bash
working-directory: ${{github.workspace}}/
run: git submodule update --init
run: |
mkdir -vp build
git submodule update --init
- name: Build dependencies
shell: bash
Expand All @@ -45,7 +51,7 @@ jobs:
# Note the current convention is to use the -S and -B options here to specify source
# and build directories, but this is only available with CMake 3.13 and higher.
# The CMake binaries on the Github Actions machines are (as of this writing) 3.12
run: cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE .
run: cmake --fresh -GNinja -DCMAKE_BUILD_TYPE=$BUILD_TYPE ..

- name: Build
working-directory: ${{github.workspace}}/build
Expand All @@ -59,7 +65,7 @@ jobs:
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
#run: ctest -C $BUILD_TYPE
run: ./ut.sh
run: ctest

- name: Packaging
shell: bash
Expand Down
15 changes: 4 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,7 @@
._*
.DS_Store

build/CMakeCache.txt
build/CMakeFiles/
build/CMakeScripts
build/Makefile
build/cmake_install.cmake
build/src
build/test
build/*.build/
build/*.xcodeproj/
build/elykseer-crypto-*.sh
build/elykseer-crypto-*.tar.gz
build

.fake
.ionide
Expand All @@ -69,7 +59,10 @@ install_manifest.txt
ext/Darwin_arm64
ext/Darwin_amd64
ext/Linux_aarch64
ext/Linux_x86_64
ext/_ccache
ext/w64devkit
ext/xWindows_x86_64

.cache
build/compile_commands.json
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "ext/gitalk"]
path = ext/gitalk
url = https://github.com/CodiePP/gitalk.git
[submodule "ext/cryptopp"]
path = ext/cryptopp
url = https://github.com/weidai11/cryptopp.git
Expand Down
171 changes: 171 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@

cmake_minimum_required(VERSION 3.30)

cmake_policy(SET CMP0074 NEW)
cmake_policy(SET CMP0167 NEW)

IF(DEFINED CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING
"Choose the type of build, options are:
None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used)
Debug Release RelWithDebInfo MinSizeRel." )
ELSE()
SET(CMAKE_BUILD_TYPE Debug CACHE STRING
"Choose the type of build, options are:
None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used)
Debug Release RelWithDebInfo MinSizeRel." )
ENDIF()

find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
endif()

project(elykseer-crypto CXX)

# The version number.
set (${PROJECT_NAME}_VERSION_MAJOR 2)
set (${PROJECT_NAME}_VERSION_MINOR 0)
set (${PROJECT_NAME}_VERSION_PATCH 1)
set (${PROJECT_NAME}_VERSION_STRING ${elykseer-crypto_VERSION_MAJOR}.${elykseer-crypto_VERSION_MINOR}.${elykseer-crypto_VERSION_PATCH})

# choose either one
set(USE_OPENSSL NO)
set(USE_CRYPTOPP YES)

option(RUN_ADDRESS_SANITIZER "using Clang you can turn on address sanitizer in Debug")

IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_definitions( -DDEBUG )
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
ELSE()
add_definitions( -UDEBUG )
ENDIF()

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON)
set(CMAKE_CXX_SCAN_FOR_MODULES ON)

set(CMAKE_POSITION_INDEPENDENT_CODE ON)

find_package(PkgConfig REQUIRED)
find_package(ZLIB REQUIRED)
#find_package(OpenMP REQUIRED)

if(NOT CMAKE_CROSSCOMPILING)
find_program(CPPCHECK NAMES cppcheck)
endif()

IF(CPPCHECK)
message(STATUS "Found: cppcheck")
add_custom_target(cppcheck
${CPPCHECK}
-Uassert --std=c++20 --enable=all
${CMAKE_SOURCE_DIR}/src/lxr/*.hpp
${CMAKE_SOURCE_DIR}/src/*.cpp
${CMAKE_SOURCE_DIR}/test/*.cpp
-I ${CMAKE_SOURCE_DIR}/../ext
-I /opt/homebrew/include
)
ELSE()
message(STATUS "Cppcheck - not found")
message(STATUS " Build target 'cppcheck' not available.")
ENDIF()

set(PROCESSOR_TYPE ${CMAKE_SYSTEM_PROCESSOR})
set(SELECTED_AR ${CMAKE_AR})
set(LIB_PREFIX "")

# OS dependent
IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(CMAKE_OSX_DEPLOYMENT_TARGET "13.6")
find_program (SELECTED_AR NAMES ar PATHS /opt/homebrew/opt/binutils/bin /opt/homebrew/ NO_DEFAULT_PATH REQUIRED)
message(STATUS "Selected: ar in " ${SELECTED_AR})
set(LIB_PREFIX "lib")
set(libs "dl" ${ZLIB_LIBRARIES})
ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")

IF(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
IF(${CMAKE_SYSTEM_PROCESSOR} MATCHES "AMD64")
set(PROCESSOR_TYPE "x86_64")
ENDIF(${CMAKE_SYSTEM_PROCESSOR} MATCHES "AMD64")
set(LIB_PREFIX "lib")
set(libs ${ZLIB_LIBRARIES})
ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Windows")

IF(${CMAKE_HOST_SYSTEM_NAME} MATCHES "FreeBSD")
set(SELECTED_AR "/usr/local/bin/ar")
ENDIF(${CMAKE_HOST_SYSTEM_NAME} MATCHES "FreeBSD")
IF(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
set(LIB_PREFIX "lib")
set(libs "dl" ${ZLIB_LIBRARIES})
ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")

IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(LIB_PREFIX "lib")
set(libs "dl" ${ZLIB_LIBRARIES})
ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")

IF(${CMAKE_CROSSCOMPILING})
set(CROSS_PREFIX "x")
ELSE()
set(CROSS_PREFIX "")
ENDIF()
set(EXT_PATH ${CROSS_PREFIX}${CMAKE_SYSTEM_NAME}_${PROCESSOR_TYPE})

# other external tools
include_directories(ext)
include_directories(ext/${EXT_PATH}/include)
link_directories("ext/${EXT_PATH}/lib")

# cryptography
IF(USE_CRYPTOPP)
add_definitions( -DCRYPTOPP )
add_definitions( -DCRYPTOLIB=CRYPTOPP )
add_library(libcryptopp_s STATIC IMPORTED)
SET_TARGET_PROPERTIES(libcryptopp_s PROPERTIES IMPORTED_LOCATION ${CMAKE_HOME_DIRECTORY}/ext/${EXT_PATH}/lib/libcryptopp.a)
set(CRYPTO_LIBS "libcryptopp_s")
ENDIF(USE_CRYPTOPP)

IF(USE_OPENSSL)
add_definitions( -DOPENSSL )
add_definitions( -DCRYPTOLIB=OPENSSL )
IF(${CMAKE_HOST_SYSTEM_NAME} MATCHES "Darwin")
set(OPENSSL_ROOT_DIR "/opt/homebrew/opt/openssl")
ENDIF(${CMAKE_HOST_SYSTEM_NAME} MATCHES "Darwin")
find_package(OpenSSL REQUIRED)
include_directories(${OPENSSL_INCLUDE_DIR})
set(CRYPTO_LIBS ${OPENSSL_CRYPTO_LIBRARY} ${OPENSSL_SSL_LIBRARY})
ENDIF(USE_OPENSSL)

# GPGme
#pkg_check_modules(GPGME REQUIRED gpgme)
#pkg_check_modules(ASSUAN REQUIRED libassuan)
#pkg_check_modules(GPGerror REQUIRED gpg-error)
add_library(libgpgme_s STATIC IMPORTED)
add_library(libassuan_s STATIC IMPORTED)
add_library(libgpg-error_s STATIC IMPORTED)
SET_TARGET_PROPERTIES(libgpgme_s PROPERTIES IMPORTED_LOCATION "${CMAKE_HOME_DIRECTORY}/ext/${EXT_PATH}/lib/libgpgme.a")
SET_TARGET_PROPERTIES(libassuan_s PROPERTIES IMPORTED_LOCATION "${CMAKE_HOME_DIRECTORY}/ext/${EXT_PATH}/lib/libassuan.a")
SET_TARGET_PROPERTIES(libgpg-error_s PROPERTIES IMPORTED_LOCATION "${CMAKE_HOME_DIRECTORY}/ext/${EXT_PATH}/lib/libgpg-error.a")
set(GPG_LIBS "libgpgme_s" "libassuan_s" "libgpg-error_s")

# address sanitizer
IF(RUN_ADDRESS_SANITIZER)
IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
IF(CMAKE_CXX_COMPILER_ID MATCHES "AppleClang|Clang")
message("enabling address sanitizer on compiler ${CMAKE_CXX_COMPILER_ID}")
add_compile_options(-fsanitize=address)
add_link_options(-fsanitize=address)
ENDIF(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
ENDIF(${CMAKE_BUILD_TYPE} MATCHES "Debug")
ENDIF(RUN_ADDRESS_SANITIZER)


add_subdirectory( src/cpp )

if(NOT CMAKE_CROSSCOMPILING)
enable_testing()
add_subdirectory( test/cpp )
endif()
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,15 @@ base library that provides cryptographic functions to _elykseer_ implementations

```sh
cd build
cmake --fresh -DCMAKE_TOOLCHAIN_FILE=Toolchain_Darwin_to_Windows.cmake -DCMAKE_BUILD_TYPE=Release .
cmake --fresh -DCMAKE_TOOLCHAIN_FILE=Toolchain_Darwin_to_Windows.cmake -DCMAKE_BUILD_TYPE=Release -G Ninja ..
```

./test/cpp/utelykseer-crypto --show_progress
./test/cpp/utelykseer-crypto --log_level=unit_scope

# copyright

Copyright 2019-2024 by Alexander Diemand
Copyright 2019-2025 by Alexander Diemand

# license

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 1 addition & 11 deletions ext/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,9 @@ check_ranlib:
@[ -n "$(RANLIB)" ] && type $(RANLIB) 2> /dev/null


make_exts: makedirs make_gitalk make_libgpg_error make_libassuan make_gpgme make_cryptopp
make_exts: makedirs make_libgpg_error make_libassuan make_gpgme make_cryptopp
echo "all done."

fset_gitalk := $(TARGETDIR)/bin/html2text
make_gitalk: $(fset_gitalk)
$(fset_gitalk):
if [ -z "$(CROSS_COMPILATION)" ]; then \
echo "making gitalk"; \
cd ./gitalk; \
git submodule update --init; \
$(MAKE) -C ext; \
fi

fset_libgpg_error := $(TARGETDIR)/include/gpg-error.h $(TARGETDIR)/lib/libgpg-error.a
make_libgpg_error: $(fset_libgpg_error)
$(fset_libgpg_error):
Expand Down
9 changes: 0 additions & 9 deletions ext/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,9 @@ External Dependencies
the content of the 'ext/' directory:

cryptopp
gitalk/
sizebounded/


gitalk
======

license: BSD3

https://github.com/CodiePP/gitalk.git


sizebounded
===========

Expand Down
1 change: 0 additions & 1 deletion ext/gitalk
Submodule gitalk deleted from 9bd114
21 changes: 12 additions & 9 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,25 @@ stdenv.mkDerivation rec {
# Customizable development requirements
nativeBuildInputs = [
cmake
ninja
ccache
git
gnused
pandoc
html2text
gettext
texinfo
swig
gcc
#clang
#gcc
llvmPackages_19.openmp
lldb_19
clang_19
opam m4
#global
cppcheck
#busybox
perl534Packages.DigestSHA3
perl538Packages.DigestSHA3
pkg-config
autoconf automake libtool
libassuan libgpgerror
libassuan libgpg-error
gnupg
];

Expand All @@ -35,9 +39,8 @@ stdenv.mkDerivation rec {
shellHook = ''
echo 'eLyKseeR nixified environment'
export SED=sed
export CC=gcc
export CXX=g++
export CC=clang
export CXX=clang++
'';

}

Loading

0 comments on commit 44a29f5

Please sign in to comment.