CMakeLists.txt
author Myhailo Danylenko <isbear@ukrpost.net>
Mon, 01 Jun 2009 19:57:22 +0300
changeset 27 23393a00c2c1
parent 26 1f7e8b53b255
child 28 2e4650583dd7
permissions -rw-r--r--
Small typo and header fixes

## Copyright 2009 Myhailo Danylenko
# This file is part of lua-lm
#
# lua-lm is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

cmake_minimum_required(VERSION 2.6)
project(lua-lm C)

## User options
option(DEBUG "Enable debugging output" OFF)
set(TEST_USER "test@jabber.org" CACHE STRING "Testing: Your jabber account name")
set(TEST_PASSWORD "greatsecret" CACHE STRING "Testing: Password for your jabber account")
set(TEST_TO "test@jabber.org/mcabber" CACHE STRING "Testing: Target jabber entity")
set(TEST_FINGERPRINT "00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff" CACHE STRING "Testing: Your jabber server SSL fingerprint")

## Define targets
add_library(loudmouth MODULE util.c lm_types.c lm_proxy.c lm_ssl.c lm_connection.c lm_message.c lm_message_node.c lm_message_handler.c lm.c)
get_target_property(lua-lm_SOURCES loudmouth SOURCES)

## Packaging information
set(CPACK_PACKAGE_NAME liblua5.1-loudmouth)
set(CPACK_PACKAGE_VERSION_MAJOR 0)
set(CPACK_PACKAGE_VERSION_MINOR 9)
set(CPACK_PACKAGE_VERSION_PATCH 0)
set(CPACK_PACKAGE_VENDOR "IsBear")
set(CPACK_PACKAGE_CONTACT "Myhailo Danylenko <isbear@ukrpost.net>")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Loudmouth XMPP client library lua interface")
set(CPACK_PACKAGE_DESCRIPTION_FILE ${lua-lm_SOURCE_DIR}/README)
set(CPACK_RESOURCE_FILE_LICENSE ${lua-lm_SOURCE_DIR}/COPYING)
set(CPACK_RESOURCE_FILE_README ${lua-lm_SOURCE_DIR}/README)
set(CPACK_RESOURCE_FILE_WELCOME ${lua-lm_SOURCE_DIR}/README)
set(CPACK_DEBIAN_PACKAGE_SECTION libs)
# XXX: tmp=`tempfile`; obj=${lua-lm_BINARY_DIR}/loudmouth.so; ldd $obj > $tmp; objdump -p $obj | \grep NEEDED | sed -e 's/.*NEEDED *//' | xargs -I "{}" grep -F "{}" $tmp | sed -e 's/.*=> *\(\S*\).*/\1/' | xargs dpkg -S | cut -d : -f 1 | sort -u ; \rm $tmp
# TODO: versions
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6, libglib2.0-0, liblua5.1-0, libloudmouth1-0")
set(CPACK_SOURCE_GENERATOR TBZ2)
set(CPACK_GENERATOR DEB CACHE STRING "Binary package generator, eg DEB, RPM, TGZ, NSIS...")
# FIXME: Detect architecture. How? Though, it anyway produces nonconformant deb names...
set(CPACK_SYSTEM_NAME i386)
# XXX: Set package name directly to get rid of -Sources?
set(CPACK_SOURCE_IGNORE_FILES "/\\\\..*;\\\\.swp;~$;/build/;\\\\.tar\\\\.;\\\\.deb;\\\\.so")
include(CPack)

## Gather information about system
find_package(Lua51 REQUIRED)
find_program(LUA_EXECUTABLE lua lua5.1 luanoreadline)
if(LUA_EXECUTABLE)
	execute_process(COMMAND ${LUA_EXECUTABLE} -e "print ( package.path )" OUTPUT_VARIABLE LUA_PATH OUTPUT_STRIP_TRAILING_WHITESPACE)
	execute_process(COMMAND ${LUA_EXECUTABLE} -e "print ( package.cpath )" OUTPUT_VARIABLE LUA_CPATH OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
find_package(PkgConfig REQUIRED)
pkg_check_modules(GLIB REQUIRED glib-2.0)
pkg_check_modules(LM REQUIRED loudmouth-1.0)
include(CheckFunctionExists)
set(CMAKE_REQUIRED_INCLUDES ${LM_INCLUDE_DIRS})
set(CMAKE_REQUIRED_LIBRARIES ${LM_LIBRARIES})
check_function_exists(lm_connection_get_keep_alive_rate HAVE_LM_CONNECTION_GET_KEEP_ALIVE_RATE)
find_package(Perl)

## Set up compiler
configure_file(config.h.in config.h)
include_directories(SYSTEM ${LUA_INCLUDE_DIR} ${GLIB_INCLUDE_DIRS} ${LM_INCLUDE_DIRS})
target_link_libraries(loudmouth ${LUA_LIBRARIES} ${GLIB_LIBRARIES} ${LM_LIBRARIES})
include_directories(${lua-lm_SOURCE_DIR} ${lua-lm_BINARY_DIR})
set_target_properties(loudmouth PROPERTIES PREFIX "")

## Extra targets
if(PERL_FOUND)
	add_custom_command(OUTPUT ${lua-lm_BINARY_DIR}/loudmouth.html COMMAND ${PERL_EXECUTABLE} ${lua-lm_SOURCE_DIR}/docgen.pl ${lua-lm_SOURCES} > ${lua-lm_BINARY_DIR}/loudmouth.html DEPENDS ${lua-lm_SOURCE_DIR}/docgen.pl ${lua-lm_SOURCES} WORKING_DIRECTORY ${lua-lm_SOURCE_DIR})
	add_custom_target(doc ALL DEPENDS ${lua-lm_BINARY_DIR}/loudmouth.html)
endif()
if(LUA_EXECUTABLE)
	add_custom_target(test COMMAND env "LUA_PATH=${lua-lm_SOURCE_DIR}/?.lua;${LUA_PATH}" "LUA_CPATH=${lua-lm_SOURCE_DIR}/?.so;${lua-lm_BINARY_DIR}/?.so;${LUA_CPATH}" "${LUA_EXECUTABLE}" "${lua-lm_SOURCE_DIR}/test.lua" "${TEST_USER}" "${TEST_PASSWORD}" "${TEST_TO}" "${TEST_FINGERPRINT}" DEPENDS loudmouth VERBATIM)
endif()

## Set up installer
install(TARGETS loudmouth DESTINATION lib/lua/5.1)
install(FILES lm.lua DESTINATION share/lua/5.1)
install(FILES test.lua DESTINATION share/doc/${CPACK_PACKAGE_NAME}/examples)
if(PERL_FOUND)
	install(FILES ${lua-lm_BINARY_DIR}/loudmouth.html DESTINATION share/doc/${CPACK_PACKAGE_NAME})
endif()
install(FILES README DESTINATION share/doc/${CPACK_PACKAGE_NAME})
install(FILES TODO DESTINATION share/doc/${CPACK_PACKAGE_NAME})
install(FILES COPYING DESTINATION share/doc/${CPACK_PACKAGE_NAME})

## The End ## vim: se ts=4: ##