Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add cmake modules to find deps
  • Loading branch information
smlng committed Jun 20, 2016
commit 1c77814e50f2cd0b5dfe7dce8e523cd5fa9d10c3
35 changes: 32 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,36 @@
project(bird-rtrlib-cli)
cmake_minimum_required(VERSION 2.6)
add_executable(bird-rtrlib-cli bird-rtrlib-cli.c bird.c rtr.c cli.c config.c)

include_directories(${RTRLIB_INCLUDE} ${INCLUDE_DIRECTORIES})
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -std=gnu99")

include_directories(.)
find_package(Argp)
if(ARGP_FOUND)
message(STATUS "argp found.")
else()
message(FATAL_ERROR "argp not found!")
endif(ARGP_FOUND)

if(NOT RTRLIB_INCLUDE AND NOT RTRLIB_LIBRARY)
find_package(Rtr)
if(RTR_FOUND)
message(STATUS "rtrlib found.")
else()
message(FATAL_ERROR "rtrlib not found!")
endif(RTR_FOUND)
else()
set(RTR_INCLUDE_DIRS ${RTRLIB_INCLUDE})
set(RTR_LIBRARIES ${RTRLIB_LIBRARY})
endif(NOT RTRLIB_INCLUDE AND NOT RTRLIB_LIBRARY)

target_link_libraries(bird-rtrlib-cli rtr)
find_package(LibSSH 0.6.0)
if(LIBSSH_FOUND)
message(STATUS "libssh found.")
else()
message(FATAL_ERROR "libssh not found!")
endif(LIBSSH_FOUND)

include_directories(${ARGP_INCLUDE_DIRS} ${LIBSSH_INCLUDE_DIRS} ${RTR_INCLUDE_DIRS} ${INCLUDE_DIRECTORIES})
add_executable(bird-rtrlib-cli bird-rtrlib-cli.c bird.c rtr.c cli.c config.c)
target_link_libraries(bird-rtrlib-cli ${ARGP_LIBRARIES} ${RTR_LIBRARIES})
59 changes: 59 additions & 0 deletions cmake/modules/FindArgp.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# - Try to find Argp
# Once done this will define
#
# ARGP_FOUND - system has Argp
# ARGP_INCLUDE_DIRS - the Argp include directory
# ARGP_LIBRARIES - Link these to use Argp
# ARGP_DEFINITIONS - Compiler switches required for using Argp
#
# Copyright (c) 2010 Andreas Schneider <[email protected]>
#
# Redistribution and use is allowed according to the terms of the New
# BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
#


if (ARGP_LIBRARIES AND ARGP_INCLUDE_DIRS)
# in cache already
set(ARGP_FOUND TRUE)
else (ARGP_LIBRARIES AND ARGP_INCLUDE_DIRS)

find_path(ARGP_INCLUDE_DIR
NAMES
argp.h
PATHS
/usr/include
/usr/local/include
/opt/local/include
/sw/include
)

find_library(ARGP_LIBRARY
NAMES
argp
PATHS
/usr/lib
/usr/local/lib
/opt/local/lib
/sw/lib
)

set(ARGP_INCLUDE_DIRS
${ARGP_INCLUDE_DIR}
)

if (ARGP_LIBRARY)
set(ARGP_LIBRARIES
${ARGP_LIBRARIES}
${ARGP_LIBRARY}
)
endif (ARGP_LIBRARY)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Argp DEFAULT_MSG ARGP_LIBRARIES ARGP_INCLUDE_DIRS)

# show the ARGP_INCLUDE_DIRS and ARGP_LIBRARIES variables only in the advanced view
mark_as_advanced(ARGP_INCLUDE_DIRS ARGP_LIBRARIES)

endif (ARGP_LIBRARIES AND ARGP_INCLUDE_DIRS)
94 changes: 94 additions & 0 deletions cmake/modules/FindLibSSH.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# - Try to find LibSSH
# Once done this will define
#
# LIBSSH_FOUND - system has LibSSH
# LIBSSH_INCLUDE_DIRS - the LibSSH include directory
# LIBSSH_LIBRARIES - Link these to use LibSSH
# LIBSSH_DEFINITIONS - Compiler switches required for using LibSSH
#
# Copyright (c) 2009 Andreas Schneider <[email protected]>
#
# Redistribution and use is allowed according to the terms of the New
# BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
#
if (LIBSSH_LIBRARIES AND LIBSSH_INCLUDE_DIRS)
# in cache already
set(LIBSSH_FOUND TRUE)
else (LIBSSH_LIBRARIES AND LIBSSH_INCLUDE_DIRS)

find_path(LIBSSH_INCLUDE_DIR
NAMES
libssh/libssh.h
PATHS
/usr/include
/usr/local/include
/opt/local/include
/sw/include
${CMAKE_INCLUDE_PATH}
${CMAKE_INSTALL_PREFIX}/include
)

