Commit cd82e5e8 authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen

add skeleton for NRF

parents
# Analogue for standard CMake module with same name, appeared in CMake 2.8.3.
#
# Used for compatibility with older versions of cmake.
function(cmake_parse_arguments prefix options one_value_keywords multi_value_keywords)
set(all_keywords ${options} ${one_value_keywords} ${multi_value_keywords})
# Clear variables before parsing.
foreach(arg ${one_value_keywords} ${multie_value_keywords})
set(cpa_${arg})
endforeach()
foreach(arg ${options})
set(cpa_${arg} FALSE)
endforeach()
set(cpa_UNPARSED_ARGUMENTS)
set(current_keyword)
# Classification for current_keyword:
# 'ONE' or 'MULTY'.
set(current_keyword_type)
# now iterate over all arguments and fill the result variables
foreach(arg ${ARGN})
list(FIND all_keywords ${arg} keyword_index)
if(keyword_index EQUAL -1)
if(current_keyword)
if(current_keyword_type STREQUAL "ONE")
set(cpa_${current_keyword} ${arg})
set(current_keyword)
else(current_keyword_type STREQUAL "ONE")
list(APPEND cpa_${current_keyword} ${arg})
endif(current_keyword_type STREQUAL "ONE")
else(current_keyword)
list(APPEND cpa_UNPARSED_ARGUMENTS ${arg})
endif(current_keyword)
else(keyword_index EQUAL -1)
if(current_keyword AND current_keyword_type STREQUAL "ONE")
message(SEND_ERROR "Value is expected for one-value-keyword ${current_keyword}")
endif(current_keyword AND current_keyword_type STREQUAL "ONE")
list(FIND options ${arg} option_index)
if(option_index EQUAL -1)
set(current_keyword ${arg})
list(FIND one_value_keywords ${arg} one_value_index)
if(one_value_index EQUAL -1)
set(current_keyword_type "MULTI")
else(one_value_index EQUAL -1)
set(current_keyword_type "ONE")
endif(one_value_index EQUAL -1)
else(option_index EQUAL -1)
set(current_keyword)
set(cpa_${arg} TRUE)
endif(option_index EQUAL -1)
endif(keyword_index EQUAL -1)
endforeach(arg ${ARGN})
if(current_keyword AND current_keyword_type STREQUAL "ONE")
message(SEND_ERROR "Value is expected for one-value-keyword ${current_keyword}")
endif(current_keyword AND current_keyword_type STREQUAL "ONE")
# propagate the result variables to the caller:
foreach(keyword ${all_keywords} UNPARSED_ARGUMENTS)
set(${prefix}_${keyword} ${cpa_${keyword}} PARENT_SCOPE)
endforeach(keyword ${all_keywords})
endfunction(cmake_parse_arguments prefix options one_value_keywords multi_value_keywords)
# - Find mysqlclient
# Find the native MySQL includes and library
#
# MYSQL_INCLUDE_DIR - where to find mysql.h, etc.
# MYSQL_LIBRARIES - List of libraries when using MySQL.
# MYSQL_FOUND - True if MySQL found.
IF (MYSQL_INCLUDE_DIR)
# Already in cache, be silent
SET(MYSQL_FIND_QUIETLY TRUE)
ENDIF (MYSQL_INCLUDE_DIR)
FIND_PATH(MYSQL_INCLUDE_DIR mysql.h
/usr/local/include/mysql
/usr/include/mysql
)
SET(MYSQL_NAMES mysqlclient mysqlclient_r)
FIND_LIBRARY(MYSQL_LIBRARY
NAMES ${MYSQL_NAMES}
PATHS /usr/lib /usr/local/lib
PATH_SUFFIXES mysql
)
IF (MYSQL_INCLUDE_DIR AND MYSQL_LIBRARY)
SET(MYSQL_FOUND TRUE)
SET( MYSQL_LIBRARIES ${MYSQL_LIBRARY} )
ELSE (MYSQL_INCLUDE_DIR AND MYSQL_LIBRARY)
SET(MYSQL_FOUND FALSE)
SET( MYSQL_LIBRARIES )
ENDIF (MYSQL_INCLUDE_DIR AND MYSQL_LIBRARY)
IF (MYSQL_FOUND)
IF (NOT MYSQL_FIND_QUIETLY)
MESSAGE(STATUS "Found MySQL: ${MYSQL_LIBRARY}")
ENDIF (NOT MYSQL_FIND_QUIETLY)
ELSE (MYSQL_FOUND)
IF (MYSQL_FIND_REQUIRED)
MESSAGE(STATUS "Looked for MySQL libraries named ${MYSQL_NAMES}.")
MESSAGE(FATAL_ERROR "Could NOT find MySQL library")
ENDIF (MYSQL_FIND_REQUIRED)
ENDIF (MYSQL_FOUND)
MARK_AS_ADVANCED(
MYSQL_LIBRARY
MYSQL_INCLUDE_DIR
)
# - Look for GNU Bison, the parser generator
# Based off a news post from Andy Cedilnik at Kitware
# Defines the following:
# BISON_EXECUTABLE - path to the bison executable
# BISON_FILE - parse a file with bison
# BISON_PREFIX_OUTPUTS - Set to true to make BISON_FILE produce prefixed
# symbols in the generated output based on filename.
# So for ${filename}.y, you'll get ${filename}parse(), etc.
# instead of yyparse().
# BISON_GENERATE_DEFINES - Set to true to make BISON_FILE output the matching
# .h file for a .c file. You want this if you're using
# flex.
IF(NOT DEFINED BISON_PREFIX_OUTPUTS)
SET(BISON_PREFIX_OUTPUTS FALSE)
ENDIF(NOT DEFINED BISON_PREFIX_OUTPUTS)
IF(NOT DEFINED BISON_GENERATE_DEFINES)
SET(BISON_GENERATE_DEFINES FALSE)
ENDIF(NOT DEFINED BISON_GENERATE_DEFINES)
IF(NOT BISON_EXECUTABLE)
MESSAGE(STATUS "Looking for bison")
FIND_PROGRAM(BISON_EXECUTABLE bison)
IF(BISON_EXECUTABLE)
MESSAGE(STATUS "Looking for bison -- ${BISON_EXECUTABLE}")
ENDIF(BISON_EXECUTABLE)
ENDIF(NOT BISON_EXECUTABLE)
IF(BISON_EXECUTABLE)
MACRO(BISON_FILE FILENAME)
GET_FILENAME_COMPONENT(PATH "${FILENAME}" PATH)
IF("${PATH}" STREQUAL "")
SET(PATH_OPT "")
ELSE("${PATH}" STREQUAL "")
SET(PATH_OPT "/${PATH}")
ENDIF("${PATH}" STREQUAL "")
GET_FILENAME_COMPONENT(HEAD "${FILENAME}" NAME_WE)
IF(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}${PATH_OPT}")
FILE(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}${PATH_OPT}")
ENDIF(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}${PATH_OPT}")
IF(BISON_PREFIX_OUTPUTS)
SET(PREFIX "${HEAD}")
ELSE(BISON_PREFIX_OUTPUTS)
SET(PREFIX "yy")
ENDIF(BISON_PREFIX_OUTPUTS)
SET(OUTFILE "${CMAKE_CURRENT_BINARY_DIR}${PATH_OPT}/${HEAD}.tab.c")
IF(BISON_GENERATE_DEFINES)
SET(HEADER "${CMAKE_CURRENT_BINARY_DIR}${PATH_OPT}/${HEAD}.tab.h")
ADD_CUSTOM_COMMAND(
OUTPUT "${OUTFILE}" "${HEADER}"
COMMAND "${BISON_EXECUTABLE}"
ARGS "--name-prefix=${PREFIX}"
"--defines"
"--output-file=${OUTFILE}"
"${CMAKE_CURRENT_SOURCE_DIR}/${FILENAME}"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${FILENAME}")
SET_SOURCE_FILES_PROPERTIES("${OUTFILE}" "${HEADER}" PROPERTIES GENERATED TRUE)
SET_SOURCE_FILES_PROPERTIES("${HEADER}" PROPERTIES HEADER_FILE_ONLY TRUE)
ELSE(BISON_GENERATE_DEFINES)
ADD_CUSTOM_COMMAND(
OUTPUT "${OUTFILE}"
COMMAND "${BISON_EXECUTABLE}"
ARGS "--name-prefix=${PREFIX}"
"--output-file=${OUTFILE}"
"${CMAKE_CURRENT_SOURCE_DIR}/${FILENAME}"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${FILENAME}")
SET_SOURCE_FILES_PROPERTIES("${OUTFILE}" PROPERTIES GENERATED TRUE)
ENDIF(BISON_GENERATE_DEFINES)
ENDMACRO(BISON_FILE)
ENDIF(BISON_EXECUTABLE)
# - Look for GNU flex, the lexer generator.
# Defines the following:
# FLEX_EXECUTABLE - path to the flex executable
# FLEX_FILE - parse a file with flex
# FLEX_PREFIX_OUTPUTS - Set to true to make FLEX_FILE produce outputs of
# lex.${filename}.c, not lex.yy.c . Passes -P to flex.
IF(NOT DEFINED FLEX_PREFIX_OUTPUTS)
SET(FLEX_PREFIX_OUTPUTS FALSE)
ENDIF(NOT DEFINED FLEX_PREFIX_OUTPUTS)
IF(NOT FLEX_EXECUTABLE)
MESSAGE(STATUS "Looking for flex")
FIND_PROGRAM(FLEX_EXECUTABLE flex)
IF(FLEX_EXECUTABLE)
MESSAGE(STATUS "Looking for flex -- ${FLEX_EXECUTABLE}")
ENDIF(FLEX_EXECUTABLE)
ENDIF(NOT FLEX_EXECUTABLE)
IF(FLEX_EXECUTABLE)
MACRO(FLEX_FILE FILENAME)
GET_FILENAME_COMPONENT(PATH "${FILENAME}" PATH)
IF("${PATH}" STREQUAL "")
SET(PATH_OPT "")
ELSE("${PATH}" STREQUAL "")
SET(PATH_OPT "/${PATH}")
ENDIF("${PATH}" STREQUAL "")
IF(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}${PATH_OPT}")
FILE(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}${PATH_OPT}")
ENDIF(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}${PATH_OPT}")
IF(FLEX_PREFIX_OUTPUTS)
GET_FILENAME_COMPONENT(PREFIX "${FILENAME}" NAME_WE)
ELSE(FLEX_PREFIX_OUTPUTS)
SET(PREFIX "yy")
ENDIF(FLEX_PREFIX_OUTPUTS)
SET(OUTFILE "${CMAKE_CURRENT_BINARY_DIR}${PATH_OPT}/lex.${PREFIX}.c")
ADD_CUSTOM_COMMAND(
OUTPUT "${OUTFILE}"
COMMAND "${FLEX_EXECUTABLE}"
ARGS "--prefix=${PREFIX}"
"--outfile=${OUTFILE}"
"${CMAKE_CURRENT_SOURCE_DIR}/${FILENAME}"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${FILENAME}")
SET_SOURCE_FILES_PROPERTIES("${OUTFILE}" PROPERTIES GENERATED TRUE)
ENDMACRO(FLEX_FILE)
ENDIF(FLEX_EXECUTABLE)
# - Try to find the CHECK libraries
# Once done this will define
#
# CHECK_FOUND - system has check
# CHECK_INCLUDE_DIR - the check include directory
# CHECK_LIBRARIES - check library
#
# This configuration file for finding libcheck is originally from
# the opensync project. The originally was downloaded from here:
# opensync.org/browser/branches/3rd-party-cmake-modules/modules/FindCheck.cmake
#
# Copyright (c) 2007 Daniel Gollub <dgollub@suse.de>
# Copyright (c) 2007 Bjoern Ricks <b.ricks@fh-osnabrueck.de>
#
# Redistribution and use is allowed according to the terms of the New
# BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
INCLUDE( FindPkgConfig )
# Take care about check.pc settings
PKG_SEARCH_MODULE( CHECK check )
# Look for CHECK include dir and libraries
IF( NOT CHECK_FOUND )
IF ( CHECK_INSTALL_DIR )
MESSAGE ( STATUS "Using override CHECK_INSTALL_DIR to find check" )
SET ( CHECK_INCLUDE_DIR "${CHECK_INSTALL_DIR}/include" )
SET ( CHECK_INCLUDE_DIRS "${CHECK_INCLUDE_DIR}" )
FIND_LIBRARY( CHECK_LIBRARY NAMES check PATHS "${CHECK_INSTALL_DIR}/lib" )
FIND_LIBRARY( COMPAT_LIBRARY NAMES compat PATHS "${CHECK_INSTALL_DIR}/lib" )
SET ( CHECK_LIBRARIES "${CHECK_LIBRARY}" "${COMPAT_LIBRARY}" )
ELSE ( CHECK_INSTALL_DIR )
FIND_PATH( CHECK_INCLUDE_DIR check.h )
FIND_LIBRARY( CHECK_LIBRARIES NAMES check )
ENDIF ( CHECK_INSTALL_DIR )
IF ( CHECK_INCLUDE_DIR AND CHECK_LIBRARIES )
SET( CHECK_FOUND 1 )
IF ( NOT Check_FIND_QUIETLY )
MESSAGE ( STATUS "Found CHECK: ${CHECK_LIBRARIES}" )
ENDIF ( NOT Check_FIND_QUIETLY )
ELSE ( CHECK_INCLUDE_DIR AND CHECK_LIBRARIES )
IF ( Check_FIND_REQUIRED )
MESSAGE( FATAL_ERROR "Could NOT find CHECK" )
ELSE ( Check_FIND_REQUIRED )
IF ( NOT Check_FIND_QUIETLY )
MESSAGE( STATUS "Could NOT find CHECK" )
ENDIF ( NOT Check_FIND_QUIETLY )
ENDIF ( Check_FIND_REQUIRED )
ENDIF ( CHECK_INCLUDE_DIR AND CHECK_LIBRARIES )
ENDIF( NOT CHECK_FOUND )
# Hide advanced variables from CMake GUIs
MARK_AS_ADVANCED( CHECK_INCLUDE_DIR CHECK_LIBRARIES )
# Find Libevent
# http://monkey.org/~provos/libevent/
#
# Once done, this will define:
#
# Event_FOUND - system has Event
# Event_INCLUDE_DIRS - the Event include directories
# Event_LIBRARIES - link these to use Event
#
if (EVENT_INCLUDE_DIR AND EVENT_LIBRARY)
# Already in cache, be silent
set(EVENT_FIND_QUIETLY TRUE)
endif (EVENT_INCLUDE_DIR AND EVENT_LIBRARY)
find_path(EVENT_INCLUDE_DIR event.h
PATHS /usr/include
PATH_SUFFIXES event
)
find_library(EVENT_LIBRARY
NAMES event
PATHS /usr/lib /usr/local/lib
)
set(EVENT_LIBRARIES ${EVENT_LIBRARY} )
add_definitions(-DLIBNET_LIL_ENDIAN)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(EVENT
DEFAULT_MSG
EVENT_INCLUDE_DIR
EVENT_LIBRARIES
)
mark_as_advanced(EVENT_INCLUDE_DIR EVENT_LIBRARY)
# - Find freediameter
# Find the native FreeDiameter includes and libraries
#
# FREEDIAMETER_FOUND - True if FreeDiameter found.
# FREEDIAMETER_INCLUDE_DIR - where to find gnutls.h, etc.
# FREEDIAMETER_LIBRARIES - List of libraries when using gnutls.
# FREEDIAMETER_HSS_S6A_ENABLED - true if FreeDiameter enabled for S6A interface
if (FREEDIAMETER_INCLUDE_DIR AND FREEDIAMETER_LIBRARIES)
set(FREEDIAMETER_FIND_QUIETLY TRUE)
endif (FREEDIAMETER_INCLUDE_DIR AND FREEDIAMETER_LIBRARIES)
# Include dir
find_path(FREEDIAMETER_INCLUDE_DIR
NAMES
freeDiameter/freeDiameter-host.h
freeDiameter/libfdcore.h
freeDiameter/libfdproto.h
)
# Library
find_library(FREEDIAMETER_LIBRARY
NAMES fdcore
)
# handle the QUIETLY and REQUIRED arguments and set FREEDIAMETER_FOUND to TRUE if
# all listed variables are TRUE
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(FREEDIAMETER DEFAULT_MSG FREEDIAMETER_LIBRARY FREEDIAMETER_INCLUDE_DIR)
IF(FREEDIAMETER_FOUND)
SET( FREEDIAMETER_LIBRARIES ${FREEDIAMETER_LIBRARY} )
ELSE(FREEDIAMETER_FOUND)
SET( FREEDIAMETER_LIBRARIES )
ENDIF(FREEDIAMETER_FOUND)
find_library(FREEDIAMETER_LIBRARY2
NAMES fdproto
)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(FREEDIAMETER2 DEFAULT_MSG FREEDIAMETER_LIBRARY2 FREEDIAMETER_INCLUDE_DIR)
IF(FREEDIAMETER2_FOUND)
SET( FREEDIAMETER_LIBRARIES ${FREEDIAMETER_LIBRARIES} ${FREEDIAMETER_LIBRARY2} )
ELSE(FREEDIAMETER2_FOUND)
SET( FREEDIAMETER_LIBRARIES )
ENDIF(FREEDIAMETER2_FOUND)
# Lastly make it so that the FREEDIAMETER_LIBRARY and FREEDIAMETER_INCLUDE_DIR variables
# only show up under the advanced options in the gui cmake applications.
MARK_AS_ADVANCED( FREEDIAMETER_LIBRARY FREEDIAMETER_INCLUDE_DIR )
# Now check if the library is patched for OPENAIR HSS S6A.
IF(FREEDIAMETER_FOUND)
IF( FREEDIAMETER_INCLUDE_DIR )
# Extract FD_PROJECT_VERSION_MAJOR, FD_PROJECT_VERSION_MINOR from freeDiameter-host.h
# Read the whole file:
#
FILE(READ "${FREEDIAMETER_INCLUDE_DIR}/freeDiameter/freeDiameter-host.h" _freeDiameter_HOST_H_CONTENTS)
STRING(REGEX REPLACE ".*#define FD_PROJECT_VERSION_MAJOR ([0-9]+).*" "\\1" FD_PROJECT_VERSION_MAJOR "${_freeDiameter_HOST_H_CONTENTS}")
STRING(REGEX REPLACE ".*#define FD_PROJECT_VERSION_MINOR ([0-9]+).*" "\\1" FD_PROJECT_VERSION_MINOR "${_freeDiameter_HOST_H_CONTENTS}")
IF(FD_PROJECT_VERSION_MAJOR GREATER 0)
MATH(EXPR FREEDIAMETER_VERSION_VALUE "${FD_PROJECT_VERSION_MAJOR} * 100 + ${FD_PROJECT_VERSION_MINOR} * 10")
SET(FREEDIAMETER_VERSION "${FREEDIAMETER_VERSION_VALUE}" CACHE INTERNAL "Freediameter release version")
MESSAGE(STATUS "freeDiameter version found ${FREEDIAMETER_VERSION}")
ENDIF(FD_PROJECT_VERSION_MAJOR GREATER 0)
ENDIF( FREEDIAMETER_INCLUDE_DIR )
GET_FILENAME_COMPONENT(FREEDIAMETER_PATH ${FREEDIAMETER_LIBRARY} PATH)
IF( NOT( "${FREEDIAMETER_VERSION_TEST_FOR}" STREQUAL "${FREEDIAMETER_LIBRARIES}" ))
INCLUDE (CheckLibraryExists)
MESSAGE(STATUS "Checking freeDiameter patched for S6A")
UNSET(FREEDIAMETER_HSS_S6A_ENABLED)
UNSET(FREEDIAMETER_HSS_S6A_ENABLED CACHE)
UNSET(DICT_S6A_FOUND)
UNSET(DICT_S6A_FOUND CACHE)
FIND_FILE(DICT_S6A_FOUND NAMES dict_s6a.fdx PATHS ${FREEDIAMETER_PATH} ${FREEDIAMETER_PATH}/freeDiameter)
IF(DICT_S6A_FOUND)
SET( FREEDIAMETER_HSS_S6A_ENABLED TRUE CACHE INTERNAL "dict_s6a.fdx Found")
ELSE(DICT_S6A_FOUND)
SET( FREEDIAMETER_HSS_S6A_ENABLED FALSE CACHE INTERNAL "dict_s6a.fdx not Found")
ENDIF(DICT_S6A_FOUND)
SET( FREEDIAMETER_VERSION_TEST_FOR ${FREEDIAMETER_LIBRARIES} CACHE INTERNAL "Version the test was made against" )
ENDIF (NOT( "${FREEDIAMETER_VERSION_TEST_FOR}" STREQUAL "${FREEDIAMETER_LIBRARIES}" ))
ENDIF(FREEDIAMETER_FOUND)
# FindGCCXML
# ----------
find_program(GCCXML
NAMES gccxml
PATHS "/usr/bin"
"usr/local/bin"
)
mark_as_advanced(GCCXML)
# - Find gnutls
# Find the native GCRYPT includes and library
#
# GCRYPT_FOUND - True if gnutls found.
# GCRYPT_INCLUDE_DIR - where to find gnutls.h, etc.
# GCRYPT_LIBRARIES - List of libraries when using gnutls.
if (GCRYPT_INCLUDE_DIR AND GCRYPT_LIBRARIES)
set(GCRYPT_FIND_QUIETLY TRUE)
endif (GCRYPT_INCLUDE_DIR AND GCRYPT_LIBRARIES)
# Include dir
find_path(GCRYPT_INCLUDE_DIR
NAMES
gcrypt.h
)
# Library
find_library(GCRYPT_LIBRARY
NAMES gcrypt
)
# handle the QUIETLY and REQUIRED arguments and set GCRYPT_FOUND to TRUE if
# all listed variables are TRUE
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(GCRYPT DEFAULT_MSG GCRYPT_LIBRARY GCRYPT_INCLUDE_DIR)
IF(GCRYPT_FOUND)
SET( GCRYPT_LIBRARIES ${GCRYPT_LIBRARY} )
ELSE(GCRYPT_FOUND)
SET( GCRYPT_LIBRARIES )
ENDIF(GCRYPT_FOUND)
# Lastly make it so that the GCRYPT_LIBRARY and GCRYPT_INCLUDE_DIR variables
# only show up under the advanced options in the gui cmake applications.
MARK_AS_ADVANCED( GCRYPT_LIBRARY GCRYPT_INCLUDE_DIR )
# - Find gnutls
# Find the native GNUTLS includes and library
#
# GNUTLS_FOUND - True if gnutls found.
# GNUTLS_INCLUDE_DIR - where to find gnutls.h, etc.
# GNUTLS_LIBRARIES - List of libraries when using gnutls.
# GNUTLS_VERSION_210 - true if GnuTLS version is >= 2.10.0 (does not require additional separate gcrypt initialization)
# GNUTLS_VERSION_212 - true if GnuTLS version is >= 2.12.0 (supports gnutls_transport_set_vec_push_function)
# GNUTLS_VERSION_300 - true if GnuTLS version is >= 3.00.0 (x509 verification functions changed)
# GNUTLS_VERSION_310 - true if GnuTLS version is >= 3.01.0 (stabilization branch with new APIs)
if (GNUTLS_INCLUDE_DIR AND GNUTLS_LIBRARIES)
set(GNUTLS_FIND_QUIETLY TRUE)
endif (GNUTLS_INCLUDE_DIR AND GNUTLS_LIBRARIES)
# Include dir
find_path(GNUTLS_INCLUDE_DIR
NAMES
gnutls.h
gnutls/gnutls.h
)
# Library
find_library(GNUTLS_LIBRARY
NAMES gnutls
)
# handle the QUIETLY and REQUIRED arguments and set GNUTLS_FOUND to TRUE if
# all listed variables are TRUE
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(GNUTLS DEFAULT_MSG GNUTLS_LIBRARY GNUTLS_INCLUDE_DIR)
IF(GNUTLS_FOUND)
SET( GNUTLS_LIBRARIES ${GNUTLS_LIBRARY} )
ELSE(GNUTLS_FOUND)
SET( GNUTLS_LIBRARIES )
ENDIF(GNUTLS_FOUND)
# Lastly make it so that the GNUTLS_LIBRARY and GNUTLS_INCLUDE_DIR variables
# only show up under the advanced options in the gui cmake applications.
MARK_AS_ADVANCED( GNUTLS_LIBRARY GNUTLS_INCLUDE_DIR )
# Now check if the library is recent. gnutls_hash was added in 2.10.0.
# Also test library is even more recent. gnutls_x509_trust_list_verify_crt was added in 3.00.0.
IF(GNUTLS_FOUND)
IF( NOT( "${GNUTLS_VERSION_TEST_FOR}" STREQUAL "${GNUTLS_LIBRARY}" ))
INCLUDE (CheckLibraryExists)
MESSAGE(STATUS "Checking GNUTLS version")
UNSET(GNUTLS_VERSION_210)
UNSET(GNUTLS_VERSION_210 CACHE)
UNSET(GNUTLS_VERSION_212)
UNSET(GNUTLS_VERSION_212 CACHE)
UNSET(GNUTLS_VERSION_300)
UNSET(GNUTLS_VERSION_300 CACHE)
UNSET(GNUTLS_VERSION_310)
UNSET(GNUTLS_VERSION_310 CACHE)
GET_FILENAME_COMPONENT(GNUTLS_PATH ${GNUTLS_LIBRARY} PATH)
CHECK_LIBRARY_EXISTS(gnutls gnutls_hash ${GNUTLS_PATH} GNUTLS_VERSION_210)
CHECK_LIBRARY_EXISTS(gnutls gnutls_transport_set_vec_push_function ${GNUTLS_PATH} GNUTLS_VERSION_212)
CHECK_LIBRARY_EXISTS(gnutls gnutls_x509_trust_list_verify_crt ${GNUTLS_PATH} GNUTLS_VERSION_300)
CHECK_LIBRARY_EXISTS(gnutls gnutls_handshake_set_timeout ${GNUTLS_PATH} GNUTLS_VERSION_310)
SET( GNUTLS_VERSION_TEST_FOR ${GNUTLS_LIBRARY} CACHE INTERNAL "Version the test was made against" )
ENDIF (NOT( "${GNUTLS_VERSION_TEST_FOR}" STREQUAL "${GNUTLS_LIBRARY}" ))
ENDIF(GNUTLS_FOUND)
# - Support for building kernel modules
# This module defines several variables which may be used when build
# kernel modules.
#
# The following variables are set here:
# Kbuild_VERSION_STRING - kernel version.
# Kbuild_ARCH - architecture.
# Kbuild_BUILD_DIR - directory for build kernel and/or its components.
# Kbuild_VERSION_{MAJOR|MINOR|TWEAK} - kernel version components
# Kbuild_VERSION_STRING_CLASSIC - classic representation of version,
# where parts are delimited by dots.
#
# Cache variables which affect on this package:
# CMAKE_SYSTEM_VERSION - change Kbuild_VERSION_STRING
# Also, setting CMAKE_SYSTEM_VERSION will be interpreted by cmake as crosscompile.
#
# Cache variables(ADVANCED) which affect on this package:
# ARCH - if not empty, change Kbuild_ARCH
# KBUILD_DIR - change Kbuild_BUILD_DIR
set(Kbuild_VERSION_STRING ${CMAKE_SYSTEM_VERSION})
# Form classic version view.
string(REGEX MATCH "([0-9]+)\\.([0-9]+)[.-]([0-9]+)"
_kernel_version_match
"${Kbuild_VERSION_STRING}"
)
if(NOT _kernel_version_match)
message(FATAL_ERROR "Kernel version has unexpected format: ${Kbuild_VERSION_STRING}")
endif(NOT _kernel_version_match)
set(Kbuild_VERSION_MAJOR ${CMAKE_MATCH_1})
set(Kbuild_VERSION_MINOR ${CMAKE_MATCH_2})
set(Kbuild_VERSION_TWEAK ${CMAKE_MATCH_3})
# Version string for compare
set(Kbuild_VERSION_STRING_CLASSIC "${Kbuild_VERSION_MAJOR}.${Kbuild_VERSION_MINOR}.${Kbuild_VERSION_TWEAK}")
set(KBUILD_DIR "/lib/modules/${Kbuild_VERSION_STRING}/build" CACHE PATH
"Directory for build linux kernel and/or its components."
)
mark_as_advanced(KBUILD_DIR)
set(Kbuild_BUILD_DIR "${KBUILD_DIR}")
set(ARCH "" CACHE STRING
"Architecture for build linux kernel components for, empty string means autodetect."
)
mark_as_advanced(ARCH)
if(NOT ARCH)
# Autodetect arch.
execute_process(COMMAND uname -m
RESULT_VARIABLE uname_m_result
OUTPUT_VARIABLE ARCH_DEFAULT
)
if(NOT uname_m_result EQUAL 0)
message("'uname -m' failed:")
message("${ARCH_DEFAULT}")
message(FATAL_ERROR "Failed to determine system architecture.")
endif(NOT uname_m_result EQUAL 0)
string(REGEX REPLACE "\n$" "" ARCH_DEFAULT "${ARCH_DEFAULT}")
# Pairs of pattern-replace for postprocess architecture string from
# 'uname -m'.
# Taken from ./Makefile of the kernel build.
set(_kbuild_arch_replacers
"i.86" "x86"
"x86_64" "x86"
"sun4u" "sparc64"
"arm.*" "arm"
"sa110" "arm"
"s390x" "s390"
"parisc64" "parisc"
"ppc.*" "powerpc"
"mips.*" "mips"
"sh[234].*" "sh"
"aarch64.*" "arm64"
)
set(_current_pattern)
foreach(p ${_kbuild_arch_replacers})
if(_current_pattern)
string(REGEX REPLACE "${_current_pattern}" "${p}" ARCH_DEFAULT "${ARCH_DEFAULT}")
set(_current_pattern)
else(_current_pattern)
set(_current_pattern "${p}")
endif(_current_pattern)
endforeach(p ${_kbuild_arch_replacers})
set(Kbuild_ARCH "${ARCH_DEFAULT}")
else(NOT ARCH)
# User-provided value is used.
set(Kbuild_ARCH "${ARCH}")
endif(NOT ARCH)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Kbuild
REQUIRED_VARS Kbuild_BUILD_DIR
VERSION_VAR KBuild_VERSION_STRING_CLASSIC
)
# - Try to find the LibXml2 xml processing library
# Once done this will define
#
# LIBXML2_FOUND - System has LibXml2
# LIBXML2_INCLUDE_DIR - The LibXml2 include directory
# LIBXML2_LIBRARIES - The libraries needed to use LibXml2
# LIBXML2_DEFINITIONS - Compiler switches required for using LibXml2
# LIBXML2_XMLLINT_EXECUTABLE - The XML checking tool xmllint coming with LibXml2
#=============================================================================
# Copyright 2006-2009 Kitware, Inc.
# Copyright 2006 Alexander Neundorf <neundorf@kde.org>
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# See the License for more information.
#=============================================================================
# (To distributed this file outside of CMake, substitute the full
# License text for the above reference.)
# use pkg-config to get the directories and then use these values
# in the FIND_PATH() and FIND_LIBRARY() calls
FIND_PACKAGE(PkgConfig)
PKG_CHECK_MODULES(PC_LIBXML libxml-2.0)
SET(LIBXML2_DEFINITIONS ${PC_LIBXML_CFLAGS_OTHER})
FIND_PATH(LIBXML2_INCLUDE_DIR NAMES libxml/xpath.h
HINTS
${PC_LIBXML_INCLUDEDIR}
${PC_LIBXML_INCLUDE_DIRS}
PATH_SUFFIXES libxml2
)
FIND_LIBRARY(LIBXML2_LIBRARIES NAMES xml2 libxml2
HINTS
${PC_LIBXML_LIBDIR}
${PC_LIBXML_LIBRARY_DIRS}
)
FIND_PROGRAM(LIBXML2_XMLLINT_EXECUTABLE xmllint)
# for backwards compat. with KDE 4.0.x:
SET(XMLLINT_EXECUTABLE "${LIBXML2_XMLLINT_EXECUTABLE}")
# handle the QUIETLY and REQUIRED arguments and set LIBXML2_FOUND to TRUE if
# all listed variables are TRUE
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibXml2 DEFAULT_MSG LIBXML2_LIBRARIES LIBXML2_INCLUDE_DIR)
MARK_AS_ADVANCED(LIBXML2_INCLUDE_DIR LIBXML2_LIBRARIES LIBXML2_XMLLINT_EXECUTABLE)
# - Find mysqlclient
#
# -*- cmake -*-
#
# Find the native MySQL includes and library
#
# MySQL_INCLUDE_DIR - where to find mysql.h, etc.
# MySQL_LIBRARIES - List of libraries when using MySQL.
# MySQL_FOUND - True if MySQL found.
IF (MySQL_INCLUDE_DIR AND MySQL_LIBRARY)
# Already in cache, be silent
SET(MySQL_FIND_QUIETLY TRUE)
ENDIF (MySQL_INCLUDE_DIR AND MySQL_LIBRARY)
# Include dir
FIND_PATH(MySQL_INCLUDE_DIR
NAMES mysql.h
PATH_SUFFIXES mysql
)
# Library
#SET(MySQL_NAMES mysqlclient mysqlclient_r)
SET(MySQL_NAMES mysqlclient)
FIND_LIBRARY(MySQL_LIBRARY
NAMES ${MySQL_NAMES}
PATHS /usr/lib /usr/local/lib
PATH_SUFFIXES mysql
)
IF (MySQL_INCLUDE_DIR AND MySQL_LIBRARY)
SET(MySQL_FOUND TRUE)
SET( MySQL_LIBRARIES ${MySQL_LIBRARY} )
ELSE (MySQL_INCLUDE_DIR AND MySQL_LIBRARY)
SET(MySQL_FOUND FALSE)
SET( MySQL_LIBRARIES )
ENDIF (MySQL_INCLUDE_DIR AND MySQL_LIBRARY)
IF (MySQL_FOUND)
IF (NOT MySQL_FIND_QUIETLY)
MESSAGE(STATUS "Found MySQL: ${MySQL_LIBRARY}")
ENDIF (NOT MySQL_FIND_QUIETLY)
ELSE (MySQL_FOUND)
IF (MySQL_FIND_REQUIRED)
MESSAGE(STATUS "Looked for MySQL libraries named ${MySQL_NAMES}.")
MESSAGE(FATAL_ERROR "Could NOT find MySQL library")
ENDIF (MySQL_FIND_REQUIRED)
ENDIF (MySQL_FOUND)
MARK_AS_ADVANCED(
MySQL_LIBRARY
MySQL_INCLUDE_DIR
)
# Find the native Nettle includes, library, and flags
#
# NETTLE_INCLUDE_DIR - where to find nettle.h, etc.
# NETTLE_LIBRARIES - List of libraries when using Nettle.
# NETTLE_FOUND - True if Nettle found.
IF (NETTLE_INCLUDE_DIR)
# Already in cache, be silent
SET(NETTLE_FIND_QUIETLY TRUE)
ENDIF (NETTLE_INCLUDE_DIR)
FIND_PATH(NETTLE_INCLUDE_DIR nettle/nettle-meta.h)
SET(NETTLE_NAMES nettle)
FIND_LIBRARY(NETTLE_LIBRARY NAMES ${NETTLE_NAMES} )
# handle the QUIETLY and REQUIRED arguments and set NETTLE_FOUND to TRUE if
# all listed variables are TRUE
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(NETTLE DEFAULT_MSG NETTLE_LIBRARY NETTLE_INCLUDE_DIR)
IF(NETTLE_FOUND)
SET(NETTLE_LIBRARIES ${NETTLE_LIBRARY})
ELSE(NETTLE_FOUND)
SET(NETTLE_LIBRARIES )
ENDIF(NETTLE_FOUND)
MARK_AS_ADVANCED(NETTLE_LIBRARY NETTLE_INCLUDE_DIR)
# - Find PostgreSQL library
#
# This module defines:
# POSTGRESQL_FOUND - True if the package is found
# POSTGRESQL_INCLUDE_DIR - containing libpq-fe.h
# POSTGRESQL_LIBRARIES - Libraries to link to use PQ functions.
if (POSTGRESQL_INCLUDE_DIR AND POSTGRESQL_LIBRARIES)
set(POSTGRESQL_FIND_QUIETLY TRUE)
endif (POSTGRESQL_INCLUDE_DIR AND POSTGRESQL_LIBRARIES)
# Include dir
find_path(POSTGRESQL_INCLUDE_DIR
NAMES libpq-fe.h
PATH_SUFFIXES pgsql postgresql
)
# Library
find_library(POSTGRESQL_LIBRARY
NAMES pq
)
# handle the QUIETLY and REQUIRED arguments and set POSTGRESQL_FOUND to TRUE if
# all listed variables are TRUE
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(POSTGRESQL DEFAULT_MSG POSTGRESQL_LIBRARY POSTGRESQL_INCLUDE_DIR)
IF(POSTGRESQL_FOUND)
SET( POSTGRESQL_LIBRARIES ${POSTGRESQL_LIBRARY} )
ELSE(POSTGRESQL_FOUND)
SET( POSTGRESQL_LIBRARIES )
ENDIF(POSTGRESQL_FOUND)
# Lastly make it so that the POSTGRESQL_LIBRARY and POSTGRESQL_INCLUDE_DIR variables
# only show up under the advanced options in the gui cmake applications.
MARK_AS_ADVANCED( POSTGRESQL_LIBRARY POSTGRESQL_INCLUDE_DIR )
# - Try to find SCTP library and headers
# Once done, this will define
#
# SCTP_FOUND - system has SCTP
# SCTP_INCLUDE_DIR - the SCTP include directories
# SCTP_LIBRARIES - link these to use SCTP
if (SCTP_INCLUDE_DIR AND SCTP_LIBRARIES)
set(SCTP_FIND_QUIETLY TRUE)
endif (SCTP_INCLUDE_DIR AND SCTP_LIBRARIES)
# Include dir
find_path(SCTP_INCLUDE_DIR
NAMES netinet/sctp.h
)
# Library
find_library(SCTP_LIBRARY
NAMES sctp
)
# Set the include dir variables and the libraries and let libfind_process do the rest.
# NOTE: Singular variables for this library, plural for libraries this this lib depends on.
#set(SCTP_PROCESS_INCLUDES SCTP_INCLUDE_DIR)
#set(SCTP_PROCESS_LIBS SCTP_LIBRARY)
#libfind_process(SCTP)
# handle the QUIETLY and REQUIRED arguments and set SCTP_FOUND to TRUE if
# all listed variables are TRUE
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SCTP DEFAULT_MSG SCTP_LIBRARY SCTP_INCLUDE_DIR)
# If we successfully found the sctp library then add the library to the
# SCTP_LIBRARIES cmake variable otherwise set SCTP_LIBRARIES to nothing.
IF(SCTP_FOUND)
SET( SCTP_LIBRARIES ${SCTP_LIBRARY} )
ELSE(SCTP_FOUND)
SET( SCTP_LIBRARIES )
ENDIF(SCTP_FOUND)
# Lastly make it so that the SCTP_LIBRARY and SCTP_INCLUDE_DIR variables
# only show up under the advanced options in the gui cmake applications.
MARK_AS_ADVANCED( SCTP_LIBRARY SCTP_INCLUDE_DIR )
# Updated FindThreads.cmake that supports pthread-win32
# Downloaded from http://www.vtk.org/Bug/bug_view_advanced_page.php?bug_id=6399
# - This module determines the thread library of the system.
#
# The following variables are set
# CMAKE_THREAD_LIBS_INIT - the thread library
# CMAKE_USE_SPROC_INIT - are we using sproc?
# CMAKE_USE_WIN32_THREADS_INIT - using WIN32 threads?
# CMAKE_USE_PTHREADS_INIT - are we using pthreads
# CMAKE_HP_PTHREADS_INIT - are we using hp pthreads
#
# If use of pthreads-win32 is desired, the following variables
# can be set.
#
# THREADS_USE_PTHREADS_WIN32 -
# Setting this to true searches for the pthreads-win32
# port (since CMake 2.8.0)
#
# THREADS_PTHREADS_WIN32_EXCEPTION_SCHEME
# C = no exceptions (default)
# (NOTE: This is the default scheme on most POSIX thread
# implementations and what you should probably be using)
# CE = C++ Exception Handling
# SE = Structure Exception Handling (MSVC only)
# (NOTE: Changing this option from the default may affect
# the portability of your application. See pthreads-win32
# documentation for more details.)
#
#======================================================
# Example usage where threading library
# is provided by the system:
#
# find_package(Threads REQUIRED)
# add_executable(foo foo.cc)
# target_link_libraries(foo ${CMAKE_THREAD_LIBS_INIT})
#
# Example usage if pthreads-win32 is desired on Windows
# or a system provided thread library:
#
# set(THREADS_USE_PTHREADS_WIN32 true)
# find_package(Threads REQUIRED)
# include_directories(${THREADS_PTHREADS_INCLUDE_DIR})
#
# add_executable(foo foo.cc)
# target_link_libraries(foo ${CMAKE_THREAD_LIBS_INIT})
#
INCLUDE (CheckIncludeFiles)
INCLUDE (CheckLibraryExists)
SET(Threads_FOUND FALSE)
IF(WIN32 AND NOT CYGWIN AND THREADS_USE_PTHREADS_WIN32)
SET(_Threads_ptwin32 true)
ENDIF()
# Do we have sproc?
IF(CMAKE_SYSTEM MATCHES IRIX)
CHECK_INCLUDE_FILES("sys/types.h;sys/prctl.h" CMAKE_HAVE_SPROC_H)
ENDIF()
IF(CMAKE_HAVE_SPROC_H)
# We have sproc
SET(CMAKE_USE_SPROC_INIT 1)
ELSEIF(_Threads_ptwin32)
IF(NOT DEFINED THREADS_PTHREADS_WIN32_EXCEPTION_SCHEME)
# Assign the default scheme
SET(THREADS_PTHREADS_WIN32_EXCEPTION_SCHEME "C")
ELSE()
# Validate the scheme specified by the user
IF(NOT THREADS_PTHREADS_WIN32_EXCEPTION_SCHEME STREQUAL "C" AND
NOT THREADS_PTHREADS_WIN32_EXCEPTION_SCHEME STREQUAL "CE" AND
NOT THREADS_PTHREADS_WIN32_EXCEPTION_SCHEME STREQUAL "SE")
MESSAGE(FATAL_ERROR "See documentation for FindPthreads.cmake, only C, CE, and SE modes are allowed")
ENDIF()
IF(NOT MSVC AND THREADS_PTHREADS_WIN32_EXCEPTION_SCHEME STREQUAL "SE")
MESSAGE(FATAL_ERROR "Structured Exception Handling is only allowed for MSVC")
ENDIF(NOT MSVC AND THREADS_PTHREADS_WIN32_EXCEPTION_SCHEME STREQUAL "SE")
ENDIF()
FIND_PATH(THREADS_PTHREADS_INCLUDE_DIR pthread.h)
# Determine the library filename
IF(MSVC)
SET(_Threads_pthreads_libname
pthreadV${THREADS_PTHREADS_WIN32_EXCEPTION_SCHEME}2)
ELSEIF(MINGW)
SET(_Threads_pthreads_libname
pthreadG${THREADS_PTHREADS_WIN32_EXCEPTION_SCHEME}2)
ELSE()
MESSAGE(FATAL_ERROR "This should never happen")
ENDIF()
# Use the include path to help find the library if possible
SET(_Threads_lib_paths "")
IF(THREADS_PTHREADS_INCLUDE_DIR)
GET_FILENAME_COMPONENT(_Threads_root_dir
${THREADS_PTHREADS_INCLUDE_DIR} PATH)
SET(_Threads_lib_paths ${_Threads_root_dir}/lib)
ENDIF()
FIND_LIBRARY(THREADS_PTHREADS_WIN32_LIBRARY
NAMES ${_Threads_pthreads_libname}
PATHS ${_Threads_lib_paths}
DOC "The Portable Threads Library for Win32"
NO_SYSTEM_PATH
)
IF(THREADS_PTHREADS_INCLUDE_DIR AND THREADS_PTHREADS_WIN32_LIBRARY)
MARK_AS_ADVANCED(THREADS_PTHREADS_INCLUDE_DIR)
SET(CMAKE_THREAD_LIBS_INIT ${THREADS_PTHREADS_WIN32_LIBRARY})
SET(CMAKE_HAVE_THREADS_LIBRARY 1)
SET(Threads_FOUND TRUE)
ENDIF()
MARK_AS_ADVANCED(THREADS_PTHREADS_WIN32_LIBRARY)
ELSE()
# Do we have pthreads?
CHECK_INCLUDE_FILES("pthread.h" CMAKE_HAVE_PTHREAD_H)
IF(CMAKE_HAVE_PTHREAD_H)
#
# We have pthread.h
# Let's check for the library now.
#
SET(CMAKE_HAVE_THREADS_LIBRARY)
IF(NOT THREADS_HAVE_PTHREAD_ARG)
# Do we have -lpthreads
CHECK_LIBRARY_EXISTS(pthreads pthread_create "" CMAKE_HAVE_PTHREADS_CREATE)
IF(CMAKE_HAVE_PTHREADS_CREATE)
SET(CMAKE_THREAD_LIBS_INIT "-lpthreads")
SET(CMAKE_HAVE_THREADS_LIBRARY 1)
SET(Threads_FOUND TRUE)
ENDIF()
# Ok, how about -lpthread
CHECK_LIBRARY_EXISTS(pthread pthread_create "" CMAKE_HAVE_PTHREAD_CREATE)
IF(CMAKE_HAVE_PTHREAD_CREATE)
SET(CMAKE_THREAD_LIBS_INIT "-lpthread")
SET(Threads_FOUND TRUE)
SET(CMAKE_HAVE_THREADS_LIBRARY 1)
ENDIF()
IF(CMAKE_SYSTEM MATCHES "SunOS.*")
# On sun also check for -lthread
CHECK_LIBRARY_EXISTS(thread thr_create "" CMAKE_HAVE_THR_CREATE)
IF(CMAKE_HAVE_THR_CREATE)
SET(CMAKE_THREAD_LIBS_INIT "-lthread")
SET(CMAKE_HAVE_THREADS_LIBRARY 1)
SET(Threads_FOUND TRUE)
ENDIF()
ENDIF(CMAKE_SYSTEM MATCHES "SunOS.*")
ENDIF(NOT THREADS_HAVE_PTHREAD_ARG)
IF(NOT CMAKE_HAVE_THREADS_LIBRARY)
# If we did not found -lpthread, -lpthread, or -lthread, look for -pthread
IF("THREADS_HAVE_PTHREAD_ARG" MATCHES "^THREADS_HAVE_PTHREAD_ARG")
MESSAGE(STATUS "Check if compiler accepts -pthread")
TRY_RUN(THREADS_PTHREAD_ARG THREADS_HAVE_PTHREAD_ARG
${CMAKE_BINARY_DIR}
${CMAKE_ROOT}/Modules/CheckForPthreads.c
CMAKE_FLAGS -DLINK_LIBRARIES:STRING=-pthread
COMPILE_OUTPUT_VARIABLE OUTPUT)
IF(THREADS_HAVE_PTHREAD_ARG)
IF(THREADS_PTHREAD_ARG MATCHES "^2$")
SET(Threads_FOUND TRUE)
MESSAGE(STATUS "Check if compiler accepts -pthread - yes")
ELSE()
MESSAGE(STATUS "Check if compiler accepts -pthread - no")
FILE(APPEND
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
"Determining if compiler accepts -pthread returned ${THREADS_PTHREAD_ARG} instead of 2. The compiler had the following output:\n${OUTPUT}\n\n")
ENDIF()
ELSE()
MESSAGE(STATUS "Check if compiler accepts -pthread - no")
FILE(APPEND
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
"Determining if compiler accepts -pthread failed with the following output:\n${OUTPUT}\n\n")
ENDIF()
ENDIF("THREADS_HAVE_PTHREAD_ARG" MATCHES "^THREADS_HAVE_PTHREAD_ARG")
IF(THREADS_HAVE_PTHREAD_ARG)
SET(Threads_FOUND TRUE)
SET(CMAKE_THREAD_LIBS_INIT "-pthread")
ENDIF()
ENDIF(NOT CMAKE_HAVE_THREADS_LIBRARY)
ENDIF(CMAKE_HAVE_PTHREAD_H)
ENDIF()
IF(CMAKE_THREAD_LIBS_INIT)
SET(CMAKE_USE_PTHREADS_INIT 1)
SET(Threads_FOUND TRUE)
ENDIF()
IF(CMAKE_SYSTEM MATCHES "Windows"
AND NOT THREADS_USE_PTHREADS_WIN32)
SET(CMAKE_USE_WIN32_THREADS_INIT 1)
SET(Threads_FOUND TRUE)
ENDIF()
IF(CMAKE_USE_PTHREADS_INIT)
IF(CMAKE_SYSTEM MATCHES "HP-UX-*")
# Use libcma if it exists and can be used. It provides more
# symbols than the plain pthread library. CMA threads
# have actually been deprecated:
# http://docs.hp.com/en/B3920-90091/ch12s03.html#d0e11395
# http://docs.hp.com/en/947/d8.html
# but we need to maintain compatibility here.
# The CMAKE_HP_PTHREADS setting actually indicates whether CMA threads
# are available.
CHECK_LIBRARY_EXISTS(cma pthread_attr_create "" CMAKE_HAVE_HP_CMA)
IF(CMAKE_HAVE_HP_CMA)
SET(CMAKE_THREAD_LIBS_INIT "-lcma")
SET(CMAKE_HP_PTHREADS_INIT 1)
SET(Threads_FOUND TRUE)
ENDIF(CMAKE_HAVE_HP_CMA)
SET(CMAKE_USE_PTHREADS_INIT 1)
ENDIF()
IF(CMAKE_SYSTEM MATCHES "OSF1-V*")
SET(CMAKE_USE_PTHREADS_INIT 0)
SET(CMAKE_THREAD_LIBS_INIT )
ENDIF()
IF(CMAKE_SYSTEM MATCHES "CYGWIN_NT*")
SET(CMAKE_USE_PTHREADS_INIT 1)
SET(Threads_FOUND TRUE)
SET(CMAKE_THREAD_LIBS_INIT )
SET(CMAKE_USE_WIN32_THREADS_INIT 0)
ENDIF()
ENDIF(CMAKE_USE_PTHREADS_INIT)
INCLUDE(FindPackageHandleStandardArgs)
IF(_Threads_ptwin32)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Threads DEFAULT_MSG
THREADS_PTHREADS_WIN32_LIBRARY THREADS_PTHREADS_INCLUDE_DIR)
ELSE()
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Threads DEFAULT_MSG Threads_FOUND)
ENDIF()
src=${dir}
obj-m += ${name}.o
${name}-y += ${objs}
ccflags-y += ${module_cc_opt}
# Create rule for obtain one file by copying another one
function(rule_copy_file target_file source_file)
add_custom_command(OUTPUT ${target_file}
COMMAND cp -p ${source_file} ${target_file}
DEPENDS ${source_file}
)
endfunction(rule_copy_file target_file source_file)
# rule_copy_source([source_dir] file ...)
#
# Create rule for obtain file(s) in binary tree by copiing it from source tree.
#
# Files are given relative to ${source_dir}, if it is set, or
# relative to ${CMAKE_CURRENT_SOURCE_DIR}.
#
# Files will be copied into ${CMAKE_CURRENT_BINARY_DIR} with same
# relative paths.
#
# ${source_dir} should be absolute path(that is, starts from '/').
# Otherwise first argument is treated as first file to copy.
function(rule_copy_source file)
string(REGEX MATCH "^/" is_abs_path ${file})
if(is_abs_path)
set(source_dir ${file})
set(files ${ARGN})
else(is_abs_path)
set(source_dir ${CMAKE_CURRENT_SOURCE_DIR})
set(files ${file} ${ARGN})
endif(is_abs_path)
foreach(file_real ${files})
rule_copy_file("${CMAKE_CURRENT_BINARY_DIR}/${file_real}"
${source_dir}/${file_real})
endforeach(file_real ${files})
endfunction(rule_copy_source file)
# to_abs_path(output_var path [...])
#
# Convert relative path of file to absolute path:
# use path in source tree, if file already exist there.
# otherwise use path in binary tree.
# If initial path already absolute, return it.
function(to_abs_path output_var)
set(result)
foreach(path ${ARGN})
string(REGEX MATCH "^/" _is_abs_path ${path})
if(_is_abs_path)
list(APPEND result ${path})
else(_is_abs_path)
file(GLOB to_abs_path_file
"${CMAKE_CURRENT_SOURCE_DIR}/${path}"
)
if(NOT to_abs_path_file)
set (to_abs_path_file "${CMAKE_CURRENT_BINARY_DIR}/${path}")
endif(NOT to_abs_path_file)
list(APPEND result ${to_abs_path_file})
endif(_is_abs_path)
endforeach(path ${ARGN})
set("${output_var}" ${result} PARENT_SCOPE)
endfunction(to_abs_path output_var path)
# is_path_inside_dir(output_var dir path)
#
# Set output_var to true if path is absolute path inside given directory.
# NOTE: Path should be absolute.
macro(is_path_inside_dir output_var dir path)
file(RELATIVE_PATH _rel_path ${dir} ${path})
string(REGEX MATCH "^\\.\\." _is_not_inside_dir ${_rel_path})
if(_is_not_inside_dir)
set(${output_var} "FALSE")
else(_is_not_inside_dir)
set(${output_var} "TRUE")
endif(_is_not_inside_dir)
endmacro(is_path_inside_dir output_var dir path)
# Write given content to the file.
#
# If file is already exists and its content is same as written one, file
# is not rewritten, so its write timestamp remains unchanged.
function(file_update filename content)
if(EXISTS "${filename}")
file(READ "${filename}" old_content)
if(old_content STREQUAL "${content}")
return()
endif(old_content STREQUAL "${content}")
endif(EXISTS "${filename}")
# File doesn't exists or its content differ.
file(WRITE "${filename}" "${content}")
endfunction(file_update filename content)
# Write given content to the file in APPEND mode.
#
# For append we use position variable <pos> which should be initialized
# to 0 for every new build process and which is updated every time when
# this function is called.
# If file is already exists and its content at given <pos> is same as
# written one, file is not rewritten, so its write timestamp remains unchanged.
#
# Note, that file will not be rewritten if new build process issues less
# APPEND actions than one which create file.
# But similar problem exists for file_update() and even for built-in
# configure_file() command: file will not be removed if new build process
# do not call configure_file() for it.
function(file_update_append filename content POS)
set(pos "${${POS}}")
string(LENGTH "${content}" len)
# Update output variable first.
# This allows to use return() when need not to do anything
math(EXPR pos_new "${pos}+${len}")
set(${POS} "${pos_new}" PARENT_SCOPE)
if(EXISTS "${filename}")
file(READ "${filename}" old_content LIMIT "${len}" OFFSET "${pos}")
if(old_content STREQUAL "${content}")
return()
elseif(old_content STREQUAL "")
file(APPEND "${filename}" "${content}")
return()
endif(old_content STREQUAL "${content}")
else(EXISTS "${filename}")
if(NOT pos EQUAL 0)
message(FATAL_ERROR "Appending to non-zero position to non-existent file.")
endif(NOT pos EQUAL 0)
endif(EXISTS "${filename}")
# File doesn't exists or its content differ.
if(NOT pos EQUAL 0)
file(READ "${filename}" prefix LIMIT "${pos}")
else(NOT pos EQUAL 0)
set(prefix)
endif(NOT pos EQUAL 0)
file(WRITE "${filename}" "${prefix}${content}")
endfunction(file_update_append filename content POS)
# Common mechanism for output status message
# when checking different aspects.
#
# Normal using:
#
# check_begin("Checking <...>")
# if(NOT <check-already-has-been-done>)
# check_try() # Here message is printed
# # Perform check(try_compile(), etc.)
# endif(NOT <check-already-has-been-done>)
# check_end("<check-result>") # Here message is printed with result.
# Should be called (unconditionally) when new cheking is issued.
# Note, that given @status_msg is not printed at that step.
function(check_begin status_msg)
set(_check_status_msg ${status_msg} PARENT_SCOPE)
set(_check_has_tries PARENT_SCOPE)
endfunction(check_begin status_msg)
# Should be called before every real checking, that is which is not come
# from cache variables comparision.
#
# First call of that function is trigger printing of @status_msg,
# passed to check_begin().
function(check_try)
if(NOT _check_has_tries)
message(STATUS "${_check_status_msg}")
set(_check_has_tries "1" PARENT_SCOPE)
endif(NOT _check_has_tries)
endfunction(check_try)
# Should be called when cheking is end, and @result_msg should be short
# description of check result.
# If any check_try() has been issued before,
# "@status_msg - @result_msg"
# will be printed.
# Otherwise,
# "@status_msg - [cached] @result_msg"
# will be printed, at it will be the only message for that check.
function(check_end result_msg)
if(NOT _check_has_tries)
message(STATUS "${_check_status_msg} [cached] - ${result_msg}")
else(NOT _check_has_tries)
message(STATUS "${_check_status_msg} - ${result_msg}")
endif(NOT _check_has_tries)
set(_check_status_msg PARENT_SCOPE)
set(_check_has_tries PARENT_SCOPE)
endfunction(check_end result_msg)
# set_bool_string(var true_string false_string value [CACHE ... | PARENT_SCOPE])
#
# Set variable to one of two string according to true property of some value.
#
# If 'value' is true-evaluated, 'var' will be set to 'true_string',
# otherwise to 'var' will be set to 'false_string'.
# Like standard set(), macro accept CACHE and PARENT_SCOPE modifiers.
#
# Useful for form meaningful value for cache variables, contained result
# of some operation.
# Also may be used for form message for check_end().
macro(set_bool_string var true_string false_string value)
# Macro parameters are not a variables, so them cannot be tested
# using 'if(value)'.
# Usage 'if(${value})' leads to warnings since 2.6.4 when ${val}
# is boolean constant
# (because until 2.6.4 'if(value)' always dereference val).
# So copy 'value' to local variable for test it.
set(_set_bool_string_value ${value})
if(_set_bool_string_value)
set(${var} "${true_string}" ${ARGN})
else()
set(${var} "${false_string}" ${ARGN})
endif()
endmacro(set_bool_string)
# set_zero_string(var true_string false_string value [CACHE ... | PARENT_SCOPE])
#
# Set variable to one of two string according to zero property of some value.
#
# If 'value' is '0' (presizely), 'var' will be set to 'zero_string',
# otherwise to 'var' will be set to 'nonzero_string'.
# Like standard set(), macro accept CACHE and PARENT_SCOPE modifiers.
#
# Useful for form meaningful value for cache variables, contained result
# of execute_process().
# Also may be used for form message for check_end().
macro(set_zero_string var zero_string nonzero_string value)
set(_set_zero_string_value ${value})
if(_set_zero_string_value EQUAL "0")
set(${var} ${zero_string} ${ARGN})
else()
set(${var} ${nonzero_string} ${ARGN})
endif()
endmacro(set_zero_string)
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
# Declare variables for path prefixes for different types of files.
# NB: depends on 'multi_kernel' and 'uninstall_target'.
# fill_install_prefixes(<project_name> <project_prefix>
# [BASE_INSTALL_PREFIX <base_install_prefix>]
# [KERNEL]
# )
#
# Setup variables <project_prefix>_* to the install prefixes for
# different project components.
# Precisely, variables with next sufficies are set:
# INSTALL_PREFIX_EXEC - executables
# INSTALL_PREFIX_READONLY - readonly files
# INSTALL_PREFIX_GLOBAL_CONF - global configuration files
# INSTALL_PREFIX_PREFIX_LIB - libraries
# INSTALL_INCLUDE_DIR - include directory(for flags to compiler)
# INSTALL_PREFIX_INCLUDE - include files
# INSTALL_PREFIX_TEMP_SESSION - temporary files(exists until system restarts)
# INSTALL_PREFIX_TEMP - temporary files(preserved even when system restats)
# INSTALL_PREFIX_STATE - files which describe current state of the project.
# INSTALL_PREFIX_CACHE - cache files
# INSTALL_PREFIX_VAR - other modifiable files
# INSTALL_PREFIX_DOC - documentation files
# INSTALL_PREFIX_EXAMPLES - documentation files
#
# With 'KERNEL' option enabled paths for kernel-related files also set:
# INSTALL_KINCLUDE_DIR - directory for include when build kernel components
# INSTALL_PREFIX_KINCLUDE - include files for the kernel.
#
# Additionally, with 'KERNEL' option enabled, several variables are set to
# paths, which contains "%kernel%" pattern.
# These paths are intended for kernel-dependent files; for make paths
# complete one should replace "%kernel%" substring with version of the
# kernel.
# Next kernel-dependend paths are set(sufficies only):
# KERNEL_INSTALL_PREFIX_KMODULE - directory for install kernel modules
# KERNEL_INSTALL_PREFIX_KSYMVERS - directory for install kernel modules' symvers files.
# KERNEL_INSTALL_INCLUDE_KERNEL_DIR - include directory with kernel-dependent headers.
# KERNEL_INSTALL_PREFIX_INCLUDE_KERNEL - include files, which depends from kernel.
#
# Iff option 'COMMON_INSTALL_PREFIX' is given, all paths above are
# calculated using <base_install_prefix> as base prefix.
# Otherwise, CMAKE_INSTALL_PREFIX is used for that purpose.
#
# Additionally,
# INSTALL_TYPE
# variable(suffix) is set to one of:
# - "GLOBAL_OPT" - install into "/opt",
# - "GLOBAL" - global installation except one into "/opt",
# - "LOCAL" - local installation.
function(fill_install_prefixes project_name project_prefix)
cmake_parse_arguments(fip "KERNEL" "BASE_INSTALL_PREFIX" "" ${ARGN})
if(fip_UNPARSED_ARGUMENTS)
list(GET fip_UNPARSED_ARGUMENTS 0 exceeded_arg)
message(SEND_ERROR "Exceeded argument: ${exceeded_arg}")
endif(fip_UNPARSED_ARGUMENTS)
if(NOT fip_BASE_INSTALL_PREFIX)
set(fip_BASE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
endif(NOT fip_BASE_INSTALL_PREFIX)
# Follow conventions about paths listed in
# devel-docs/general/path_conventions.txt
# in kedr-devel package.
# Determine type of installation
if(fip_BASE_INSTALL_PREFIX MATCHES "^/opt")
set(fip_INSTALL_TYPE "GLOBAL_OPT")
elseif(fip_BASE_INSTALL_PREFIX MATCHES "^/usr"
OR fip_BASE_INSTALL_PREFIX STREQUAL "/"
)
set(fip_INSTALL_TYPE "GLOBAL")
else()
set(fip_INSTALL_TYPE "LOCAL")
endif()
# 1
if(fip_INSTALL_TYPE STREQUAL "GLOBAL_OPT")
set(fip_INSTALL_PREFIX_EXEC "/opt/${project_name}/bin")
else(fip_INSTALL_TYPE STREQUAL "GLOBAL_OPT")
set(fip_INSTALL_PREFIX_EXEC "${fip_BASE_INSTALL_PREFIX}/bin")
endif(fip_INSTALL_TYPE STREQUAL "GLOBAL_OPT")
# 2
set(fip_INSTALL_PREFIX_EXEC_AUX
"${fip_BASE_INSTALL_PREFIX}/lib/${project_name}"
)
# 3
set(fip_INSTALL_PREFIX_READONLY
"${fip_BASE_INSTALL_PREFIX}/share/${project_name}"
)
# 4
set(fip_INSTALL_PREFIX_MANPAGE
"${fip_BASE_INSTALL_PREFIX}/share/man"
)
# 5
if(fip_INSTALL_TYPE STREQUAL "GLOBAL_OPT")
set(fip_INSTALL_PREFIX_GLOBAL_CONF "/etc/opt/${project_name}")
elseif(fip_INSTALL_TYPE STREQUAL "GLOBAL")
set(fip_INSTALL_PREFIX_GLOBAL_CONF "/etc/${project_name}")
else(fip_INSTALL_TYPE STREQUAL "GLOBAL_OPT")
set(fip_INSTALL_PREFIX_GLOBAL_CONF
"${fip_BASE_INSTALL_PREFIX}/etc/${project_name}"
)
endif(fip_INSTALL_TYPE STREQUAL "GLOBAL_OPT")
# 6
set(fip_INSTALL_PREFIX_LIB "${fip_BASE_INSTALL_PREFIX}/lib")
# 7
set(fip_INSTALL_PREFIX_LIB_AUX
"${fip_BASE_INSTALL_PREFIX}/lib/${project_name}"
)
# 8
set(fip_INSTALL_INCLUDE_DIR "${fip_BASE_INSTALL_PREFIX}/include")
set(fip_INSTALL_PREFIX_INCLUDE
"${fip_INSTALL_INCLUDE_DIR}/${project_name}"
)
# 9
set(fip_INSTALL_PREFIX_TEMP_SESSION "/tmp/${project_name}")
# 10
if(fip_INSTALL_TYPE MATCHES "GLOBAL")
set(fip_INSTALL_PREFIX_TEMP "/var/tmp/${project_name}")
else(fip_INSTALL_TYPE MATCHES "GLOBAL")
set(fip_INSTALL_PREFIX_TEMP
"${fip_BASE_INSTALL_PREFIX}/var/tmp/${project_name}"
)
endif(fip_INSTALL_TYPE MATCHES "GLOBAL")
# 11
if(fip_INSTALL_TYPE STREQUAL "GLOBAL_OPT")
set(fip_INSTALL_PREFIX_STATE
"/var/opt/${project_name}/lib/${project_name}"
)
elseif(fip_INSTALL_TYPE STREQUAL "GLOBAL")
set(fip_INSTALL_PREFIX_STATE "/var/lib/${project_name}")
else(fip_INSTALL_TYPE STREQUAL "GLOBAL")
set(fip_INSTALL_PREFIX_STATE
"${fip_BASE_INSTALL_PREFIX}/var/lib/${project_name}"
)
endif(fip_INSTALL_TYPE STREQUAL "GLOBAL_OPT")
# 12
if(fip_INSTALL_TYPE STREQUAL "GLOBAL_OPT")
set(fip_INSTALL_PREFIX_CACHE
"/var/opt/${project_name}/cache/${project_name}"
)
elseif(fip_INSTALL_TYPE STREQUAL "GLOBAL")
set(fip_INSTALL_PREFIX_CACHE "/var/cache/${project_name}")
else(fip_INSTALL_TYPE STREQUAL "GLOBAL_OPT")
set(fip_INSTALL_PREFIX_CACHE
"${fip_BASE_INSTALL_PREFIX}/var/cache/${project_name}"
)
endif(fip_INSTALL_TYPE STREQUAL "GLOBAL_OPT")
# 13
if(fip_INSTALL_TYPE MATCHES "GLOBAL")
set(fip_INSTALL_PREFIX_VAR "/var/opt/${project_name}")
else(fip_INSTALL_TYPE MATCHES "GLOBAL")
set(fip_INSTALL_PREFIX_VAR
"${fip_BASE_INSTALL_PREFIX}/var/${project_name}"
)
endif(fip_INSTALL_TYPE MATCHES "GLOBAL")
# 14
set(fip_INSTALL_PREFIX_DOC
"${fip_BASE_INSTALL_PREFIX}/share/doc/${project_name}"
)
# Set derivative install path and prefixes
# additional, 4
set(fip_INSTALL_PREFIX_EXAMPLES
"${fip_INSTALL_PREFIX_READONLY}/examples")
# Export symbols to the outer scope
foreach(suffix
INSTALL_TYPE
INSTALL_PREFIX_EXEC
INSTALL_PREFIX_EXEC_AUX
INSTALL_PREFIX_READONLY
INSTALL_PREFIX_MANPAGE
INSTALL_PREFIX_GLOBAL_CONF
INSTALL_PREFIX_LIB
INSTALL_PREFIX_LIB_AUX
INSTALL_INCLUDE_DIR
INSTALL_PREFIX_INCLUDE
INSTALL_PREFIX_TEMP_SESSION
INSTALL_PREFIX_TEMP
INSTALL_PREFIX_STATE
INSTALL_PREFIX_CACHE
INSTALL_PREFIX_VAR
INSTALL_PREFIX_DOC
INSTALL_PREFIX_EXAMPLES
)
set(${project_prefix}_${suffix} "${fip_${suffix}}" PARENT_SCOPE)
endforeach(suffix)
if(fip_KERNEL)
# Set derivative install path and prefixes
# additional, 1
if(fip_INSTALL_TYPE MATCHES GLOBAL)
set(fip_KERNEL_INSTALL_PREFIX_KMODULE
"/lib/modules/%kernel%/extra"
)
else(fip_INSTALL_TYPE MATCHES GLOBAL)
set(fip_KERNEL_INSTALL_PREFIX_KMODULE
"${fip_INSTALL_PREFIX_LIB}/modules/%kernel%/extra"
)
endif(fip_INSTALL_TYPE MATCHES GLOBAL)
# additional, 2
set(fip_KERNEL_INSTALL_PREFIX_KSYMVERS
"${fip_INSTALL_PREFIX_LIB}/modules/%kernel%/symvers"
)
# additional, 3
set(fip_INSTALL_KINCLUDE_DIR "${fip_INSTALL_INCLUDE_DIR}")
set(fip_INSTALL_PREFIX_KINCLUDE "${fip_INSTALL_PREFIX_INCLUDE}")
# Kernel include files, which depends from kernel version.
# This prefix is not listed in path conventions.
set(fip_KERNEL_INSTALL_INCLUDE_KERNEL_DIR
"${fip_BASE_INSTALL_PREFIX}/include-kernel/%kernel%"
)
set(fip_KERNEL_INSTALL_PREFIX_INCLUDE_KERNEL
"${fip_KERNEL_INSTALL_INCLUDE_KERNEL_DIR}/${project_name}-kernel"
)
# Export symbols to the outer scope
foreach(suffix
KERNEL_INSTALL_PREFIX_KMODULE
KERNEL_INSTALL_PREFIX_KSYMVERS
INSTALL_KINCLUDE_DIR
INSTALL_PREFIX_KINCLUDE
KERNEL_INSTALL_INCLUDE_KERNEL_DIR
KERNEL_INSTALL_PREFIX_INCLUDE_KERNEL
)
set(${project_prefix}_${suffix} "${fip_${suffix}}" PARENT_SCOPE)
endforeach(suffix)
endif(fip_KERNEL)
endfunction(fill_install_prefixes project_name project_prefix)
########################################################################
# Kernel-dependent paths.
#
# Some deliverables may depends on linux kernel.
#
# For make "one user installation for several kernels" paradigm works,
# installation directory for that deliverables should include
# kernel-version part(like "3.10.2-generic").
#
# So, components installed by user installation can determine at runtime,
# which kernel-dependent deliverable should be used on currently loaded system.
# They do selection using 'uname -r' request.
#
# For define variables represented kernel-dependent directories,
# we use strings containing "%kernel%" stem.
# kernel_path(kernel_version RESULT_VARIABLE pattern ...)
#
# Form concrete path representation from kernel-dependent pattern(s).
# Replace occurence of %kernel% in pattern(s) with given @kernel_version string.
# Result is stored in the RESULT_VARIABLE.
#
# @kernel_version may be concrete version of the kernel,
# or variable reference in some language.
macro(kernel_path kernel_version RESULT_VARIABLE pattern)
string(REPLACE "%kernel%" "${kernel_version}" ${RESULT_VARIABLE} ${pattern} ${ARGN})
endmacro(kernel_path kernel_version RESULT_VARIABLE pattern)
################################################################################
# Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The OpenAirInterface Software Alliance licenses this file to You under
# the OAI Public License, Version 1.1 (the "License"); you may not use this file
# except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.openairinterface.org/?page_id=698
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#-------------------------------------------------------------------------------
# For more information about the OpenAirInterface (OAI) Software Alliance:
# contact@openairinterface.org
################################################################################
# file build_helper
# brief
# author Laurent Thomas, Lionel GAUTHIER
#
#######################################
#SUPPORTED_DISTRO="Ubuntu 18.04, CentOS 7, RHEL 7"
SUPPORTED_DISTRO="Ubuntu 18.04"
if [ ! -f /etc/os-release ]; then
echo_fatal "No /etc/os-release file found. You're likely on an unsupported distro."
fi
OS_DISTRO=$(grep "^ID=" /etc/os-release | sed "s/ID=//" | sed "s/\"//g")
OS_RELEASE=$(grep "^VERSION_ID=" /etc/os-release | sed "s/VERSION_ID=//" | sed "s/\"//g")
case "$OS_DISTRO" in
fedora) OS_BASEDISTRO="fedora"; INSTALLER="dnf"; CMAKE="cmake" ;;
rhel) OS_BASEDISTRO="fedora"; INSTALLER="yum"; CMAKE="cmake3" ;;
centos) OS_BASEDISTRO="fedora"; INSTALLER="yum"; CMAKE="cmake3" ;;
debian) OS_BASEDISTRO="debian"; INSTALLER="apt-get"; CMAKE="cmake" ;;
ubuntu) OS_BASEDISTRO="debian"; INSTALLER="apt-get"; CMAKE="cmake" ;;
esac
IS_CONTAINER=`egrep -c "docker|kubepods" /proc/self/cgroup`
if [ $IS_CONTAINER -eq 0 ]
then
SUDO='sudo -S -E'
else
SUDO=''
fi
###############################
## echo and family
###############################
black='\E[30m'
red='\E[31m'
green='\E[32m'
yellow='\E[33m'
blue='\E[1;34m'
magenta='\E[35m'
cyan='\E[36m'
white='\E[37m'
reset_color='\E[00m'
COLORIZE=1
#-------------------------------------------------------------------------------
cecho() {
# Color-echo
# arg1 = message
# arg2 = color
local default_msg="No Message."
message=${1:-$default_msg}
color=${2:-$green}
[ "$COLORIZE" = "1" ] && message="$color$message$reset_color"
echo -e "$message"
return
}
echo_error() { cecho "$*" $red ;}
echo_fatal() { cecho "$*" $red; exit -1 ;}
echo_warning() { cecho "$*" $yellow ;}
echo_success() { cecho "$*" $green ;}
echo_info() { cecho "$*" $blue ;}
#-------------------------------------------------------------------------------
# From https://stackoverflow.com/questions/4023830/how-to-compare-two-strings-in-dot-separated-version-format-in-bash
# arg1 is a dotted (or not) version number (ex 4.10.6.56-ubunutu)
# arg2 is a dotted (or not) version number (ex 4.10.6.56-ubunutu)
# return 0 if $1 lower or equal $2, else 1
version_le() {
[ "$1" = "`echo -e "$1\n$2" | sort -V | head -n1`" ]
}
# From https://stackoverflow.com/questions/4023830/how-to-compare-two-strings-in-dot-separated-version-format-in-bash
version_lt() {
[ "$1" = "$2" ] && return 1 || version_le $1 $2
}
# From https://stackoverflow.com/questions/4023830/how-to-compare-two-strings-in-dot-separated-version-format-in-bash
version_ge() {
[ "$1" = "`echo -e "$1\n$2" | sort -V | tail -n1`" ]
}
# From https://stackoverflow.com/questions/4023830/how-to-compare-two-strings-in-dot-separated-version-format-in-bash
version_gt() {
[ "$1" = "$2" ] && return 1 || version_ge $1 $2
}
########################
# distribution helpers #
########################
#-------------------------------------------------------------------------------
# This function return a string to identify the distribution we are running
# If we can't check the distribution, it returns "Unknown"
# This function return always true as exit code by design
# Examples:
# ubuntu18.04
# debian8.5
get_distribution_release() {
if [[ ! -z "$OS_DISTRO$OS_RELEASE" ]]; then
echo -n "$OS_DISTRO$OS_RELEASE"
else
echo -n Unknown
fi
}
check_supported_distribution() {
local distribution=$(get_distribution_release)
case "$distribution" in
"ubuntu18.04") return 0 ;;
#"rhel7") return 0 ;;
#"centos7") return 0 ;;
esac
return 1
}
###########################
# Cleaners
###########################
#-------------------------------------------------------------------------------
clean_kernel() {
$SUDO modprobe ip_tables
$SUDO modprobe x_tables
$SUDO iptables -P INPUT ACCEPT
$SUDO iptables -F INPUT
$SUDO iptables -P OUTPUT ACCEPT
$SUDO iptables -F OUTPUT
$SUDO iptables -P FORWARD ACCEPT
$SUDO iptables -F FORWARD
$SUDO iptables -t nat -F
$SUDO iptables -t mangle -F
$SUDO iptables -t filter -F
$SUDO iptables -t raw -F
echo_info "Flushed iptables"
}
#-------------------------------------------------------------------------------
disable_ipv6() {
$SUDO sysctl -w net.ipv6.conf.all.disable_ipv6=1
}
#-------------------------------------------------------------------------------
# Compare two versions of software. Returns true if $version is greater than $req_version
# arg1 = version
# arg2 = req_version
#
function version_gt() {
test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1";
}
###################################
# Compilers
###################################
# From https://stackoverflow.com/a/20473191
# test if a list include item
# arg1 is list, ex "item1 item2 ..."
# arg2 is item
function list_include_item {
local list="$1"
local item="$2"
if [[ $list =~ (^|[[:space:]])"$item"($|[[:space:]]) ]] ; then
# yes, list include item
result=0
else
result=1
fi
return $result
}
# arg 1 Build directory OPENAIR_DIR/build/?/build
# arg 2 Executable target name
# arg 3 Executable name (no path)
# arg 4 Verbose (1 or 0)
compilations() {
echo_info "Compilation log for $3 is here: $dlog/$2.txt"
cd $OPENAIRCN_DIR/build/$1/build
if [ "a$4" == "a1" ]; then
set -o pipefail
{
rm -f $3
make $make_args $2
} | tee $dlog/$2.txt
else
{
rm -f $3
make $make_args $2
} > $dlog/$2.txt 2>&1
fi
if [ $? == 0 -a -s $3 ] ; then
echo_success "$2 compiled"
return 0
else
echo_error "$2 compilation failed"
return 1
fi
}
###################################
# make test
###################################
# arg 1 Build directory OPENAIRCN_DIR/build/?/build
# arg 2 Executable target name
# arg 3 Executable name (no path)
# arg 4 Verbose (1 or 0)
make_test() {
echo_success "unit tests start"
cd $OPENAIRCN_DIR/build/$1/build
if [ "a$4" == "a1" ]; then
{
make test ARGS="-V"
} | tee $dlog/$2_test.txt
else
{
make test
} > $dlog/$2_test.txt 2>&1
fi
echo_success "unit tests end"
}
#-------------------------------------------------------------------------------
# arg1 is package name
test_install_package() {
# usage: test_install_package package_name
if [ $# -eq 1 ]; then
dpkg -s "$1" > /dev/null 2>&1 && {
echo "$1 is installed."
} || {
echo "$1 is not installed."
$SUDO apt-get install --force-yes $1
}
fi
}
#-------------------------------------------------------------------------------
update_package_db() {
if [ ! -f /tmp/no_more_update_package_db ]; then
$SUDO $INSTALLER update
[[ $? -ne 0 ]] && return $?
touch /tmp/no_more_update_package_db
[[ $? -ne 0 ]] && return $?
else
let elapsed_time=$(expr `date +%s` - `stat -c %Y /tmp/no_more_update_package_db`)
if [ $elapsed_time -gt 3600 ]; then
$SUDO $INSTALLER update
[[ $? -ne 0 ]] && return $?
touch /tmp/no_more_update_package_db
[[ $? -ne 0 ]] && return $?
fi
fi
return 0
}
#-------------------------------------------------------------------------------
check_enable_epel_repos() {
# on Enterprise Linuxes, ensure EPEL repos are installed
# (provides: libidn2-devel, vconfig, iperf, phpMyAdmin, dkms, ...)
if [[ "$OS_DISTRO" == "rhel" ]] || [[ "$OS_DISTRO" == "centos" ]]; then
if rpm -q epel-release > /dev/null; then
echo "EPEL repos already present. Good."
else
echo "EPEL repos not present. Installing them."
$SUDO $INSTALLER install $OPTION https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
fi
fi
}
################################
# set_openair_env
###############################
#-------------------------------------------------------------------------------
set_openair_env(){
fullpath=`readlink -f $BASH_SOURCE`
[ -f "/.$fullpath" ] || fullpath=`readlink -f $PWD/$fullpath`
openair_path=${fullpath%/build/*}
openair_path=${openair_path%/scripts/*}
openair_path=${openair_path%/src/nas/*}
openair_path=${openair_path%/src/s6a/*}
export OPENAIRCN_DIR=$openair_path
}
################################################################################
# Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The OpenAirInterface Software Alliance licenses this file to You under
# the OAI Public License, Version 1.1 (the "License"); you may not use this file
# except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.openairinterface.org/?page_id=698
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#-------------------------------------------------------------------------------
# For more information about the OpenAirInterface (OAI) Software Alliance:
# contact@openairinterface.org
################################################################################
# file build_helper.fb_folly
# brief
# author Lionel GAUTHIER
#
#######################################
SCRIPT=$(readlink -f ${BASH_SOURCE})
THIS_SCRIPT_PATH=`dirname $SCRIPT`
source $THIS_SCRIPT_PATH/build_helper
#arg1 is force (0 or 1) (no interactive script)
#arg2 is debug (0 or 1) (install debug libraries)
install_fb_folly_from_source(){
if [ $1 -eq 0 ]; then
OPTION=""
read -p "Do you want to install FaceBook folly (github)? <y/N> " prompt
else
prompt='y'
OPTION="-y"
fi
if [ $2 -eq 0 ]; then
debug=0
else
debug=1
fi
if [[ $prompt =~ [yY](es)* ]]
then
$SUDO apt-get install $OPTION \
g++ \
cmake \
libboost-all-dev \
libevent-dev \
libdouble-conversion-dev \
libgoogle-glog-dev \
libgflags-dev \
libiberty-dev \
liblz4-dev \
liblzma-dev \
libsnappy-dev \
make \
zlib1g-dev \
binutils-dev \
libjemalloc-dev \
libssl-dev \
pkg-config
ret=$?;[[ $ret -ne 0 ]] && return $ret
pushd /tmp
if [ $debug -eq 1 ]; then
# For advanced debugging options
$SUDO apt-get install $OPTION \
libunwind8-dev \
libelf-dev \
libdwarf-dev
ret=$?;[[ $ret -ne 0 ]] && return $ret
wget https://github.com/google/googletest/archive/release-1.8.0.tar.gz && \
tar zxf release-1.8.0.tar.gz && \
rm -f release-1.8.0.tar.gz && \
cd googletest-release-1.8.0 && \
cmake . && \
make && \
$SUDO make install
ret=$?;[[ $ret -ne 0 ]] && popd && return $ret
cd ..
fi
$SUDO rm -rf /tmp/folly
git clone https://github.com/facebook/folly.git
ret=$?;[[ $ret -ne 0 ]] && popd && return $ret
cd folly
git checkout -f v2019.11.11.00
mkdir _build && cd _build
cmake ..
ret=$?;[[ $ret -ne 0 ]] && popd && return $ret
make -j $(nproc)
ret=$?;[[ $ret -ne 0 ]] && popd && return $ret
$SUDO make install
ret=$?;[[ $ret -ne 0 ]] && popd && return $ret
popd
fi
return 0
}
################################################################################
# Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The OpenAirInterface Software Alliance licenses this file to You under
# the OAI Public License, Version 1.1 (the "License"); you may not use this file
# except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.openairinterface.org/?page_id=698
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#-------------------------------------------------------------------------------
# For more information about the OpenAirInterface (OAI) Software Alliance:
# contact@openairinterface.org
################################################################################
# file build_helper.libconfig
# brief
# author Lionel GAUTHIER
#
#######################################
SCRIPT=$(readlink -f ${BASH_SOURCE})
THIS_SCRIPT_PATH=`dirname $SCRIPT`
source $THIS_SCRIPT_PATH/build_helper
#-------------------------------------------------------------------------------
# Motivation: seems libconfig++ need to be compiled with same application C++ compiler,
# otherwise you encounter strange linker errors. (ubuntu 16.04)
#arg1 is force (0 or 1) (no interactive script)
#arg2 is debug (0 or 1) (install debug libraries)
install_libconfig_from_source(){
if [ $1 -eq 0 ]; then
OPTION=""
read -p "Do you want to install libconfig (github)? <y/N> " prompt
else
prompt='y'
OPTION="-y"
fi
if [ $2 -eq 0 ]; then
debug=0
else
debug=1
fi
if [[ $prompt =~ [yY](es)* ]]
then
if [[ "$OS_DISTRO" == "ubuntu" ]]; then
PACKAGE_LIST="\
autoconf \
automake \
bison \
build-essential \
flex \
gcc \
libtool"
elif [[ "$OS_BASEDISTRO" == "fedora" ]]; then
PACKAGE_LIST="\
autoconf \
automake \
bison \
patch \
flex \
gcc \
libtool \
textinfo"
else
echo_fatal "$OS_DISTRO is not a supported distribution."
fi
$SUDO $INSTALLER install $OPTION $PACKAGE_LIST
pushd /tmp
$SUDO rm -rf /tmp/libconfig
git clone https://github.com/hyperrealm/libconfig.git
ret=$?;[[ $ret -ne 0 ]] && popd && return $ret
cd libconfig
autoreconf -fi
./configure
ret=$?;[[ $ret -ne 0 ]] && return $ret
make -j `nproc` > /tmp/log_compile_config 2>&1
ret=$?;[[ $ret -ne 0 ]] && popd && return $ret
$SUDO make install
ret=$?;[[ $ret -ne 0 ]] && popd && return $ret
popd
fi
return 0
}
This diff is collapsed.
#!/bin/bash
################################################################################
# Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The OpenAirInterface Software Alliance licenses this file to You under
# the OAI Public License, Version 1.1 (the "License"); you may not use this file
# except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.openairinterface.org/?page_id=698
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#-------------------------------------------------------------------------------
# For more information about the OpenAirInterface (OAI) Software Alliance:
# contact@openairinterface.org
################################################################################
# file build_smf
# brief
# author Lionel Gauthier
# company Eurecom
# email: lionel.gauthier@eurecom.fr
#
set -o pipefail
INSTALL_DIR=/usr/local/bin
################################
# include helper functions
################################
THIS_SCRIPT_PATH=$(dirname $(readlink -f $0))
source $THIS_SCRIPT_PATH/build_helper.smf
function help()
{
echo_error " "
echo_error "Usage: build_smf [OPTION]..."
echo_error "Build the SMF executable."
echo_error " "
echo_error "Options:"
echo_error "Mandatory arguments to long options are mandatory for short options too."
echo_error " -b, --build-type Build type as defined in cmake, allowed values are: Debug Release RelWithDebInfo MinSizeRel"
echo_error " -c, --clean Clean the build generated files: config, object, executable files (build from scratch)"
echo_error " -f, --force No interactive script for installation of software packages."
echo_error " -h, --help Print this help."
echo_error " -I, --install-deps Check installed software necessary to build and run SMF (support $SUPPORTED_DISTRO)."
echo_error " -i, --install-min-deps Check installed software necessary to run a statically linked SMF (support $SUPPORTED_DISTRO)."
echo_error " -j, --jobs Multiple jobs for compiling."
echo_error " -v, --verbose Build process verbose."
echo_error " -V, --Verbose CMake only build process verbose, display compilation warnings and errors."
echo_error " "
}
function main()
{
local -i clean=0
local -i force=0
local -i debug=0
local -i verbose=0
local -i var_check_install_min_deps=0
local -i var_check_install_deps=0
local cmake_args=" "
export make_args=" "
until [ -z "$1" ]
do
case "$1" in
-a | --auto-test)
cmake_args="$cmake_args -DSGW_AUTOTEST=1"
shift;
;;
-b | --build-type)
list_include_item "Debug Release RelWithDebInfo MinSizeRel" $2
[[ $? -ne 0 ]] && echo_error "Build type $2 not recognized" && return $?
cmake_args="$cmake_args -DCMAKE_BUILD_TYPE=$2"
list_include_item "Debug" $2
[[ $? -ne 0 ]] && debug=1
shift 2;
;;
-c | --clean)
clean=1
echo "Clean the build generated files (build from scratch)"
shift;
;;
-f | --force)
force=1
echo "Force set (no interactive)"
shift;
;;
-h | --help)
help
shift;
return 0
;;
-I | --install-deps)
echo "Check installed software necessary to build and run SMF (support $SUPPORTED_DISTRO):"
set_openair_env
var_check_install_deps=1
shift;
;;
-i | --install-min-deps)
echo "Check installed software necessary to run SMF (support $SUPPORTED_DISTRO):"
set_openair_env
var_check_install_min_deps=1
shift;
;;
-j | --jobs)
make_args="$make_args -j`nproc`"
shift;
;;
-v | --verbose)
echo "Make build process verbose"
cmake_args="$cmake_args -DCMAKE_VERBOSE_MAKEFILE=ON"
make_args="VERBOSE=1 $make_args"
verbose=1
shift;
;;
-V | --Verbose)
echo "CMake build process verbose"
verbose=1
shift;
;;
*)
echo "Unknown option $1"
help
return 1
;;
esac
done
if [ ! -d /usr/local/etc/oai ]; then
$SUDO mkdir -m 777 -p /usr/local/etc/oai
fi
set_openair_env
local dlog=$OPENAIRCN_DIR/build/log
local dext=$OPENAIRCN_DIR/build/ext
mkdir -m 777 -p $dlog
mkdir -m 777 -p $dext
if [ $var_check_install_min_deps -gt 0 ];then
disable_ipv6
check_install_smf_min_deps $force $debug
if [[ $? -ne 0 ]]; then
echo_error "Error: SMF minimal deps installation failed"
return 1
else
echo_success "SMF minimal deps installation successful"
echo_warning "SMF not compiled, to compile it, re-run build_smf without -i option"
return 0
fi
fi
if [ $var_check_install_deps -gt 0 ];then
disable_ipv6
check_install_smf_deps $force $debug
if [[ $? -ne 0 ]]; then
echo_error "Error: SMF deps installation failed"
return 1
else
echo_success "SMF deps installation successful"
echo_warning "SMF not compiled, to compile it, re-run build_smf without -I option"
return 0
fi
fi
cmake_args="$cmake_args -DBUILD_SHARED_LIBS=OFF"
##############################################################################
# Clean
##############################################################################
cd $OPENAIRCN_DIR/build/smf
if [ $clean -ne 0 ]; then
if [[ $verbose -eq 1 ]]; then
echo "Cleaning SMF: generated configuration files, obj files, executable"
fi
rm -Rf $OPENAIRCN_DIR/build/smf/build 2>&1
mkdir -m 777 -p -v build
fi
##############################################################################
# Compile SMF
##############################################################################
cd $OPENAIRCN_DIR/build/smf
if [ ! -d ./build ]; then
mkdir -m 777 -p -v build
fi
cd ./build
$CMAKE $cmake_args .. > /dev/null
ret=$?;[[ $ret -ne 0 ]] && return $ret
compilations smf smf $OPENAIRCN_DIR/build/smf/build/smf $verbose
ret=$?;[[ $ret -ne 0 ]] && return $ret
# For daemon should not be group writable
$SUDO chmod 755 $OPENAIRCN_DIR/build/smf/build/smf
$SUDO cp -upv $OPENAIRCN_DIR/build/smf/build/smf $INSTALL_DIR && $SUDO chmod 755 $INSTALL_DIR/smf && echo_success "smf installed"
return 0
}
main "$@"
# prompt has been removed for easier Ctrl+C Ctrl+V
# please update the following information according to your configuration
INSTANCE=1
PREFIX='/usr/local/etc/oai'
sudo mkdir -m 0777 -p $PREFIX
cp ../../etc/smf.conf $PREFIX
declare -A SMF_CONF
SMF_CONF[@INSTANCE@]=$INSTANCE
SMF_CONF[@PREFIX@]=$PREFIX
SMF_CONF[@PID_DIRECTORY@]='/var/run'
SMF_CONF[@SMF_INTERFACE_NAME_FOR_N4@]='ens3'
SMF_CONF[@SMF_INTERFACE_NAME_FOR_SBI@]='ens3'
SMF_CONF[@SMF_INTERFACE_PORT_FOR_SBI@]='80'
SMF_CONF[@SMF_INTERFACE_HTTP2_PORT_FOR_SBI@]='9090'
SMF_CONF[@SMF_API_VERSION@]='v1'
SMF_CONF[@UDM_IPV4_ADDRESS@]='172.16.1.103'
SMF_CONF[@UDM_PORT@]='80'
SMF_CONF[@UDM_API_VERSION@]='v2'
SMF_CONF[@AMF_IPV4_ADDRESS@]='192.168.122.183'
SMF_CONF[@AMF_PORT@]='80'
SMF_CONF[@AMF_API_VERSION@]='v1'
SMF_CONF[@UPF_IPV4_ADDRESS@]='192.168.122.151'
SMF_CONF[@DEFAULT_DNS_IPV4_ADDRESS@]='8.8.8.8'
SMF_CONF[@DEFAULT_DNS_SEC_IPV4_ADDRESS@]='4.4.4.4'
for K in "${!SMF_CONF[@]}"; do
egrep -lRZ "$K" $PREFIX | xargs -0 -l sed -i -e "s|$K|${SMF_CONF[$K]}|g"
ret=$?;[[ ret -ne 0 ]] && echo "Tried to replace $K with ${SMF_CONF[$K]}"
done
# prompt has been removed for easier Ctrl+C Ctrl+V
sudo ifconfig eno1:smf 172.16.1.101 up # SMF
sudo ifconfig eno1:amf 172.16.1.102 up # AMF
sudo ifconfig eno1:udm 172.16.1.103 up # UDM
sudo ifconfig eno1:sn4 172.16.2.101 up # SMF N4 interface
sudo ifconfig eno1:un4 172.16.2.102 up # UPF N4 interface
INSTANCE=1
PREFIX='/usr/local/etc/oai'
sudo mkdir -m 0777 -p $PREFIX
cp ../../etc/smf.conf $PREFIX
declare -A SMF_CONF
SMF_CONF[@INSTANCE@]=$INSTANCE
SMF_CONF[@PREFIX@]=$PREFIX
SMF_CONF[@PID_DIRECTORY@]='/var/run'
SMF_CONF[@SMF_INTERFACE_NAME_FOR_N4@]='eno1:sn4'
SMF_CONF[@SMF_INTERFACE_NAME_FOR_SBI@]='eno1:smf'
SMF_CONF[@SMF_INTERFACE_IPV4_ADDRESS_FOR_SBI@]='172.16.1.101'
SMF_CONF[@SMF_INTERFACE_PORT_FOR_SBI@]='80'
SMF_CONF[@SMF_INTERFACE_HTTP2_PORT_FOR_SBI@]='9090'
SMF_CONF[@UDM_IPV4_ADDRESS@]='172.16.1.103'
SMF_CONF[@UDM_PORT@]='80'
SMF_CONF[@AMF_IPV4_ADDRESS@]='172.16.1.102'
SMF_CONF[@AMF_PORT@]='80'
SMF_CONF[@UPF_IPV4_ADDRESS@]='172.16.2.102'
SMF_CONF[@DEFAULT_DNS_IPV4_ADDRESS@]='8.8.8.8'
SMF_CONF[@DEFAULT_DNS_SEC_IPV4_ADDRESS@]='4.4.4.4'
for K in "${!SMF_CONF[@]}"; do
egrep -lRZ "$K" $PREFIX | xargs -0 -l sed -i -e "s|$K|${SMF_CONF[$K]}|g"
ret=$?;[[ ret -ne 0 ]] && echo "Tried to replace $K with ${SMF_CONF[$K]}"
done
################################################################################
# Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The OpenAirInterface Software Alliance licenses this file to You under
# the OAI Public License, Version 1.1 (the "License"); you may not use this file
# except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.openairinterface.org/?page_id=698
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#-------------------------------------------------------------------------------
# For more information about the OpenAirInterface (OAI) Software Alliance:
# contact@openairinterface.org
################################################################################
cmake_minimum_required (VERSION 3.0.2)
project(oai-cn)
# Override options for SMF
set ( PACKAGE_NAME "SMF" )
set ( STATIC_LINKING False )
#############################################
# Base directories, compatible with legacy OAI building
################################################
set (OPENAIRCN_DIR $ENV{OPENAIRCN_DIR})
set (BUILD_TOP_DIR ${OPENAIRCN_DIR}/build)
set (SRC_TOP_DIR $ENV{OPENAIRCN_DIR}/src)
include(${CMAKE_CURRENT_SOURCE_DIR}/../../src/oai_smf/CMakeLists.txt)
ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../../src/smf_app ${CMAKE_CURRENT_BINARY_DIR}/smf_app)
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.
# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
CMakeLists.txt
README.md
api/CompleteStoredSearchDocumentApi.cpp
api/CompleteStoredSearchDocumentApi.h
api/NFInstancesStoreApi.cpp
api/NFInstancesStoreApi.h
api/StoredSearchDocumentApi.cpp
api/StoredSearchDocumentApi.h
impl/CompleteStoredSearchDocumentApiImpl.cpp
impl/CompleteStoredSearchDocumentApiImpl.h
impl/NFInstancesStoreApiImpl.cpp
impl/NFInstancesStoreApiImpl.h
impl/StoredSearchDocumentApiImpl.cpp
impl/StoredSearchDocumentApiImpl.h
main-api-server.cpp
model/AccessType.cpp
model/AccessType.h
model/AmfInfo.cpp
model/AmfInfo.h
model/Atom.cpp
model/Atom.h
model/AtsssCapability.cpp
model/AtsssCapability.h
model/AusfInfo.cpp
model/AusfInfo.h
model/BsfInfo.cpp
model/BsfInfo.h
model/ChfInfo.cpp
model/ChfInfo.h
model/ChfServiceInfo.cpp
model/ChfServiceInfo.h
model/Cnf.cpp
model/Cnf.h
model/CnfUnit.cpp
model/CnfUnit.h
model/ComplexQuery.cpp
model/ComplexQuery.h
model/DataSetId.cpp
model/DataSetId.h
model/DefaultNotificationSubscription.cpp
model/DefaultNotificationSubscription.h
model/Dnf.cpp
model/Dnf.h
model/DnfUnit.cpp
model/DnfUnit.h
model/DnnSmfInfoItem.cpp
model/DnnSmfInfoItem.h
model/DnnUpfInfoItem.cpp
model/DnnUpfInfoItem.h
model/EventId.cpp
model/EventId.h
model/Guami.cpp
model/Guami.h
model/Helpers.cpp
model/Helpers.h
model/IdentityRange.cpp
model/IdentityRange.h
model/InterfaceUpfInfoItem.cpp
model/InterfaceUpfInfoItem.h
model/InvalidParam.cpp
model/InvalidParam.h
model/IpEndPoint.cpp
model/IpEndPoint.h
model/Ipv4AddressRange.cpp
model/Ipv4AddressRange.h
model/Ipv6Addr.cpp
model/Ipv6Addr.h
model/Ipv6Prefix.cpp
model/Ipv6Prefix.h
model/Ipv6PrefixRange.cpp
model/Ipv6PrefixRange.h
model/N1MessageClass.cpp
model/N1MessageClass.h
model/N2InformationClass.cpp
model/N2InformationClass.h
model/N2InterfaceAmfInfo.cpp
model/N2InterfaceAmfInfo.h
model/NFProfile.cpp
model/NFProfile.h
model/NFService.cpp
model/NFService.h
model/NFServiceStatus.cpp
model/NFServiceStatus.h
model/NFServiceVersion.cpp
model/NFServiceVersion.h
model/NFStatus.cpp
model/NFStatus.h
model/NFType.cpp
model/NFType.h
model/NotificationType.cpp
model/NotificationType.h
model/NwdafEvent.cpp
model/NwdafEvent.h
model/NwdafInfo.cpp
model/NwdafInfo.h
model/PcfInfo.cpp
model/PcfInfo.h
model/PduSessionType.cpp
model/PduSessionType.h
model/PlmnId.cpp
model/PlmnId.h
model/PlmnRange.cpp
model/PlmnRange.h
model/PlmnSnssai.cpp
model/PlmnSnssai.h
model/ProblemDetails.cpp
model/ProblemDetails.h
model/SearchResult.cpp
model/SearchResult.h
model/ServiceName.cpp
model/ServiceName.h
model/SmfInfo.cpp
model/SmfInfo.h
model/Snssai.cpp
model/Snssai.h
model/SnssaiSmfInfoItem.cpp
model/SnssaiSmfInfoItem.h
model/SnssaiUpfInfoItem.cpp
model/SnssaiUpfInfoItem.h
model/StoredSearchResult.cpp
model/StoredSearchResult.h
model/SupiRange.cpp
model/SupiRange.h
model/TacRange.cpp
model/TacRange.h
model/Tai.cpp
model/Tai.h
model/TaiRange.cpp
model/TaiRange.h
model/TransportProtocol.cpp
model/TransportProtocol.h
model/UPInterfaceType.cpp
model/UPInterfaceType.h
model/UdmInfo.cpp
model/UdmInfo.h
model/UdrInfo.cpp
model/UdrInfo.h
model/UpfInfo.cpp
model/UpfInfo.h
model/UriScheme.cpp
model/UriScheme.h
5.0.0-SNAPSHOT
\ No newline at end of file
cmake_minimum_required (VERSION 3.2)
project(api-server)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -pg -g3" )
include(ExternalProject)
set(EXTERNAL_INSTALL_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/external)
ExternalProject_Add(PISTACHE
GIT_REPOSITORY https://github.com/oktal/pistache.git
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${EXTERNAL_INSTALL_LOCATION}
)
ExternalProject_Add(NLOHMANN
GIT_REPOSITORY https://github.com/nlohmann/json.git
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${EXTERNAL_INSTALL_LOCATION}
)
include_directories(${EXTERNAL_INSTALL_LOCATION}/include)
link_directories(${EXTERNAL_INSTALL_LOCATION}/lib)
include_directories(model)
include_directories(api)
include_directories(impl)
file(GLOB SRCS
${CMAKE_CURRENT_SOURCE_DIR}/api/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/impl/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/model/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
)
add_executable(${PROJECT_NAME} ${SRCS} )
add_dependencies(${PROJECT_NAME} PISTACHE NLOHMANN)
target_link_libraries(${PROJECT_NAME} pistache pthread)
# REST API Server for NRF NFDiscovery Service
## Overview
This API Server was generated by the [OpenAPI Generator](https://openapi-generator.tech) project.
It uses the [Pistache](https://github.com/oktal/pistache) Framework.
## Files organization
The Pistache C++ REST server generator creates three folders:
- `api`: This folder contains the handlers for each method specified in the OpenAPI definition. Every handler extracts
the path and body parameters (if any) from the requests and tries to parse and possibly validate them.
Once this step is completed, the main API class calls the corresponding abstract method that should be implemented
by the developer (a basic implementation is provided under the `impl` folder)
- `impl`: As written above, the implementation folder contains, for each API, the corresponding implementation class,
which extends the main API class and implements the abstract methods.
Every method receives the path and body parameters as constant reference variables and a reference to the response
object, that should be filled with the right response and sent at the end of the method with the command:
response.send(returnCode, responseBody, [mimeType])
- `model`: This folder contains the corresponding class for every object schema found in the OpenAPI specification.
The main folder contains also a file with a main that can be used to start the server.
Of course, is you should customize this file based on your needs
## Installation
First of all, you need to download and install the libraries listed [here](#libraries-required).
Once the libraries are installed, in order to compile and run the server please follow the steps below:
```bash
mkdir build
cd build
cmake ..
make
```
Once compiled run the server:
```bash
cd build
./api-server
```
## Libraries required
- [pistache](http://pistache.io/quickstart)
- [JSON for Modern C++](https://github.com/nlohmann/json/#integration): Please download the `json.hpp` file and
put it under the model/nlohmann folder
## Namespaces
oai.nrf.api
oai.nrf.model
/**
* NRF NFDiscovery Service
* NRF NFDiscovery Service. © 2019, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TSDSI, TTA, TTC). All rights reserved.
*
* The version of the OpenAPI document: 1.1.0.alpha-1
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
#include "CompleteStoredSearchDocumentApi.h"
#include "Helpers.h"
namespace oai {
namespace nrf {
namespace api {
using namespace org::openapitools::server::helpers;
using namespace oai::nrf::model;
CompleteStoredSearchDocumentApi::CompleteStoredSearchDocumentApi(std::shared_ptr<Pistache::Rest::Router> rtr) {
router = rtr;
}
void CompleteStoredSearchDocumentApi::init() {
setupRoutes();
}
void CompleteStoredSearchDocumentApi::setupRoutes() {
using namespace Pistache::Rest;
Routes::Get(*router, base + "/searches/:searchId/complete", Routes::bind(&CompleteStoredSearchDocumentApi::retrieve_complete_search_handler, this));
// Default handler, called when a route is not found
router->addCustomHandler(Routes::bind(&CompleteStoredSearchDocumentApi::complete_stored_search_document_api_default_handler, this));
}
void CompleteStoredSearchDocumentApi::retrieve_complete_search_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
// Getting the path params
auto searchId = request.param(":searchId").as<std::string>();
try {
this->retrieve_complete_search(searchId, response);
} catch (nlohmann::detail::exception &e) {
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (Pistache::Http::HttpError &e) {
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
return;
} catch (std::exception &e) {
//send a 500 error
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
return;
}
}
void CompleteStoredSearchDocumentApi::complete_stored_search_document_api_default_handler(const Pistache::Rest::Request &, Pistache::Http::ResponseWriter response) {
response.send(Pistache::Http::Code::Not_Found, "The requested method does not exist");
}
}
}
}
/**
* NRF NFDiscovery Service
* NRF NFDiscovery Service. © 2019, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TSDSI, TTA, TTC). All rights reserved.
*
* The version of the OpenAPI document: 1.1.0.alpha-1
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
/*
* CompleteStoredSearchDocumentApi.h
*
*
*/
#ifndef CompleteStoredSearchDocumentApi_H_
#define CompleteStoredSearchDocumentApi_H_
#include <pistache/http.h>
#include <pistache/router.h>
#include <pistache/http_headers.h>
#include <pistache/optional.h>
#include "StoredSearchResult.h"
#include <string>
namespace oai {
namespace nrf {
namespace api {
using namespace oai::nrf::model;
class CompleteStoredSearchDocumentApi {
public:
CompleteStoredSearchDocumentApi(std::shared_ptr<Pistache::Rest::Router>);
virtual ~CompleteStoredSearchDocumentApi() {}
void init();
const std::string base = "/nnrf-disc/v1";
private:
void setupRoutes();
void retrieve_complete_search_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
void complete_stored_search_document_api_default_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
std::shared_ptr<Pistache::Rest::Router> router;
/// <summary>
///
/// </summary>
/// <remarks>
///
/// </remarks>
/// <param name="searchId">Id of a stored search</param>
virtual void retrieve_complete_search(const std::string &searchId, Pistache::Http::ResponseWriter &response) = 0;
};
}
}
}
#endif /* CompleteStoredSearchDocumentApi_H_ */
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment