CMakeLists.txt
author Myhailo Danylenko <isbear@ukrpost.net>
Sat, 05 Mar 2016 18:34:07 +0200
changeset 148 b222f4d111d9
parent 147 66a63c9609de
child 151 5d90caa7fb2c
permissions -rw-r--r--
lua: Add support for lua 5.3 (v0.0.4)

## Copyright 2009-2016 Myhailo Danylenko
# This file is part of mcabber-lua.
#
# mcabber-lua 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 C)
set(PROJECT_VERSION "0.0.4")

## User options
option(DEBUG                 "Enable debugging output"                                                           ON)
option(ENABLE_LUA_ALIAS      "Enable aliasing command '/lua' to corresponding '/lua5.x' at module loading time"  ON)
option(LLM_CONNECTION_ENABLE "Enable exposing of mcabber loudmouth connection to lua"                            ON)
option(LLM_LOG_HANDLER       "Enable registration of log messages handler for lua-loudmouth library's messages"  ON)
set(ML_SOURCE_PRIORITY G_PRIORITY_HIGH_IDLE CACHE STRING "Glib event source priority for timeout and bgread")
set(ML_BGREAD_BUFFER   4096                 CACHE STRING "Background pipe reading buffer size")
set(OPT_MLUA_RC        "lua_init_filename"  CACHE STRING "Mcabber option name to specify lua initialization file")
set(OPT_MLUA_LM_DEBUG  "lua_lm_debug"       CACHE STRING "Mcabber option name to enable/disable lua logging of LM messages")
set(WANT_LUA           "AUTO" CACHE STRING "Lua version to use (You'll have to define this with -DWANT_LUA=LUAX.X)")
set_property(CACHE WANT_LUA PROPERTY STRINGS "AUTO" "LUA5.1" "LUA5.2" "LUA5.3")

## Gather information about system
find_package(PkgConfig REQUIRED)
if(WANT_LUA STREQUAL "LUA5.3")
	find_package(Lua 5.3 EXACT REQUIRED)
elseif(WANT_LUA STREQUAL "LUA5.2")
	find_package(Lua 5.2 EXACT REQUIRED)
elseif(WANT_LUA STREQUAL "LUA5.1")
	find_package(Lua 5.1 EXACT REQUIRED)
else()
	find_package(Lua 5.1 REQUIRED)
endif()
set(LUA_VERSION "${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}")
set(LUA_MODULENAME "lua${LUA_VERSION_MAJOR}${LUA_VERSION_MINOR}")
if(LUA_VERSION VERSION_EQUAL "5.1")
	set(LUA51_COMPATIBILITY TRUE)
