From 4ecb70100a0239d5c58c4a8559d53c5be8b3b055 Mon Sep 17 00:00:00 2001 From: Youngjae Shin Date: Thu, 30 Jul 2020 14:03:49 +0900 Subject: [PATCH] revise build scripts and packaging Change-Id: Idb4394bb0c2c079b9622af0647158c4cf6d8a7b0 --- CMakeLists.txt | 63 +++++++++++-------------------- db-util.pc.in | 12 ++---- packaging/libslp-db-util.spec | 88 +++++++++++++++++++------------------------ tests/CMakeLists.txt | 27 +++---------- tests/run_coverage.sh | 38 ------------------- 5 files changed, 70 insertions(+), 158 deletions(-) delete mode 100755 tests/run_coverage.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 75a92ab..f12f9e1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,56 +1,37 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -PROJECT(SLP-db-util) +PROJECT(db-util) -SET(PREFIX ${CMAKE_INSTALL_PREFIX}) -SET(EXEC_PREFIX "\${prefix}") -SET(INCLUDEDIR "\${prefix}/include/db-util") -SET(VERSION_MAJOR 0) -SET(VERSION "${VERSION_MAJOR}.1.0") +SET(EXTRA_FLAGS "-Wall -Werror -fvisibility=hidden") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_FLAGS}") +SET(LIB_NAME "SLP-db-util") SET(SRCS src/util-func.c src/collation.c) -INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include) - INCLUDE(FindPkgConfig) -pkg_check_modules(pkgs REQUIRED - sqlite3 - dlog - glib-2.0 - icu-i18n - vconf -) - -FOREACH(flag ${pkgs_CFLAGS}) - SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") -ENDFOREACH(flag) - -SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -ldl -g") - -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") +pkg_check_modules(pkgs REQUIRED sqlite3 dlog glib-2.0 icu-i18n vconf) +INCLUDE_DIRECTORIES(${pkgs_INCLUDE_DIRS}) +LINK_DIRECTORIES(${pkgs_LIBRARY_DIRS}) +INCLUDE_DIRECTORIES(include) ADD_DEFINITIONS("-DLIB_DIR=\"${LIB_INSTALL_DIR}\"") -ADD_DEFINITIONS("-DPREFIX=\"${PREFIX}\"") -ADD_DEFINITIONS("-DFACTORYFS=\"$ENV{FACTORYFS}\"") -IF(NOT DEFINED GCOV ) -ADD_DEFINITIONS("-DDB_UTIL_USING_PLATFORM_DBG") -ENDIF() ADD_DEFINITIONS("-DDB_UTIL_ENABLE_TRACE") ##ADD_DEFINITIONS("-DDB_UTIL_ENABLE_DEVDEBUG") +IF(NOT BUILD_GCOV) + ADD_DEFINITIONS("-DDB_UTIL_USING_PLATFORM_DBG") +ENDIF() -ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} -ldl) -SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION ${VERSION_MAJOR}) -SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${VERSION}) +ADD_LIBRARY(${LIB_NAME} SHARED ${SRCS}) +TARGET_LINK_LIBRARIES(${LIB_NAME} ${pkgs_LIBRARIES} dl) +TARGET_COMPILE_OPTIONS(${LIB_NAME} PUBLIC ${pkgs_CFLAGS_OTHER}) +SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES VERSION ${FULLVER} SOVERSION ${MAJORVER}) +INSTALL(TARGETS ${LIB_NAME} DESTINATION ${LIB_INSTALL_DIR}) -CONFIGURE_FILE(db-util.pc.in db-util.pc @ONLY) +CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) +INSTALL(FILES ${PROJECT_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) -INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) -INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/db-util.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/db-util.h DESTINATION include/db-util) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/db-util-common.h DESTINATION include/db-util) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/util-func.h DESTINATION include/db-util) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/collation.h DESTINATION include/db-util) +FILE(GLOB HEADERS include/*.h) +INSTALL(FILES ${HEADERS} DESTINATION ${INCLUDE_INSTALL_DIR}/${PROJECT_NAME}) -IF( DEFINED GCOV ) -ADD_SUBDIRECTORY(tests) +IF(BUILD_GCOV) + ADD_SUBDIRECTORY(tests) ENDIF() diff --git a/db-util.pc.in b/db-util.pc.in index a1df72b..b884427 100644 --- a/db-util.pc.in +++ b/db-util.pc.in @@ -1,13 +1,9 @@ -# Package Information for pkg-config - -prefix=@PREFIX@ -exec_prefix=@EXEC_PREFIX@ libdir=@LIB_INSTALL_DIR@ -includedir=@INCLUDEDIR@ +includedir=@INCLUDE_INSTALL_DIR@/@PROJECT_NAME@ -Name: db-util +Name: @PROJECT_NAME@ Description: DB Utility -Version: @VERSION@ +Version: @FULLVER@ Requires: sqlite3 dlog glib-2.0 icu-i18n -Libs: -L${libdir} -lSLP-db-util +Libs: -L${libdir} -l@LIB_NAME@ Cflags: -I${includedir} diff --git a/packaging/libslp-db-util.spec b/packaging/libslp-db-util.spec index 27d34ca..1e09c95 100644 --- a/packaging/libslp-db-util.spec +++ b/packaging/libslp-db-util.spec @@ -1,36 +1,37 @@ -Name: libslp-db-util -Version: 0.1.1 -Release: 6 -License: Apache-2.0 -Summary: DB Utility -Group: Application Framework/Database -Source0: %{name}-%{version}.tar.gz +Name: libslp-db-util +Version: 0.1.2 +Release: 0 +License: Apache-2.0 +Summary: DB Utility +Group: Application Framework/Database +Source0: %{name}-%{version}.tar.gz Source1001: %{name}.manifest -BuildRequires: cmake -BuildRequires: pkgconfig(dlog) -BuildRequires: pkgconfig(glib-2.0) -BuildRequires: pkgconfig(icu-i18n) -BuildRequires: pkgconfig(sqlite3) -BuildRequires: pkgconfig(vconf) +BuildRequires: cmake +BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(glib-2.0) +BuildRequires: pkgconfig(icu-i18n) +BuildRequires: pkgconfig(sqlite3) +BuildRequires: pkgconfig(vconf) %if 0%{?gcov:1} -BuildRequires: gtest-devel -BuildRequires: lcov +BuildRequires: gtest-devel +BuildRequires: lcov +BuildRequires: tar %endif %description DB Utility. %package devel -Summary: Devel package for libslp-db-util (devel) -Requires: %{name} = %{version} +Summary: Devel package for libslp-db-util (devel) +Requires: %{name} = %{version} %description devel Devel package for libslp-db-util (devel) %if 0%{?gcov:1} %package gcov -Summary: DB Utility(gcov) -Group: Application Framework/Database +Summary: DB Utility(gcov) +Group: Application Framework/Database %description gcov libslp-db-util gcov objects %endif @@ -40,42 +41,35 @@ libslp-db-util gcov objects cp %{SOURCE1001} ./%{name}.manifest %build - -%ifarch aarch64 x86_64 -export CFLAGS+=" $CFLAGS -DDB_UTIL_ARCH_64 " -export CXXFLAGS+=" $CXXFLAGS -DDB_UTIL_ARCH_64 " -export FFLAGS+=" $FFLAGS -DDB_UTIL_ARCH_64 " -%endif - %if 0%{?gcov:1} -export CFLAGS+=" -O0 -fprofile-arcs -ftest-coverage" -export CXXFLAGS+=" -O0 -fprofile-arcs -ftest-coverage" -%define CMAKE_GCOV -DGCOV=1 -%else -%define CMAKE_GCOV %{nil} +export CFLAGS+=" -fprofile-arcs -ftest-coverage" +export CXXFLAGS+=" -fprofile-arcs -ftest-coverage" +export LDFLAGS+=" -lgcov" %endif -%cmake . %{CMAKE_GCOV} +MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` +%cmake . -DMAJORVER=${MAJORVER} -DFULLVER=%{version} \ + -DCMAKE_VERBOSE_MAKEFILE=OFF \ + -DBUILD_GCOV=%{?gcov:1}%{!?gcov:0} make %{?_smp_mflags} -%if 0%{?gcov:1} -mkdir -p gcov-obj -find . -name '*.gcno' -exec cp '{}' gcov-obj ';' -%endif - %install %make_install %if 0%{?gcov:1} -mkdir -p %{buildroot}%{_datadir}/gcov/obj -install -m 0644 gcov-obj/* %{buildroot}%{_datadir}/gcov/obj +find .. -name '*.gcno' | tar cf %{name}-gcov.tar -T - +install -d -m 755 %{buildroot}%{_datadir}/gcov/obj +tar xf %{name}-gcov.tar -C %{buildroot}%{_datadir}/gcov/obj %endif %check %if 0%{?gcov:1} pushd tests -./run_coverage.sh +./test-collation-db.sh +LD_PRELOAD=./libvconf-mock.so LD_LIBRARY_PATH=.. ./db-util-gtest popd +lcov -c --ignore-errors graph --no-external -b . -d . -o %{name}.info +genhtml %{name}.info -o out --legend --show-details %endif %post -p /sbin/ldconfig @@ -84,21 +78,15 @@ popd %files %manifest %{name}.manifest +%{_libdir}/libSLP-db-util.so.* %license LICENSE.APLv2 -%defattr(-,root,root,-) -%{_libdir}/libSLP-db-util.so.0 -%{_libdir}/libSLP-db-util.so.0.1.0 %files devel -%defattr(-,root,root,-) -%dir %{_includedir}/db-util -%{_includedir}/db-util/*.h -%{_libdir}/pkgconfig/db-util.pc %{_libdir}/libSLP-db-util.so - +%{_libdir}/pkgconfig/db-util.pc +%{_includedir}/db-util/*.h %if 0%{?gcov:1} %files gcov -%defattr(-,root,root,-) -%{_datadir}/gcov/obj/* +%{_datadir}/gcov/* %endif diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 592da0d..069079e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,26 +1,11 @@ -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIE") -SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIE") - - -INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include) -INCLUDE_DIRECTORIES(/usr/include/vconf) - -pkg_check_modules(gtest_pkgs REQUIRED sqlite3 dlog glib-2.0 icu-i18n vconf) -INCLUDE_DIRECTORIES(${gtest_pkgs_INCLUDE_DIRS}) -LINK_DIRECTORIES(${gtest_pkgs_LIBRARY_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}) +SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie") #=======================================================================================# SET(VCONF_MOCK "vconf-mock") -SET(VCONF_MOCK_SRCS vconf.c ) -SET(VCONF_MOCK_CFLAGS "${CMAKE_C_FLAGS}") -ADD_LIBRARY(${VCONF_MOCK} SHARED ${VCONF_MOCK_SRCS}) -SET_TARGET_PROPERTIES(${VCONF_MOCK} PROPERTIES - COMPILE_FLAGS ${VCONF_MOCK_CFLAGS} -) -TARGET_LINK_LIBRARIES(${VCONF_MOCK} ${gtest_pkgs_LIBRARIES} -ldl) +ADD_LIBRARY(${VCONF_MOCK} SHARED vconf.c) #=======================================================================================# -SET(DB-UTIL_GTEST "db-util-gtest") -SET(DB-UTIL_GTEST_SRCS db-util-gtest.cpp) -ADD_EXECUTABLE(${DB-UTIL_GTEST} ${DB-UTIL_GTEST_SRCS}) -TARGET_LINK_LIBRARIES(${DB-UTIL_GTEST} ${gtest_pkgs_LIBRARIES} pthread gtest SLP-db-util ) +SET(DB_UTIL_GTEST "db-util-gtest") +ADD_EXECUTABLE(${DB_UTIL_GTEST} db-util-gtest.cpp) +SET_TARGET_PROPERTIES(${DB_UTIL_GTEST} PROPERTIES POSITION_INDEPENDENT_CODE ON) +TARGET_LINK_LIBRARIES(${DB_UTIL_GTEST} ${LIB_NAME} gtest) #=======================================================================================# diff --git a/tests/run_coverage.sh b/tests/run_coverage.sh deleted file mode 100755 index f93918f..0000000 --- a/tests/run_coverage.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/bash -pushd ../ -RootDir=$PWD -popd - -# Create vconf keys -# if [ -x "/usr/bin/buxton2ctl" ] -# then -# /usr/bin/buxton2ctl -i -d create-string "system" "db/menu_widget/language" "en_US.UTF-8" "http://tizen.org/privilege/internal/default/public" "http://tizen.org/privilege/systemsettings.admin" -# fi - -unitTestFile=db-util-gtest -if [ ! -x "./$unitTestFile" ] -then - echo "$unitTestFile file does not exist!" - exit -1 -fi - -LD_LIBRARY_PATH=../:$LD_LIBRARY_PATH LD_PRELOAD=./libvconf-mock.so ./$unitTestFile - -CMakeDir=${RootDir}/CMakeFiles/SLP-db-util.dir -CoverageDir=${RootDir}/coverage - -pushd $CMakeDir - for obj in `ls *.o` - do - gcov -b -c $obj - done - - if [ -f /usr/bin/lcov ] - then - lcov -c -d . -o cov.info - genhtml cov.info -o ${CoverageDir} - echo "Coverage test result created! [${CoverageDir}]" - else - echo "lcov does not exist!" - fi -popd -- 2.7.4