Skip to content

Commit

Permalink
Tạo debian package cho môi trường Linux với CPack, đổi tên thư viện b…
Browse files Browse the repository at this point in the history
…kc thành bkcgen
  • Loading branch information
bangoc committed Sep 25, 2022
1 parent 8e93c1c commit 06bb19a
Show file tree
Hide file tree
Showing 38 changed files with 111 additions and 43 deletions.
61 changes: 54 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,30 @@ project(cgen)

# ON by default, use -DNOWARN=ON/OFF in Cmake command to turn ON/OFF
option(NOWARN "ON-No warnings, OFF-Tend to show all warnings" ON)
option(DEBUG "Debug build" ON)
option(BENCH_OP "Optimization (O1, O2, O3) benchmark" OFF)

include_directories(${CMAKE_CURRENT_SOURCE_DIR})

if (DEBUG)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
else (DEBUG)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2")
set(CMAKE_C_STANDARD 11)

if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug")
endif (NOT CMAKE_BUILD_TYPE)

if (${CMAKE_BUILD_TYPE} STREQUAL Debug)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Wall")
endif()

if (${CMAKE_BUILD_TYPE} STREQUAL Release)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 -w")
endif()

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-function")

if (WARN_ERROR)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
endif ()

if (NOWARN)
MESSAGE(STATUS "cgen no warnings")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w")
Expand All @@ -26,7 +39,7 @@ add_subdirectory(tests)
add_subdirectory(examples)
add_subdirectory(mega-unit)

add_library(bkc STATIC all.c)
add_library(bkcgen STATIC all.c)

include(CTest)
add_test(NAME BNLeftRotate COMMAND bn_left_rotate_ut)
Expand Down Expand Up @@ -152,4 +165,38 @@ add_test(NAME Q2M3Sort COMMAND q2m3sort_ut 10000)
add_test(NAME HeapSort COMMAND heapsort_ut 10000)
add_test(NAME GvecMemResize COMMAND gvec_mem_resize_ut)
add_test(NAME GvecFill COMMAND gvec_fill_ut)
add_test(NAME GvecCreateFull COMMAND gvec_create_full_ut)
add_test(NAME GvecCreateFull COMMAND gvec_create_full_ut)

if (${CMAKE_BUILD_TYPE} STREQUAL Release)
set(cgraph_include_dest "include")
set(cgraph_lib_dest "lib")
set(MERGE_CMD ${CMAKE_CURRENT_BINARY_DIR}/mega-unit/merge)
execute_process(COMMAND ${MERGE_CMD}
${CMAKE_CURRENT_SOURCE_DIR} all.h all.c bkcgen
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/bkcgen.h DESTINATION "${cgraph_include_dest}")
install(TARGETS bkcgen DESTINATION "${cgraph_lib_dest}")

set(CPACK_PACKAGE_INSTALL_DIRECTORY "/usr")
set(CPACK_GENERATOR "DEB")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Nguyễn Bá Ngọc")
set(CPACK_DEBIAN_PACKAGE_DESCRIPTION
"Thư viện cấu trúc dữ liệu và giải thuật khái quát.")
set(CMAKE_PROJECT_HOMEPAGE_URL "https://github.com/bangoc/cgen")
set(CPACK_DEBIAN_PACKAGE_PRIORITY "standard")
set(CPACK_DEBIAN_PACKAGE_SECTION "devel")

file (READ ${CMAKE_CURRENT_SOURCE_DIR}/VERSION CGEN_VERSION)

# Set a Package Version
set(CPACK_PACKAGE_VERSION "${CGEN_VERSION}")
include(CPack)