find_library(SSH_LIBRARY
NAMES
ssh
libssh
PATHS
/usr/lib
/usr/local/lib
/opt/local/lib
/sw/lib
${CMAKE_LIBRARY_PATH}
${CMAKE_INSTALL_PREFIX}/lib
)

if (LIBSSH_INCLUDE_DIR AND SSH_LIBRARY)
set(SSH_FOUND TRUE)
endif (LIBSSH_INCLUDE_DIR AND SSH_LIBRARY)

set(LIBSSH_INCLUDE_DIRS
${LIBSSH_INCLUDE_DIR}
)

if (SSH_FOUND)
set(LIBSSH_LIBRARIES
${LIBSSH_LIBRARIES}
${SSH_LIBRARY}
)

if (LibSSH_FIND_VERSION)
file(STRINGS ${LIBSSH_INCLUDE_DIR}/libssh/libssh.h LIBSSH_VERSION_MAJOR
REGEX "#define[ ]+LIBSSH_VERSION_MAJOR[ ]+[0-9]+")
# Older versions of libssh like libssh-0.2 have LIBSSH_VERSION but not LIBSSH_VERSION_MAJOR
if (LIBSSH_VERSION_MAJOR)
string(REGEX MATCH "[0-9]+" LIBSSH_VERSION_MAJOR ${LIBSSH_VERSION_MAJOR})
file(STRINGS ${LIBSSH_INCLUDE_DIR}/libssh/libssh.h LIBSSH_VERSION_MINOR
REGEX "#define[ ]+LIBSSH_VERSION_MINOR[ ]+[0-9]+")
string(REGEX MATCH "[0-9]+" LIBSSH_VERSION_MINOR ${LIBSSH_VERSION_MINOR})
file(STRINGS ${LIBSSH_INCLUDE_DIR}/libssh/libssh.h LIBSSH_VERSION_PATCH
REGEX "#define[ ]+LIBSSH_VERSION_MICRO[ ]+[0-9]+")
string(REGEX MATCH "[0-9]+" LIBSSH_VERSION_PATCH ${LIBSSH_VERSION_PATCH})

set(LibSSH_VERSION ${LIBSSH_VERSION_MAJOR}.${LIBSSH_VERSION_MINOR}.${LIBSSH_VERSION_PATCH})

include(FindPackageVersionCheck)
find_package_version_check(LibSSH DEFAULT_MSG)
else (LIBSSH_VERSION_MAJOR)
message(STATUS "LIBSSH_VERSION_MAJOR not found in ${LIBSSH_INCLUDE_DIR}/libssh/libssh.h, assuming libssh is too old")
set(LIBSSH_FOUND FALSE)
endif (LIBSSH_VERSION_MAJOR)
endif (LibSSH_FIND_VERSION)
endif (SSH_FOUND)

# If the version is too old, but libs and includes are set,
# find_package_handle_standard_args will set LIBSSH_FOUND to TRUE again,
# so we need this if() here.
if (LIBSSH_FOUND)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LibSSH DEFAULT_MSG LIBSSH_LIBRARIES LIBSSH_INCLUDE_DIRS)
endif (LIBSSH_FOUND)

# show the LIBSSH_INCLUDE_DIRS and LIBSSH_LIBRARIES variables only in the advanced view
mark_as_advanced(LIBSSH_INCLUDE_DIRS LIBSSH_LIBRARIES)

endif (LIBSSH_LIBRARIES AND LIBSSH_INCLUDE_DIRS)
68 changes: 68 additions & 0 deletions cmake/modules/FindPackageVersionCheck.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# FIND_PACKAGE_VERSION_CHECK(NAME (DEFAULT_MSG|"Custom failure message"))
# This function is intended to be used in FindXXX.cmake modules files.
# It handles NAME_FIND_VERSION and NAME_VERSION variables in a Module.
#
# Example:
# find_package(LibSSH 0.3.2)
#
# # check for the version and set it
# set(LibSSH_VERSION 0.3.0)
# find_package_version_check(LibSSH DEFAULT_MSG)
#
#
# Copyright (c) 2009 Andreas Schneider <[email protected]>
#
# Redistribution and use is allowed according to the terms of the New
# BSD license.

function(FIND_PACKAGE_VERSION_CHECK _NAME _FAIL_MSG)
string(TOUPPER ${_NAME} _NAME_UPPER)
set(_AGE "old")