endif()
pkg_check_modules(GLIB REQUIRED glib-2.0)
pkg_check_modules(GMODULE REQUIRED gmodule-2.0)
pkg_check_modules(MCABBER REQUIRED mcabber)
find_program(DOCGEN_EXECUTABLE NAMES docgen.pl docgen DOC "Docgen documentation generator script (optional)")
include(CheckCSourceCompiles)
set(CMAKE_REQUIRED_INCLUDES ${MCABBER_INCLUDE_DIRS})
set(CMAKE_REQUIRED_LIBRARIES ${MCABBER_LIBRARIES})
set(CMAKE_REQUIRED_FLAGS ${MCABBER_LDFLAGS} ${MCABBER_CFLAGS})
check_c_source_compiles("
	#include <glib.h>
	#include <mcabber/api.h>
	#ifdef MCABBER_API_HAVE_COMPL_FLAGS
	int main (void) { return 0; }
	#endif
	" HAVE_MCABBER_COMPLETION_FLAGS)
include(CheckSymbolExists)
check_symbol_exists(COMPL_CARBONS mcabber/compl.h HAVE_COMPL_CARBONS)
link_directories(${GLIB_LIBRARY_DIRS}
				 ${GMODULE_LIBRARY_DIRS}
				 ${MCABBER_LIBRARY_DIRS})

## Define targets
add_library(lua MODULE lua.c util.c)
get_target_property(lua_SOURCES lua SOURCES)

## Set up compiler
configure_file(config.h.in config.h ESCAPE_QUOTES)
include_directories(SYSTEM ${LUA_INCLUDE_DIR}
					${GLIB_INCLUDE_DIRS}
					${GMODULE_INCLUDE_DIRS}
					${MCABBER_INCLUDE_DIRS})
target_link_libraries(lua ${LUA_LIBRARIES}
					  ${GLIB_LIBRARIES}
					  ${GMODULE_LIBRARIES}
					  ${MCABBER_LIBRARRIES})
include_directories(${lua_SOURCE_DIR}
					${lua_BINARY_DIR})
set_target_properties(lua PROPERTIES
                      COMPILE_FLAGS "-Wall"
					  OUTPUT_NAME "${LUA_MODULENAME}")

## Extra targets
if(DOCGEN_EXECUTABLE)
	add_custom_command(OUTPUT ${lua_BINARY_DIR}/lua.html      COMMAND ${DOCGEN_EXECUTABLE} -f html -t "Documentation for Lua module for MCabber" -o ${lua_BINARY_DIR}/lua.html      -- ${lua_SOURCES} DEPENDS ${DOCGEN_EXECUTABLE} ${lua_SOURCES} WORKING_DIRECTORY ${lua_SOURCE_DIR})
	add_custom_target(doc    ALL DEPENDS ${lua_BINARY_DIR}/lua.html)
	add_custom_command(OUTPUT ${lua_SOURCE_DIR}/docs/api.mdwn COMMAND ${DOCGEN_EXECUTABLE} -f mdwn -t "Documentation for Lua module for MCabber" -o ${lua_SOURCE_DIR}/docs/api.mdwn -- ${lua_SOURCES} DEPENDS ${DOCGEN_EXECUTABLE} ${lua_SOURCES} WORKING_DIRECTORY ${lua_SOURCE_DIR})
	add_custom_target(update_api DEPENDS ${lua_SOURCE_DIR}/docs/api.mdwn)
endif()

## Packaging information
set(CPACK_PACKAGE_NAME                mcabber-mod-${LUA_MODULENAME})
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 "Mcabber module for lua ${LUA_VERSION} scripting")
set(CPACK_PACKAGE_DESCRIPTION_FILE    ${lua_SOURCE_DIR}/README)
set(CPACK_RESOURCE_FILE_LICENSE       ${lua_SOURCE_DIR}/COPYING)
set(CPACK_RESOURCE_FILE_README        ${lua_SOURCE_DIR}/README)
set(CPACK_RESOURCE_FILE_WELCOME       ${lua_SOURCE_DIR}/README)
set(CPACK_SOURCE_GENERATOR TBZ2)
set(CPACK_GENERATOR                   DEB CACHE STRING "Binary package generator, eg DEB, RPM, TGZ, NSIS...")
# XXX
set(CPACK_DEBIAN_PACKAGE_DEPENDS      "libc6, liblua${LUA_VERSION}-0, libglib2.0-0")
set(CPACK_DEBIAN_PACKAGE_RECOMMENDS   "mcabber")
set(CPACK_DEBIAN_PACKAGE_SUGGESTS     "lua${LUA_VERSION}-posix, lua${LUA_VERSION}-base64, lua${LUA_VERSION}-sha1")
set(CPACK_DEBIAN_PACKAGE_SECTION      libs)
find_program(DPKG_EXECUTABLE dpkg DOC "Path to dpkg (optional, to detect architecture)")
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)

if(HAVE_MCABBER_COMPLETION_FLAGS)
	set(AVV_COMPL_VERSION "compl:4")
else()
	set(AVV_COMPL_VERSION "compl:3")
endif()
configure_file(lua.avv.in ${LUA_MODULENAME}.avv)

## Set up installer
install(TARGETS   lua                           DESTINATION lib/mcabber)
if(DOCGEN_EXECUTABLE)
	install(FILES ${lua_BINARY_DIR}/lua.html    DESTINATION share/doc/${CPACK_PACKAGE_NAME})
endif()
install(DIRECTORY examples                      DESTINATION share/doc/${CPACK_PACKAGE_NAME} PATTERN "*~" EXCLUDE)
install(FILES     docs/readme.mdwn docs/todo.mdwn COPYING DESTINATION share/doc/${CPACK_PACKAGE_NAME})
install(FILES     help/en/hlp_lua.txt           DESTINATION share/mcabber RENAME hlp_lua${LUA_MODULENAME}.txt) # XXX localizations/other help
install(FILES     ${PROJECT_BINARY_DIR}/${LUA_MODULENAME}.avv DESTINATION share/mcabber/avv/modules RENAME ${LUA_MODULENAME})

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