Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP - Handle sources as a library + cli app #18

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,25 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: make
run: make
- name: test
run: ./test_unishox2 -t

- name: Configure Project
run: |
cmake --version
mkdir buildRelease && cd buildRelease
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=install ..

- name: Compile project
run: |
cd buildRelease
cmake --build .

- name: Install library
run: |
cd buildRelease
cmake --build . --target install
tree install

- name: Test with CLI app
run: |
cd buildRelease
./unishox_cli -t
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,9 @@ delta_only

# Traditional cmake building directories
build*

# QtCreator temporary files
CMakeLists.txt.user

# Vim temporary files
*.swp
51 changes: 48 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,61 @@
cmake_minimum_required(VERSION 3.20)
cmake_minimum_required(VERSION 3.15)
cmake_policy(SET CMP0092 NEW)

project(Unixshox
LANGUAGES C
VERSION 2.0.0
)

include(GNUInstallDirs)
include(WriteBasicConfigVersionFile)
include(CMakePackageConfigHelpers)
include(GenerateExportHeader)

include(cmake/compilerFlags.cmake REQUIRED)

add_executable(unishox
unishox2.c
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)

include_directories(${CMAKE_BINARY_DIR})

add_library(unishox
unishox2.h
unishox2.c
)

generate_export_header(unishox)

# --------------------------------------------------------------------
# Install rules for C library
# --------------------------------------------------------------------
# Use include/unishox to build libary code
target_include_directories(unishox PUBLIC
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

write_basic_package_version_file(unishoxConfigVersion.cmake COMPATIBILITY ExactVersion)

install(TARGETS unishox EXPORT unishoxConfig
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/unishox/
)

install(FILES ${PROJECT_BINARY_DIR}/unishox_export.h unishox2.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/unishox)

install(EXPORT unishoxConfig DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/unishox")

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/unishoxConfigVersion.cmake DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/unishox")

# --------------------------------------------------------------------
# Test CLI application
# --------------------------------------------------------------------

add_executable(unishox_cli
test_unishox2.c
)
target_link_libraries(unishox_cli PRIVATE unishox)

include(cmake/summary.cmake REQUIRED)
1 change: 1 addition & 0 deletions cmake/compilerFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ if (COMPILER_IS_GCC OR COMPILER_IS_CLANG)
add_compile_options(-Werror)
add_compile_options(-Wall -Wcast-align -Wpointer-arith -Wformat-security -Wmissing-format-attribute -W)
add_compile_options(-Wno-error=format-nonliteral)
add_compile_options(-Wno-error=stringop-truncation)

check_c_compiler_flag(-Wdeprecated-copy DEPRECATED_COPY)
if ( DEPRECATED_COPY)
Expand Down
6 changes: 3 additions & 3 deletions cmake/summary.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ message( STATUS "---------------------------------------------------------------
message( STATUS "CMake Generator: ${CMAKE_GENERATOR}" )
message( STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}" )
message( STATUS "Compiler info: ${CMAKE_C_COMPILER_ID} (${CMAKE_C_COMPILER}) ; version: ${CMAKE_C_COMPILER_VERSION}")
message( STATUS "CMAKE_C_STANDARD:${CMAKE_C_STANDARD}" )
message( STATUS "CMAKE_C_STANDARD: ${CMAKE_C_STANDARD}" )
message( STATUS " --- Compiler flags --- ")
message( STATUS "General: ${CMAKE_C_FLAGS}" )
message( STATUS "Extra: ${EXTRA_COMPILE_FLAGS}" )
Expand All @@ -18,6 +18,6 @@ message( STATUS "Release: ${CMAKE_EXE_LINKER_FLAGS_RELEASE}" )
message( STATUS "RelWithDebInfo: ${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO}" )
message( STATUS "MinSizeRel: ${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL}" )
message( STATUS "" )
message( STATUS "Compiler Options")
message( STATUS "" )
message( STATUS "CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}" )
message( STATUS "BUILD_SHARED_LIBS: ${BUILD_SHARED_LIBS}" )
message( STATUS "------------------------------------------------------------------" )
18 changes: 10 additions & 8 deletions unishox2.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#ifndef unishox2
#define unishox2

#include "unishox_export.h"

#define UNISHOX_VERSION "2.0"

//enum {USX_ALPHA = 0, USX_SYM, USX_NUM, USX_DICT, USX_DELTA};
Expand Down Expand Up @@ -88,19 +90,19 @@ struct us_lnk_lst {
struct us_lnk_lst *previous;
};

extern int unishox2_compress_simple(const char *in, int len, char *out);
extern int unishox2_decompress_simple(const char *in, int len, char *out);
extern int unishox2_compress(const char *in, int len, char *out,
const unsigned char usx_hcodes[], const unsigned char usx_hcode_lens[],
UNISHOX_EXPORT int unishox2_compress_simple(const char *in, int len, char *out);
UNISHOX_EXPORT int unishox2_decompress_simple(const char *in, int len, char *out);
UNISHOX_EXPORT int unishox2_compress(const char *in, int len, char *out,
const unsigned char usx_hcodes[], const unsigned char usx_hcode_lens[],
const char *usx_freq_seq[], const char *usx_templates[]);
extern int unishox2_decompress(const char *in, int len, char *out,
UNISHOX_EXPORT int unishox2_decompress(const char *in, int len, char *out,
const unsigned char usx_hcodes[], const unsigned char usx_hcode_lens[],
const char *usx_freq_seq[], const char *usx_templates[]);
extern int unishox2_compress_lines(const char *in, int len, char *out,
const unsigned char usx_hcodes[], const unsigned char usx_hcode_lens[],
UNISHOX_EXPORT int unishox2_compress_lines(const char *in, int len, char *out,
const unsigned char usx_hcodes[], const unsigned char usx_hcode_lens[],
const char *usx_freq_seq[], const char *usx_templates[],
struct us_lnk_lst *prev_lines);
extern int unishox2_decompress_lines(const char *in, int len, char *out,
UNISHOX_EXPORT int unishox2_decompress_lines(const char *in, int len, char *out,
const unsigned char usx_hcodes[], const unsigned char usx_hcode_lens[],
const char *usx_freq_seq[], const char *usx_templates[],
struct us_lnk_lst *prev_lines);
Expand Down