CMakeLists.txt
author Myhailo Danylenko <isbear@ukrpost.net>
Sat, 05 Mar 2016 15:43:04 +0200
changeset 59 19cfaceda6bb
parent 57 37ed3c7ac1b6
child 62 d92358eafead
permissions -rw-r--r--
ssl: Add ssl:ca_path and ssl:cipher_list methods (v0.9.4)

## Copyright 2009-2016 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)
set(PROJECT_VERSION "0.9.4")

## User options
option(DEBUG      "Enable debugging output" OFF)
option(WANT_LUA52 "Force Lua 5.2 usage"     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")

## Gather information about system
find_package(PkgConfig REQUIRED)
if(NOT WANT_LUA52)
	find_package(Lua51)
endif()
if(WANT_LUA52 OR NOT LUA51_FOUND)
	pkg_check_modules(LUA REQUIRED lua5.2)
	set(LUA_VERSION "5.2")
	set(HAVE_LUA52 "1")
else()
	set(LUA_VERSION "5.1")
	set(LUA_INCLUDE_DIRS ${LUA_INCLUDE_DIR})
endif()
find_program(LUA_EXECUTABLE lua${LUA_VERSION} lua 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()
pkg_check_modules(GLIB REQUIRED glib-2.0)
pkg_check_modules(LM loudmouth-1.0>=1.5.3)
if ( LM_FOUND )
	set(HAVE_LM_SHA256_FINGERPRINTS TRUE)
else()
	pkg_check_modules(LM REQUIRED loudmouth-1.0)
endif()
include(CheckFunctionExists)
set(CMAKE_REQUIRED_INCLUDES ${LM_INCLUDE_DIRS})
set(CMAKE_REQUIRED_LIBRARIES ${LM_LIBRARIES})
set(CMAKE_REQUIRED_FLAGS ${LM_LDFLAGS} ${LM_CFLAGS})
check_function_exists(lm_connection_get_keep_alive_rate HAVE_LM_CONNECTION_GET_KEEP_ALIVE_RATE)
check_function_exists(lm_connection_unregister_reply_handler HAVE_LM_CONNECTION_UNREGISTER_REPLY_HANDLER)
check_function_exists(lm_ssl_set_ca HAVE_LM_SSL_SET_CA)
check_function_exists(lm_ssl_set_cipher_list HAVE_LM_SSL_SET_CIPHER_LIST)
find_program(DOCGEN_EXECUTABLE NAMES docgen.pl docgen DOC "Docgen documentation generator script (optional)")
# (this should be before targets definitions)
link_directories(${LUA_LIBRARY_DIRS} ${GLIB_LIBRARY_DIRS} ${LM_LIBRARY_DIRS})

## 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(loudmouth_SOURCES loudmouth SOURCES)

## Set up compiler
if(DEBUG)
	set(DEBUG_COMPILE_FLAGS "-g")
endif()
configure_file(config.h.in config.h)
include_directories(SYSTEM ${LUA_INCLUDE_DIRS} ${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 ""
                      COMPILE_FLAGS "-Wall ${DEBUG_COMPILE_FLAGS}")

## Extra targets
if(DOCGEN_EXECUTABLE)
	add_custom_command(OUTPUT ${lua-lm_BINARY_DIR}/loudmouth.html COMMAND ${DOCGEN_EXECUTABLE} -f html -t "Lua-loudmouth API reference" -o ${lua-lm_BINARY_DIR}/loudmouth.html -- ${loudmouth_SOURCES} DEPENDS ${DOCGEN_EXECUTABLE} ${loudmouth_SOURCES} WORKING_DIRECTORY ${lua-lm_SOURCE_DIR})
	add_custom_target(doc ALL DEPENDS ${lua-lm_BINARY_DIR}/loudmouth.html)
	add_custom_command(OUTPUT ${lua-lm_SOURCE_DIR}/docs/api.mdwn COMMAND ${DOCGEN_EXECUTABLE} -f mdwn -t "Lua-loudmouth API reference" -o ${lua-lm_SOURCE_DIR}/docs/api.mdwn -- ${loudmouth_SOURCES} DEPENDS ${DOCGEN_EXECUTABLE} ${loudmouth_SOURCES} WORKING_DIRECTORY ${lua-lm_SOURCE_DIR})
	add_custom_target(update_api DEPENDS ${lua-lm_SOURCE_DIR}/docs/api.mdwn)
endif()
if(LUA_EXECUTABLE)
	add_custom_target(dotest 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()

## Packaging information
set(CPACK_PACKAGE_NAME lua${LUA_VERSION}-loudmouth)
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
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_SOURCE_GENERATOR TBZ2)
set(CPACK_GENERATOR DEB CACHE STRING "Binary package generator, eg DEB, RPM, TGZ, NSIS...")
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, liblua${LUA_VERSION}-0, libloudmouth1-0")
find_program(DPKG_EXECUTABLE dpkg)
if(DPKG_EXECUTABLE)
	execute_process(COMMAND ${DPKG_EXECUTABLE} --print-architecture OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE OUTPUT_STRIP_TRAILING_WHITESPACE)
else()
	set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE i386 CACHE STRING "Architecture of package")
endif()
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}")
# XXX: Set package name directly to get rid of -Sources?
set(CPACK_SOURCE_IGNORE_FILES "/\\\\..*;\\\\.swp;~$;/build/;\\\\.tar\\\\.;\\\\.deb;\\\\.so")
include(CPack)

## Set up installer
install(TARGETS loudmouth DESTINATION lib/lua/${LUA_VERSION})
install(FILES lm.lua DESTINATION share/lua/${LUA_VERSION})
install(FILES test.lua DESTINATION share/doc/${CPACK_PACKAGE_NAME}/examples)
if(DOCGEN_EXECUTABLE)
	install(FILES ${lua-lm_BINARY_DIR}/loudmouth.html DESTINATION share/doc/${CPACK_PACKAGE_NAME})
endif()
install(FILES docs/readme.mdwn docs/todo.mdwn COPYING DESTINATION share/doc/${CPACK_PACKAGE_NAME})

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