Skip to content

Commit

Permalink
Merge pull request #3 from TytanRock/Github-Actions-Dev
Browse files Browse the repository at this point in the history
Github Actions now produces a deb file that the user can apt install on
  • Loading branch information
TytanRock committed Aug 18, 2020
2 parents c067d97 + 2d68b1f commit 8cc2a7e
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 18 deletions.
18 changes: 12 additions & 6 deletions .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
branches: [ master ]

jobs:
# Build the project and ensure it compiles
build:

runs-on: ubuntu-latest
Expand All @@ -15,9 +16,14 @@ jobs:
- uses: actions/checkout@v2
- name: configure
run: ./configure
- name: make
run: ./build.sh
# - name: make check
# run: make check
# - name: make distcheck
# run: make distcheck
- name: 'build and package'
run: ./package.sh

# Once the project is built, upload the deb package
- name: upload
uses: actions/upload-artifact@v2
with:
name: PenguinTuner
path: build/PenguinTuner*.deb


63 changes: 56 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
# Specify minimum required version of CMake
cmake_minimum_required (VERSION 2.8.11 )
cmake_minimum_required (VERSION 3.0 )

file(READ "version.txt" ver)
string(REGEX MATCH "VERSION_MAJOR ([0-9]*)" _ ${ver})
set(major ${CMAKE_MATCH_1})
string(REGEX MATCH "VERSION_MINOR ([0-9]*)" _ ${ver})
set(minor ${CMAKE_MATCH_1})
string(REGEX MATCH "VERSION_PATCH ([0-9]*)" _ ${ver})
set(patch ${CMAKE_MATCH_1})

# Project name
project (PenguinTuner C)
project (PenguinTuner LANGUAGES C VERSION "${major}.${minor}.${patch}")


message("version: ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")

find_package(PkgConfig REQUIRED)
find_package(CURL REQUIRED)
pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
include_directories(${GTK3_INCLUDE_DIRS})
link_directories(${GTK3_LIBRARY_DIRS})

add_library(Penguin_Backend SHARED IMPORTED)
set_property(TARGET Penguin_Backend PROPERTY IMPORTED_LOCATION "${CMAKE_SOURCE_DIR}/backend/lib/libPenguin_Backend.so")

add_definitions(${GTK3_CFLAGS_OTHER})

Expand All @@ -18,13 +31,49 @@ aux_source_directory (native/src SOURCE_FILES)
# Specify include directory
include_directories (native/include INCLUDE_DIR)
include_directories (backend/headers INCLUDE_DIR)
link_directories (backend/lib)

# Creates C resources file from files in given directory
function(create_resources dir output)
# Create empty output file
file(WRITE ${output} "")
# Collect input files
file(GLOB bins ${dir}/*)
# Iterate through input files
foreach(bin ${bins})
# Get short filename
string(REGEX MATCH "([^/]+)$" filename ${bin})
# Replace filename spaces & extension separator for C compatibility
string(REGEX REPLACE "\\.| |-" "_" filename ${filename})
# Read hex data from file
file(READ ${bin} filedata HEX)
# Convert hex data for C compatibility
string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1," filedata ${filedata})
# Append data to output file
file(APPEND ${output} "const unsigned char ${filename}[] = {${filedata}};\nconst unsigned ${filename}_size = sizeof(${filename});\n")
endforeach()
endfunction()

create_resources(${CMAKE_SOURCE_DIR}/config ${CMAKE_CURRENT_BINARY_DIR}/resources.c)

# Add source files to executable
add_executable(${PROJECT_NAME} ${SOURCE_FILES} ${INCLUDE_DIR})
add_executable(${PROJECT_NAME} ${SOURCE_FILES} ${CMAKE_CURRENT_BINARY_DIR}/resources.c ${INCLUDE_DIR})

add_custom_command(TARGET ${PROJECT_NAME} PRE_BUILD COMMAND cp ${CMAKE_SOURCE_DIR}/config/MainApp.ui .)
add_custom_command(TARGET ${PROJECT_NAME} PRE_BUILD COMMAND objcopy --input binary --output elf32-i386 --binary-architecture i386 MainApp.ui ${CMAKE_CURRENT_BINARY_DIR}/MainApp.o)

# Copy config files for styling the widgets
add_custom_command(TARGET ${PROJECT_NAME} PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/config/ $<TARGET_FILE_DIR:${PROJECT_NAME}>)
target_link_libraries(${PROJECT_NAME} ${GTK3_LIBRARIES})
target_link_libraries(${PROJECT_NAME} Penguin_Backend.so)
target_link_libraries(${PROJECT_NAME} "${CMAKE_SOURCE_DIR}/backend/lib/libPenguin_Backend.so")
target_link_libraries(${PROJECT_NAME} ${CURL_LIBRARIES})

install(TARGETS PenguinTuner
DESTINATION bin
)
install(FILES "${CMAKE_SOURCE_DIR}/backend/lib/libPenguin_Backend.so"
DESTINATION lib
)

set(CPACK_GENERATOR "DEB")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "TytanRock")
include(CPack)

2 changes: 1 addition & 1 deletion native/include/app_callbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Connect all signals from the UI xml file specified
* Returns: 0 if success, nonzero otherwise
*/
int connect_all_signals(const char *ui_filename);
int connect_all_signals();

void frontend_callback(backend_error err, const backend_action *action);
void frontend_update_firm_status(double status, int stillUpgrading);
Expand Down
8 changes: 5 additions & 3 deletions native/src/app_callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,19 @@ void frontend_update_firm_status(double status, int stillUpgrading)
_module.firm_upgrade_status = status;
}

int connect_all_signals(const char *ui_filename)
extern char MainApp_ui[];
extern unsigned MainApp_ui_size;
int connect_all_signals()
{
GtkApplication *app;
GtkBuilder *builder;
GObject *obj;

/* Parse UI file generated by glade */
if((builder = gtk_builder_new_from_file(ui_filename)) == NULL)
if((builder = gtk_builder_new_from_string(MainApp_ui, MainApp_ui_size)) == NULL)
{
/* If parse failed, it will return NULL, let user know */
g_printerr("Error loading xml file: %s\n", ui_filename);
g_printerr("Error loading xml file\n");
return -1;
}
/* Start backend server */
Expand Down
2 changes: 1 addition & 1 deletion native/src/application.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ int main(int argc, char **argv) {

gtk_init(&argc, &argv);

connect_all_signals("MainApp.ui");
connect_all_signals();

gtk_main();

Expand Down
6 changes: 6 additions & 0 deletions package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

./build.sh
cd build
cpack

4 changes: 4 additions & 0 deletions version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
VERSION_MAJOR 0
VERSION_MINOR 1
VERSION_PATCH 0

0 comments on commit 8cc2a7e

Please sign in to comment.