# To build a debian package
# cmake .. -DCMAKE_BUILD_TYPE=Release
# make -j 2
# make package
#
# To install the debian package
# sudo dpkg -i package.deb
endif()
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Tạo tệp CMakeLists.txt với các nội dung sau:
add_subdirectory(cgen)
include_directories(cgen)
add_executable(prog main.c)
target_link_libraries(prog bkc)
target_link_libraries(prog bkcgen)
```

Nên thực hiện biên dịch dự án trong một thư mục độc lập, ví dụ:
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.1
1.1.2
2 changes: 1 addition & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ add_executable(dll_songs dll_songs.c)
add_executable(gtype_demo_io gtype_demo_io.c)

foreach (p str_id s2i_pprint s2i_pprint_custom dll_songs)
target_link_libraries(${p} bkc)
target_link_libraries(${p} bkcgen)
endforeach()

add_subdirectory(benchmarks)
Expand Down
2 changes: 1 addition & 1 deletion examples/OOP/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ add_executable(SllG SllGDemo.c)
add_executable(SllStr SllStr.c)

foreach (p SllDemo SllG SllStr)
target_link_libraries(${p} bkc)
target_link_libraries(${p} bkcgen)
endforeach()
2 changes: 1 addition & 1 deletion examples/benchmarks/rb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
add_executable(b123 bench_123.c)
add_executable(b++123 bench_123.cc)

target_link_libraries(b123 bkc)
target_link_libraries(b123 bkcgen)

# Người dùng tự bổ xung thư mục libfdr để biên dịch nếu quan tâm
# có thể tài về ở địa chỉ https://github.com/bangoc/libfdr
Expand Down
2 changes: 1 addition & 1 deletion examples/benchmarks/sort/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
add_executable(bench_sort bench_sort.c)
target_link_libraries(bench_sort bkc)
target_link_libraries(bench_sort bkcgen)

if (BENCH_OP)
add_executable(generator generator.c)
Expand Down
21 changes: 21 additions & 0 deletions examples/deb/system_gvec_demo.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* (C) Nguyễn Bá Ngọc 2022 */

/** @file
* @brief Minh họa kịch bản sử dụng thư viện cgen sau khi cài như thư viện tiêu chuẩn.
* Có thể biên dịch chương trình với lệnh:
* gcc -o prog system_gvec_demo.c -lbkcgen
*/

#include <bkcgen.h>

#include <stdio.h>

int main() {
struct gvector *v = gvec_create(0, NULL);
gvec_append(v, gtype_l(1));
gvec_append(v, gtype_l(3));
gvec_append(v, gtype_l(5));
gvec_pprint(v, gtype_print_l);
gvec_free(v);
return 0;
}
2 changes: 1 addition & 1 deletion examples/gsl/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
add_executable(gsl_demo gsl_demo.c)

foreach (p gsl_demo)
target_link_libraries(${p} bkc)
target_link_libraries(${p} bkcgen)
endforeach()
2 changes: 1 addition & 1 deletion examples/gtype/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_executable(gtype_demo gtype_demo.c)
foreach (p gtype_demo)
target_link_libraries(${p} bkc)
target_link_libraries(${p} bkcgen)
endforeach()
2 changes: 1 addition & 1 deletion examples/gvec/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ add_executable(gvec_clear_demo gvec_clear_demo.c)

foreach (p gvec_demo gvec_i_demo gvec_s_demo gvec_pp_demo
gvec_clear_demo)
target_link_libraries(${p} bkc)
target_link_libraries(${p} bkcgen)
endforeach()
2 changes: 1 addition & 1 deletion examples/hfunc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
add_executable(hgen_demo hgen_demo.c)

target_link_libraries(hgen_demo bkc)
target_link_libraries(hgen_demo bkcgen)
2 changes: 1 addition & 1 deletion examples/hmap/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
add_executable(hmap_demo hmap_demo.c)
add_executable(hmap_clear_demo hmap_clear_demo.c)
foreach (p hmap_demo hmap_clear_demo)
target_link_libraries(${p} bkc)
target_link_libraries(${p} bkcgen)
endforeach()
2 changes: 1 addition & 1 deletion examples/hset/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ add_executable(hset_demo hset_demo.c)
add_executable(hset_clear_demo hset_clear_demo.c)

foreach (p hset_demo hset_clear_demo)
target_link_libraries(${p} bkc)
target_link_libraries(${p} bkcgen)
endforeach()
2 changes: 1 addition & 1 deletion examples/p1w/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ add_executable(p1wi_root p1wi_root.c)
add_executable(p1wi_clear_demo p1wi_clear_demo.c)

foreach (p p1wi_demo p1wi_root p1wi_clear_demo)
target_link_libraries(${p} bkc)
target_link_libraries(${p} bkcgen)
endforeach()
2 changes: 1 addition & 1 deletion examples/rbm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ add_executable(rbm_rgb_rand_demo rbm_rgb_rand_demo.c)
add_executable(rbm_tf_cf_demo rbm_tf_cf_demo.c)
add_executable(rbm_clear_demo rbm_clear_demo.c)
foreach (p rbm_si_demo rbm_rgb_rand_demo rbm_tf_cf_demo rbm_clear_demo)
target_link_libraries(${p} bkc)
target_link_libraries(${p} bkcgen)
endforeach()
2 changes: 1 addition & 1 deletion examples/rbs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
add_executable(rbs_demo rbs_demo.c)
add_executable(rbs_clear_demo rbs_clear_demo.c)
foreach (p rbs_demo rbs_clear_demo)
target_link_libraries(${p} bkc)
target_link_libraries(${p} bkcgen)
endforeach()
2 changes: 1 addition & 1 deletion mega-unit/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
add_executable(merge merge.c)
target_link_libraries(merge bkc)
target_link_libraries(merge bkcgen)
2 changes: 1 addition & 1 deletion tests/bn/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ foreach(p bn_most_ut bn_transplant_ut
bn_foreach_ut bn_similar_tree_ut
bn_edge_height_ut
bn_insert_ut)
target_link_libraries(${p} bkc)
target_link_libraries(${p} bkcgen)
endforeach()
2 changes: 1 addition & 1 deletion tests/bs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ add_executable(bs_search_lte_gte_g_ut bs_search_lte_gte_g_ut.c)
foreach (p bs_search_ut bs_search_lte_ut bs_search_gte_ut
bs_search_lte_gte_1k_ut bs_gtype_i_ut
bs_search_lte_gte_g_ut)
target_link_libraries(${p} bkc)
target_link_libraries(${p} bkcgen)
endforeach()
2 changes: 1 addition & 1 deletion tests/dll/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ add_executable(dll_int_ut dll_int_ut.c)
add_executable(dll_gtype_ut dll_gtype_ut.c)

foreach (p dll_generic_ut dll_int_ut dll_gtype_ut)
target_link_libraries(${p} bkc)
target_link_libraries(${p} bkcgen)
endforeach()
2 changes: 1 addition & 1 deletion tests/gsl/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_executable(gsl_inserta_ut gsl_inserta_ut.c)
foreach (p gsl_inserta_ut)
target_link_libraries(${p} bkc)
target_link_libraries(${p} bkcgen)
endforeach()
2 changes: 1 addition & 1 deletion tests/gttreemap/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
add_executable(gt_treemap_ut gt_treemap_ut.c)

foreach(p gt_treemap_ut)
target_link_libraries(${p} bkc)
target_link_libraries(${p} bkcgen)
endforeach()
2 changes: 1 addition & 1 deletion tests/gvec/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ add_executable(gvec_create_full_ut gvec_create_full_ut.c)
foreach (p gvec_ut gvec_v_ut gvec_selsort_ut gvec_insort_ut
gvec_bubsort_ut gvec_mem_resize_ut gvec_fill_ut
gvec_create_full_ut)
target_link_libraries(${p} bkc)
target_link_libraries(${p} bkcgen)
endforeach()
2 changes: 1 addition & 1 deletion tests/hmap/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ add_executable(hmap_hmap_ut hmap_hmap_ut.c)
add_executable(hmap_put_si_ut hmap_put_si_ut.c)
foreach (p hmap_small_ut hmap_nnode_ut hmap_randi_ut hmap_free0_ut
hmap_gvec_ut hmap_hmap_ut hmap_put_si_ut)
target_link_libraries(${p} bkc)
target_link_libraries(${p} bkcgen)
endforeach()
2 changes: 1 addition & 1 deletion tests/hset/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
add_executable(hset_ut hset_ut.c)
add_executable(hset_rand_ut hset_rand_ut.c)
foreach(p hset_ut hset_rand_ut)
target_link_libraries(${p} bkc)
target_link_libraries(${p} bkcgen)
endforeach()
2 changes: 1 addition & 1 deletion tests/p1w/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
add_executable(p1w_ut p1w_ut.c)

foreach (p p1w_ut)
target_link_libraries(${p} bkc)
target_link_libraries(${p} bkcgen)
endforeach()
2 changes: 1 addition & 1 deletion tests/p2w/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
add_executable(d2wheap_ut d2wheap_ut.c)
add_executable(gtp2wheap_ut gtp2wheap_ut.c)
foreach(p d2wheap_ut gtp2wheap_ut)
target_link_libraries(${p} bkc)
target_link_libraries(${p} bkcgen)
endforeach()
2 changes: 1 addition & 1 deletion tests/que/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_executable(que_simple_ut que_simple_ut.c)
foreach (p que_simple_ut)
target_link_libraries(${p} bkc)
target_link_libraries(${p} bkcgen)
endforeach()
2 changes: 1 addition & 1 deletion tests/rb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ foreach (p bn_left_rotate_ut rb_insert_delete_ut rb_build_ut
rb_delete_ut rb_delete_similar_ut rb_is_valid_ut
rb_insert_delete_1k_ut rb_rand_insert_delete_ut
rb_insert_delete_duplicates_ut)
target_link_libraries(${p} bkc)
target_link_libraries(${p} bkcgen)
endforeach()
2 changes: 1 addition & 1 deletion tests/rbm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ add_executable(rbm_hmap_ut rbm_hmap_ut.c)
add_executable(rbm_put_si_ut rbm_put_si_ut.c)

foreach (p rbm_rand_i_ut rbm_gvec_ut rbm_hmap_ut rbm_put_si_ut)
target_link_libraries(${p} bkc)
target_link_libraries(${p} bkcgen)
endforeach()
2 changes: 1 addition & 1 deletion tests/rbs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ add_executable(rbs_str_ut rbs_str_ut.c)
add_executable(rbs_rand_ut rbs_rand_ut.c)

foreach (p rbs_i_ut rbs_str_ut rbs_rand_ut)
target_link_libraries(${p} bkc)
target_link_libraries(${p} bkcgen)
endforeach()
2 changes: 1 addition & 1 deletion tests/s2i/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ add_executable(s2i_insert_dup_ut s2i_insert_dup_ut.c)
add_executable(s2i_set_dup_ut s2i_set_dup_ut.c)

foreach(p s2i_ut s2i_ut2 s2i_insert_dup_ut s2i_set_dup_ut)
target_link_libraries(${p} bkc)
target_link_libraries(${p} bkcgen)
endforeach()
2 changes: 1 addition & 1 deletion tests/s2w/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_executable(s2w_ut s2w_ut.c)
foreach (p s2w_ut)
target_link_libraries(${p} bkc)
target_link_libraries(${p} bkcgen)
endforeach()
2 changes: 1 addition & 1 deletion tests/sll/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ add_executable(sll_l_queue_ut sll_l_queue_ut.c)
add_executable(sll_l_stack_ut sll_l_stack_ut.c)

foreach (p sll_ut sll_g_ut sll_l_queue_ut sll_l_stack_ut)
target_link_libraries(${p} bkc)
target_link_libraries(${p} bkcgen)
endforeach()
2 changes: 1 addition & 1 deletion tests/sort/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ add_executable(heapsort_ut heapsort_ut.c)

foreach (p q2sort_ut q2m3sort_ut q3sort_ut quicksort_ut
sort_all_identical_ut heapsort_ut)
target_link_libraries(${p} bkc)
target_link_libraries(${p} bkcgen)
endforeach()
2 changes: 1 addition & 1 deletion tests/stk/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_executable(stk_simple_ut stk_simple_ut.c)
foreach (p stk_simple_ut)
target_link_libraries(${p} bkc)
target_link_libraries(${p} bkcgen)
endforeach()
2 changes: 1 addition & 1 deletion tests/str/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
add_executable(spaces_ut spaces_ut.c)
add_executable(split_ut split_ut.c)
foreach (p spaces_ut split_ut)
target_link_libraries(${p} bkc)
target_link_libraries(${p} bkcgen)
endforeach()

0 comments on commit 06bb19a

Please sign in to comment.