rpmbuild spec CMake 創建項目的rpm 包,下面是項目的樹狀圖
.
├── cmake_fei
│ ├── build
│ ├── CMakeLists.txt
│ ├── libhello
│ │ ├── CMakeLists.txt
│ │ ├── hello.c
│ │ └── hello.h
│ ├── packaging
│ │ └── cmake_fei.spec
│ └── src
│ ├── CMakeLists.txt
│ └── main.c
└── packgfei.sh
最外面的CMakeLists.txt
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(HELLO)
MESSAGE(STATUS "This is project binary dir" ${HELLO_BINARY_DIR})
MESSAGE(STATUS "This is project source dir" ${HELLO_SOURCE_DIR})
MESSAGE(STATUS "This is cmake binary dir" ${CMAKE_BINARY_DIR})
MESSAGE(STATUS "This is cmake source dir" ${CMAKE_SOURCE_DIR})
ADD_SUBDIRECTORY(libhello)
ADD_SUBDIRECTORY(src)
libhello下面的CMakeLists.txt
SET(LIB_SRC hello.c)
ADD_DEFINITIONS("-DLIBHELLO_BUILD")
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
#dynamic library
ADD_LIBRARY(libhello SHARED ${LIB_SRC})
set_target_properties(libhello PROPERTIES OUTPUT_NAME "hello")
install(TARGETS libhello DESTINATION /usr/lib)
install(FILES ${CMAKE_SOURCE_DIR}/libhello/hello.h DESTINATION /usr/include/hello)
hello.c
/*************************************************************************
> File Name: hello.c
> Author: ma6174
> Mail: [email protected]
> Created Time: Mon 22 Dec 2014 01:11:57 PM HKT
************************************************************************/
#include <stdio.h>
#include "hello.h"
void hello(const char *name)
{
printf("hello %s \n", name);
}
hello.h
/*************************************************************************
> File Name: hello.h
> Author: ma6174
> Mail: [email protected]
> Created Time: Mon 22 Dec 2014 01:09:54 PM HKT
************************************************************************/
#ifndef CMAKE_FEI_HELLO_H
#define CMAKE_FEI_HELLO_H
#ifdef _WIN32
#if LIBHELLO_BUILD
#define LIBHELLO_API __declspec(dllexport)
#else
#define LIBHELLO_API __declspec(dllimport)
#endif
#else
#define LIBHELLO_API
#endif
LIBHELLO_API void hello(const char *name);
//static library is simple as normal c code.
#endif
src下面的CMakeLists.txt
include_directories(${PROJECT_SOURCE_DIR}/libhello)
SET(APP_SRC main.c)
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
ADD_EXECUTABLE(hello ${APP_SRC})
target_link_libraries(hello libhello)
install(TARGETS hello DESTINATION /usr/apps/com.mc.cmake_fei/bin)
main.c
#include <stdio.h>
#include <hello.h>
int main()
{
hello("hello world!");
return 0;
}
spec文件
#key word===========================================
Summary:This is first cmake spec package of xfei
Version:1.0
Name:cmake_fei
Release:1
Source:%{name}-%{version}.tar.gz
License:GPL
Packager:xfei
Group:Application
URL:www.baidu.com
#BuildArch: %{arm}
#spec main body======================================
%description
This is just a wonderful package
%prep
%setup -q
%build
cmake .
make %{?jobs:-j%jobs}
%install
rm -rf $RPM_BUILD_ROOT
echo $RPM_BUILD_ROOT
#RPM_BUILD_ROOT is virtual build dir, %file will start based on it.
echo $RPM_BUILD_DIR
echo %{buildroot}
%make_install
%post
%postun
#/sbin/ldconfig
%clean
rm -rf $RPM_BUILD_ROOT
make clean
#files will be started in RPM_BUILD_ROOT dir
%files
%defattr(-,root,root)
/usr/lib/libhello.so
/usr/include/hello/hello.h
/usr/apps/com.mc.cmake_fei/bin/*
/usr/apps/com.mc.cmake_fei/data/*
packgfei.sh
rm cmake_fei-1.0* -rf
cp cmake_fei cmake_fei-1.0 -r
tar zcvf cmake_fei-1.0.tar.gz cmake_fei-1.0
cp cmake_fei-1.0.tar.gz ~/rpmbuild/SOURCES/
rpmbuild -ba cmake_fei/packaging/cmake_fei.spec
rm cmake_fei-1.0* -rf
sudo rpm -Uvh ~/rpmbuild/RPMS/i386/cmake_fei-1.0-1.i386.rpm --force --nodeps
/usr/apps/com.mc.cmake_fei/bin/hello