isbear@59: ## Copyright 2009-2016 Myhailo Danylenko isbear@20: # This file is part of lua-lm isbear@20: # isbear@20: # lua-lm is free software: you can redistribute it and/or modify isbear@20: # it under the terms of the GNU General Public License as published by isbear@20: # the Free Software Foundation, either version 2 of the License, or isbear@20: # (at your option) any later version. isbear@20: # isbear@20: # This program is distributed in the hope that it will be useful, isbear@20: # but WITHOUT ANY WARRANTY; without even the implied warranty of isbear@20: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the isbear@20: # GNU General Public License for more details. isbear@20: # isbear@20: # You should have received a copy of the GNU General Public License isbear@20: # along with this program. If not, see . isbear@2: isbear@2: cmake_minimum_required(VERSION 2.6) isbear@5: project(lua-lm C) isbear@66: set(PROJECT_VERSION "0.9.7") isbear@2: isbear@5: ## User options isbear@63: option(DEBUG "Enable debugging output" OFF) isbear@54: set(TEST_USER "test@jabber.org" CACHE STRING "Testing: Your jabber account name") isbear@54: set(TEST_PASSWORD "greatsecret" CACHE STRING "Testing: Password for your jabber account") isbear@54: set(TEST_TO "test@jabber.org/mcabber" CACHE STRING "Testing: Target jabber entity") isbear@27: 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") isbear@63: set(WANT_LUA "AUTO" CACHE STRING "Lua version to use (You'll have to define this with -DWANT_LUA=LUAX.X)") isbear@63: set_property(CACHE WANT_LUA PROPERTY STRINGS "AUTO" "LUA5.1" "LUA5.2" "LUA5.3") isbear@5: isbear@32: ## Gather information about system isbear@54: find_package(PkgConfig REQUIRED) isbear@63: if(WANT_LUA STREQUAL "LUA5.3") isbear@65: find_package(Lua 5.3 EXACT REQUIRED) isbear@63: elseif(WANT_LUA STREQUAL "LUA5.2") isbear@65: find_package(Lua 5.2 EXACT REQUIRED) isbear@63: elseif(WANT_LUA STREQUAL "LUA5.1") isbear@65: find_package(Lua 5.1 EXACT REQUIRED) isbear@54: else() isbear@65: find_package(Lua 5.1 REQUIRED) isbear@63: endif() isbear@65: set(LUA_VERSION "${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}") isbear@65: if(LUA_VERSION VERSION_EQUAL "5.1") isbear@63: set(LUA51_COMPATIBILITY TRUE) isbear@54: endif() isbear@54: find_program(LUA_EXECUTABLE lua${LUA_VERSION} lua luanoreadline) isbear@32: if(LUA_EXECUTABLE) isbear@54: execute_process(COMMAND ${LUA_EXECUTABLE} -e "print ( package.path )" OUTPUT_VARIABLE LUA_PATH OUTPUT_STRIP_TRAILING_WHITESPACE) isbear@32: execute_process(COMMAND ${LUA_EXECUTABLE} -e "print ( package.cpath )" OUTPUT_VARIABLE LUA_CPATH OUTPUT_STRIP_TRAILING_WHITESPACE) isbear@32: endif() isbear@32: pkg_check_modules(GLIB REQUIRED glib-2.0) isbear@57: pkg_check_modules(LM loudmouth-1.0>=1.5.3) isbear@57: if ( LM_FOUND ) isbear@57: set(HAVE_LM_SHA256_FINGERPRINTS TRUE) isbear@57: else() isbear@57: pkg_check_modules(LM REQUIRED loudmouth-1.0) isbear@57: endif() isbear@32: include(CheckFunctionExists) isbear@66: include(CheckStructHasMember) isbear@32: set(CMAKE_REQUIRED_INCLUDES ${LM_INCLUDE_DIRS}) isbear@32: set(CMAKE_REQUIRED_LIBRARIES ${LM_LIBRARIES}) isbear@32: set(CMAKE_REQUIRED_FLAGS ${LM_LDFLAGS} ${LM_CFLAGS}) isbear@32: check_function_exists(lm_connection_get_keep_alive_rate HAVE_LM_CONNECTION_GET_KEEP_ALIVE_RATE) isbear@32: check_function_exists(lm_connection_unregister_reply_handler HAVE_LM_CONNECTION_UNREGISTER_REPLY_HANDLER) isbear@59: check_function_exists(lm_ssl_set_ca HAVE_LM_SSL_SET_CA) isbear@59: check_function_exists(lm_ssl_set_cipher_list HAVE_LM_SSL_SET_CIPHER_LIST) isbear@66: check_struct_has_member("LmMessageNodeAttribute" next loudmouth/loudmouth.h HAVE_LM_MESSAGE_NODE_ATTRIBUTE) isbear@47: find_program(DOCGEN_EXECUTABLE NAMES docgen.pl docgen DOC "Docgen documentation generator script (optional)") isbear@32: # (this should be before targets definitions) isbear@32: link_directories(${LUA_LIBRARY_DIRS} ${GLIB_LIBRARY_DIRS} ${LM_LIBRARY_DIRS}) isbear@32: isbear@5: ## Define targets isbear@2: 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) isbear@44: get_target_property(loudmouth_SOURCES loudmouth SOURCES) isbear@2: isbear@32: ## Set up compiler isbear@44: if(DEBUG) isbear@44: set(DEBUG_COMPILE_FLAGS "-g") isbear@44: endif() isbear@32: configure_file(config.h.in config.h) isbear@65: include_directories(SYSTEM ${LUA_INCLUDE_DIR} ${GLIB_INCLUDE_DIRS} ${LM_INCLUDE_DIRS}) isbear@32: target_link_libraries(loudmouth ${LUA_LIBRARIES} ${GLIB_LIBRARIES} ${LM_LIBRARIES}) isbear@32: include_directories(${lua-lm_SOURCE_DIR} ${lua-lm_BINARY_DIR}) isbear@44: set_target_properties(loudmouth PROPERTIES isbear@44: PREFIX "" isbear@44: COMPILE_FLAGS "-Wall ${DEBUG_COMPILE_FLAGS}") isbear@32: isbear@32: ## Extra targets isbear@47: if(DOCGEN_EXECUTABLE) isbear@47: 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}) isbear@32: add_custom_target(doc ALL DEPENDS ${lua-lm_BINARY_DIR}/loudmouth.html) isbear@48: 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}) isbear@48: add_custom_target(update_api DEPENDS ${lua-lm_SOURCE_DIR}/docs/api.mdwn) isbear@32: endif() isbear@32: if(LUA_EXECUTABLE) isbear@56: 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) isbear@32: endif() isbear@32: isbear@5: ## Packaging information isbear@54: set(CPACK_PACKAGE_NAME lua${LUA_VERSION}-loudmouth) isbear@44: set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION}) isbear@5: set(CPACK_PACKAGE_VENDOR "IsBear") isbear@5: set(CPACK_PACKAGE_CONTACT "Myhailo Danylenko ") isbear@5: set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Loudmouth XMPP client library lua interface") isbear@5: set(CPACK_PACKAGE_DESCRIPTION_FILE ${lua-lm_SOURCE_DIR}/README) isbear@5: set(CPACK_RESOURCE_FILE_LICENSE ${lua-lm_SOURCE_DIR}/COPYING) isbear@5: set(CPACK_RESOURCE_FILE_README ${lua-lm_SOURCE_DIR}/README) isbear@5: set(CPACK_RESOURCE_FILE_WELCOME ${lua-lm_SOURCE_DIR}/README) isbear@28: set(CPACK_SOURCE_GENERATOR TBZ2) isbear@28: set(CPACK_GENERATOR DEB CACHE STRING "Binary package generator, eg DEB, RPM, TGZ, NSIS...") isbear@5: set(CPACK_DEBIAN_PACKAGE_SECTION libs) isbear@20: # 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 isbear@20: # TODO: versions isbear@55: set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6, libglib2.0-0, liblua${LUA_VERSION}-0, libloudmouth1-0") isbear@28: find_program(DPKG_EXECUTABLE dpkg) isbear@28: if(DPKG_EXECUTABLE) isbear@28: execute_process(COMMAND ${DPKG_EXECUTABLE} --print-architecture OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE OUTPUT_STRIP_TRAILING_WHITESPACE) isbear@28: else() isbear@28: set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE i386 CACHE STRING "Architecture of package") isbear@28: endif() isbear@28: set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}") isbear@5: # XXX: Set package name directly to get rid of -Sources? isbear@5: set(CPACK_SOURCE_IGNORE_FILES "/\\\\..*;\\\\.swp;~$;/build/;\\\\.tar\\\\.;\\\\.deb;\\\\.so") isbear@5: include(CPack) isbear@5: isbear@34: ## Set up installer isbear@54: install(TARGETS loudmouth DESTINATION lib/lua/${LUA_VERSION}) isbear@54: install(FILES lm.lua DESTINATION share/lua/${LUA_VERSION}) isbear@34: install(FILES test.lua DESTINATION share/doc/${CPACK_PACKAGE_NAME}/examples) isbear@47: if(DOCGEN_EXECUTABLE) isbear@34: install(FILES ${lua-lm_BINARY_DIR}/loudmouth.html DESTINATION share/doc/${CPACK_PACKAGE_NAME}) isbear@34: endif() isbear@48: install(FILES docs/readme.mdwn docs/todo.mdwn COPYING DESTINATION share/doc/${CPACK_PACKAGE_NAME}) isbear@34: isbear@44: ## The End ## vim: se ts=4 sw=4: ##