if(${_NAME}_FIND_VERSION_EXACT)
if (${_NAME}_FIND_VERSION VERSION_EQUAL ${_NAME}_VERSION)
# exact version found
set(${_NAME_UPPER}_FOUND TRUE)
else (${_NAME}_FIND_VERSION VERSION_EQUAL ${_NAME}_VERSION)
# exect version not found
set(${_NAME_UPPER}_FOUND FALSE)
# check if newer or older
if (${_NAME}_FIND_VERSION VERSION_LESS ${_NAME}_VERSION)
set(_AGE "new")
else (${_NAME}_FIND_VERSION VERSION_LESS ${_NAME}_VERSION)
set(_AGE "old")
endif (${_NAME}_FIND_VERSION VERSION_LESS ${_NAME}_VERSION)
endif (${_NAME}_FIND_VERSION VERSION_EQUAL ${_NAME}_VERSION)
else (${_NAME}_FIND_VERSION_EXACT)
if (${_NAME}_FIND_VERSION)
if (${_NAME}_VERSION VERSION_LESS ${_NAME}_FIND_VERSION)
set(${_NAME_UPPER}_FOUND FALSE)
set(_AGE "old")
else (${_NAME}_VERSION VERSION_LESS ${_NAME}_FIND_VERSION)
set(${_NAME_UPPER}_FOUND TRUE)
endif (${_NAME}_VERSION VERSION_LESS ${_NAME}_FIND_VERSION)
endif (${_NAME}_FIND_VERSION)
endif(${_NAME}_FIND_VERSION_EXACT)

if ("${_FAIL_MSG}" STREQUAL "DEFAULT_MSG")
if (${_NAME}_FIND_VERSION_EXACT)
set(_FAIL_MESSAGE "The installed ${_NAME} version ${${_NAME}_VERSION} is too ${_AGE}, version ${${_NAME}_FIND_VERSION} is required.")
else (${_NAME}_FIND_VERSION_EXACT)
set(_FAIL_MESSAGE "The installed ${_NAME} version ${${_NAME}_VERSION} is too ${_AGE}, at least version ${${_NAME}_FIND_VERSION} is required.")
endif (${_NAME}_FIND_VERSION_EXACT)
else ("${_FAIL_MSG}" STREQUAL "DEFAULT_MSG")
set(_FAIL_MESSAGE "${_FAIL_MSG}")
endif ("${_FAIL_MSG}" STREQUAL "DEFAULT_MSG")

if (NOT ${_NAME_UPPER}_FOUND)
if (${_NAME}_FIND_REQUIRED)
message(FATAL_ERROR "${_FAIL_MESSAGE}")
else (${_NAME}_FIND_REQUIRED)
if (NOT ${_NAME}_FIND_QUIETLY)
message(STATUS "${_FAIL_MESSAGE}")
endif (NOT ${_NAME}_FIND_QUIETLY)
endif (${_NAME}_FIND_REQUIRED)
endif (NOT ${_NAME_UPPER}_FOUND)

set(${_NAME_UPPER}_FOUND ${${_NAME_UPPER}_FOUND} PARENT_SCOPE)
endfunction(FIND_PACKAGE_VERSION_CHECK)
60 changes: 60 additions & 0 deletions cmake/modules/FindRtr.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# - Try to find RTR
# Once done this will define
#
# RTR_FOUND - system has RTR
# RTR_INCLUDE_DIRS - the RTR include directory
# RTR_LIBRARIES - Link these to use RTR
# RTR_DEFINITIONS - Compiler switches required for using RTR
#
# Copyright (c) 2016 smlng <[email protected]>
# based on FindArgp.cmake by Andreas Schneider <[email protected]>
#
# Redistribution and use is allowed according to the terms of the New
# BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
#


if (RTR_LIBRARIES AND RTR_INCLUDE_DIRS)
# in cache already
set(RTR_FOUND TRUE)
else (RTR_LIBRARIES AND RTR_INCLUDE_DIRS)

find_path(RTR_INCLUDE_DIR
NAMES
rtrlib/rtrlib.h
PATHS
/usr/include
/usr/local/include
/opt/local/include
/sw/include
)

find_library(RTR_LIBRARY
NAMES
rtr
PATHS
/usr/lib
/usr/local/lib
/opt/local/lib
/sw/lib
)

set(RTR_INCLUDE_DIRS
${RTR_INCLUDE_DIR}
)

if (RTR_LIBRARY)
set(RTR_LIBRARIES
${RTR_LIBRARIES}
${RTR_LIBRARY}
)
endif (RTR_LIBRARY)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(RTR DEFAULT_MSG RTR_LIBRARIES RTR_INCLUDE_DIRS)

# show the RTR_INCLUDE_DIRS and RTR_LIBRARIES variables only in the advanced view
mark_as_advanced(RTR_INCLUDE_DIRS RTR_LIBRARIES)

endif (RTR_LIBRARIES AND RTR_INCLUDE_DIRS)