Improve CMake find modules.

This adds the possibility for Tox modules like AV to be optional.
This commit is contained in:
Håvard Pettersson 2015-09-02 22:34:10 +02:00
parent 210a644c9d
commit 7b9f8a48fd
3 changed files with 40 additions and 13 deletions

View File

@ -22,8 +22,11 @@ cmake_minimum_required(VERSION 2.8.7)
project(tox-weechat C)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
find_package(WeeChat)
find_package(Tox)
find_package(WeeChat REQUIRED)
find_package(Tox REQUIRED
COMPONENTS CORE
OPTIONAL_COMPONENTS AV)
set(PLUGIN_PATH "lib/weechat/plugins" CACHE PATH
"Path to install the plugin binary to.")
@ -48,11 +51,14 @@ add_library(tox MODULE
set(CMAKE_C_FLAGS_DEBUG "-DTWC_DEBUG")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -Wall -Wextra -Wno-unused-parameter")
include_directories(${TOX_INCLUDE_DIR})
include_directories(${WEECHAT_INCLUDE_DIR})
include_directories(${Tox_INCLUDE_DIRS})
include_directories(${WeeChat_INCLUDE_DIRS})
target_link_libraries(tox ${TOX_LIBRARY})
target_link_libraries(tox ${TOXAV_LIBRARY})
target_link_libraries(tox ${Tox_LIBRARIES})
if(Tox_AV_FOUND)
add_definitions(-DTOXAV_ENABLED)
endif()
# remove lib prefix (libtox.so -> tox.so)
set_target_properties(tox PROPERTIES PREFIX "")

View File

@ -1,8 +1,29 @@
find_path(TOX_INCLUDE_DIR tox/tox.h)
find_path(TOXAV_INCLUDE_DIR tox/toxav.h)
find_path(Tox_CORE_INCLUDE_DIR tox/tox.h)
find_library(Tox_CORE_LIBRARY toxcore)
find_library(TOX_LIBRARY toxcore)
find_library(TOXAV_LIBRARY toxav)
if(Tox_CORE_INCLUDE_DIR AND Tox_CORE_LIBRARY)
set(Tox_CORE_FOUND TRUE)
endif()
find_path(Tox_AV_INCLUDE_DIR tox/toxav.h)
find_library(Tox_AV_LIBRARY toxav)
if(Tox_AV_INCLUDE_DIR AND Tox_AV_LIBRARY)
set(Tox_AV_FOUND TRUE)
endif()
set(Tox_INCLUDE_DIRS)
set(Tox_LIBRARIES)
if(Tox_CORE_FOUND)
list(APPEND Tox_INCLUDE_DIRS ${Tox_CORE_INCLUDE_DIR})
list(APPEND Tox_LIBRARIES ${Tox_CORE_LIBRARY})
endif()
if(Tox_AV_FOUND)
list(APPEND Tox_INCLUDE_DIRS ${Tox_AV_INCLUDE_DIR})
list(APPEND Tox_LIBRARIES ${Tox_AV_LIBRARY})
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Tox DEFAULT_MSG TOX_INCLUDE_DIR TOXAV_INCLUDE_DIR TOX_LIBRARY TOXAV_LIBRARY)
find_package_handle_standard_args(Tox HANDLE_COMPONENTS REQUIRED_VARS Tox_INCLUDE_DIRS Tox_LIBRARIES)

View File

@ -1,4 +1,4 @@
find_path(WEECHAT_INCLUDE_DIR weechat/weechat-plugin.h)
find_path(WeeChat_INCLUDE_DIRS weechat/weechat-plugin.h)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(WeeChat DEFAULT_MSG WEECHAT_INCLUDE_DIR)
find_package_handle_standard_args(WeeChat REQUIRED_VARS WeeChat_INCLUDE_DIRS)