2014년 6월 27일 금요일

CMakeLists.txt for JsonCpp 0.6.0-rc2

C++ 환경에서 잘 쓰고 있는 JsonCpp인데, 2011년 5월 2일 0.6.0-rc2가 마지막 버전인 것이 함정.


암튼 SCons라는 처음 보는 빌드툴을 사용하는데, RPM/DEB 같은 패키징을 지원하는 것 같은데 0.6.0-rc2 빌드 스크립트에는 없는 것 같다. SCons 이용해서 해보려고 했지만, 생소하고 굳이 이걸 할 필요가 있을까...해서 CMakeLists.txt로 만들어 보았다.

CMakeLists.txt for JsonCpp 0.6.0-rc2
# CMakeLists.txt script for jsoncpp-0.6.0-rc2                                                                                                                                             
# Author: Yubin Lim (purewell@purewell.biz)
# JsonCpp Author: Baptiste Lepilleur <blep@users.sourceforge.net>

cmake_minimum_required(VERSION 2.8)
project(jsoncpp CXX)

set(TARGET ${PROJECT_NAME})
set(CMAKE_USE_RELATIVE_PATHS true)
include(GNUInstallDirs)

set(PKGCONFIG_CONF_PATH "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
set(CMAKE_INSTALL_PREFIX "/usr")

set(CPACK_PACKAGE_NAME ${PROJECT_NAME})
set(CPACK_PACKAGE_VENDOR "Baptiste Lepilleur")
set(CPACK_PACKAGE_CONTACT "blep@users.sourceforge.net")
set(CPACK_PACKAGE_VERSION_MAJOR 0)
set(CPACK_PACKAGE_VERSION_MINOR 6)
set(CPACK_PACKAGE_VERSION_PATCH 0)
set(CPACK_PACKAGE_VERSION_RELEASE rc2)
set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}-${CPACK_PACKAGE_VERSION_RELEASE}")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "JSONCPP")
#set(CPACK_PACKAGE_DESCRIPTION_FILE "${PROJECT_SOURCE_DIR}/DESCRIPTION.txt")
set(CPACK_GENERATOR RPM;DEB)
set(CPACK_RPM_PACKAGE_DEBUG false)
set(CPACK_RPM_PACKAGE_URL "http://jsoncpp.sourceforge.net/")
set(CPACK_RPM_PACKAGE_LICENSE ./LICENSE)
#set(CPACK_RPM_PACKAGE_REQUIRES "zlib-devel, openssl-devel")                                                                  
set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "/usr/${PKGCONFIG_CONF_PATH}")
set(CPACK_RPM_PACKAGE_ARCHITECTURE "${CMAKE_SYSTEM_PROCESSOR}")
set(CPACK_RPM_PACKAGE_GROUP "Development/Libraries")

file(GLOB_RECURSE SRCS "src/lib_json/*.cpp")
file(GLOB_RECURSE HDRS "include/json/*.h")

set(PKGCONFIG_PC "prefix=/usr
libdir=\${prefix}/lib
includedir=\${prefix}/include
version = ${CPACK_PACKAGE_VERSION}
name = jsoncpp

Name: \${name}
Version: \${version}
Description: Jsoncpp library version \${version}
Cflags: -I\${includedir}
Libs: -L\${libdir} -l${TARGET}
")
#message(STATUS ${PKGCONFIG_PC})

include_directories(${PROJECT_SOURCE_DIR}/include)
add_library(${TARGET} STATIC SHARED ${SRCS})

file(WRITE ${PROJECT_SOURCE_DIR}/jsoncpp.pc ${PKGCONFIG_PC})

install(TARGETS ${TARGET}
    ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    )
install(FILES ${HDRS}
    DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/json)
install(FILES ${PROJECT_SOURCE_DIR}/jsoncpp.pc
    DESTINATION ${PKGCONFIG_CONF_PATH})

include(CPack)

소스 압축을 푼 제일 처음 디렉토리에 쳐넣고 아래 명령을 때리면 RPM이나 DEB를 구워준다.


$ cmake .
$ cpack -G RPM
$ cpack -G DEB