vcpe/CMakeLists.txt

163 lines
4.6 KiB
CMake

CMAKE_MINIMUM_REQUIRED(VERSION 3.10 FATAL_ERROR)
INCLUDE(CMakeDependentOption)
OPTION(VCPE_AGENT "Enable vCPE agent test application" OFF)
OPTION(VCPE_PPPOE "Enable vCPE work befof PPPoE mode" OFF)
OPTION(USED_OPENDHCPD "DHCP server for vCPE" OFF)
OPTION(USED_OPENDHCPDDNS "DHCP And DNS server for vCPE" OFF)
OPTION(USED_USER_VNI "Support pass user vni id from console command line" OFF)
OPTION(USED_JSON_VALIDATE "Support json protocol field validate" OFF)
OPTION(BUILD_TESTING "Enable tests" OFF)
# 数据库开关
OPTION(USED_REDIS "Add redis database support for vCPE" OFF)
OPTION(USED_MYSQL "Add mysql database support for vCPE" OFF)
OPTION(USED_SQLITE_CRYPTO "Sqlite3 database support crypto" OFF)
CMAKE_DEPENDENT_OPTION(USED_HTTP_SVR "Build-in http(s) server support" ON "USED_OPENDHCPD OR USED_OPENDHCPDDNS" ON)
CMAKE_DEPENDENT_OPTION(USED_LWIP "PPPoE of LWIP support for vCPE" ON "VCPE_PPPOE" OFF)
CMAKE_DEPENDENT_OPTION(USED_ZMQ "ZeroMQ support for vCPE" ON "VCPE_PPPOE" OFF)
CMAKE_DEPENDENT_OPTION(USED_SQLITE "Add sqlite3 database support for vCPE" ON "USED_SQLITE_CRYPTO" ON)
LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/depend)
IF (BUILD_TESTING)
INCLUDE(doctest_framework)
ENDIF ()
INCLUDE(system_libs)
SET(VCPE_VERSION "1.2.0")
PROJECT(vCPE VERSION "${VCPE_VERSION}")
SET(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:/usr/local/lib/pkgconfig")
SET(URI_HOME "${CMAKE_SOURCE_DIR}/libs")
SET(VERSION_GIT_TAG "")
SET(VERSION_GIT_HASH "")
SET(VERSION_GIT_HASH_SHORT "")
SET(VERSION_GIT_BRANCH "")
FIND_PACKAGE(Git QUIET)
IF (GIT_FOUND)
EXECUTE_PROCESS(
COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
OUTPUT_VARIABLE VERSION_GIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
EXECUTE_PROCESS(
COMMAND ${GIT_EXECUTABLE} rev-parse --short=8 HEAD
OUTPUT_VARIABLE VERSION_GIT_HASH_SHORT
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
EXECUTE_PROCESS(
COMMAND ${GIT_EXECUTABLE} symbolic-ref --short -q HEAD
OUTPUT_VARIABLE VERSION_GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
EXECUTE_PROCESS(
COMMAND ${GIT_EXECUTABLE} describe --tags --always --dirty=-dev
OUTPUT_VARIABLE VERSION_GIT_TAG
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
ENDIF ()
IF ("${VERSION_GIT_TAG}" STREQUAL "")
STRING(TIMESTAMP COMPILE_TIME %Y-%m-%d_%H:%M:%S)
SET(VERSION_GIT_TAG ${COMPILE_TIME})
ELSE ()
SET(VERSION_GIT_TAG ${VERSION_GIT_TAG})
ENDIF ()
CONFIGURE_FILE(prj_config.h.in prj_config.h)
MESSAGE("Git Tag: " ${VERSION_GIT_TAG})
# 判断依赖库是否存在
FIND_PACKAGE(PkgConfig)
SET(COMMON_LIBS "")
INCLUDE(./depend/third_libs.cmake)
IF (USED_JSON_VALIDATE)
LIST(APPEND COMMON_DEFINE "-DJSON_SCHEMA_ON")
ENDIF ()
IF (USED_USER_VNI)
LIST(APPEND COMMON_DEFINE "-DUSERVNI_ON")
MESSAGE("Select Option USED_USER_VNI")
ENDIF ()
IF (USED_HTTP_SVR)
LIST(APPEND COMMON_DEFINE "-DHTTPSERVER_ON")
MESSAGE("Select Option USED_HTTP_SVR")
ENDIF ()
IF (USED_ZMQ)
LIST(APPEND COMMON_DEFINE "-DZEROMQ_ON")
MESSAGE("Select Option USED_ZMQ")
ENDIF ()
IF (VCPE_PPPOE)
LIST(APPEND COMMON_DEFINE "-DPPPOE_ON")
MESSAGE("Select Option VCPE_PPPOE")
ENDIF ()
IF (USED_LWIP)
LIST(APPEND COMMON_DEFINE "-DLWIP_ON")
MESSAGE("Select Option USED_LWIP")
ENDIF ()
IF (USED_OPENDHCPD)
LIST(APPEND COMMON_DEFINE "-DOPENDHCPD_ON")
MESSAGE("Select Option USED_OPENDHCPD")
ADD_SUBDIRECTORY(srcs/opendhcp183)
ENDIF ()
IF (USED_OPENDHCPDDNS)
LIST(APPEND COMMON_DEFINE "-DOPENDHCPDDNS_ON")
MESSAGE("Select Option USED_OPENDHCPDDNS")
ADD_SUBDIRECTORY(srcs/dual_server)
ENDIF ()
IF (VCPE_AGENT)
MESSAGE("Select Option VCPE_AGENT")
ENDIF ()
IF (USED_SQLITE)
MESSAGE("Select Option USED_SQLITE")
LIST(APPEND COMMON_DEFINE "-DSQLITE_ON")
ENDIF ()
IF (USED_MYSQL)
MESSAGE("Select Option USED_MYSQL")
LIST(APPEND COMMON_DEFINE "-DUSED_MYSQL")
ENDIF ()
IF (USED_REDIS)
MESSAGE("Select Option USED_REDIS")
LIST(APPEND COMMON_DEFINE "-DUSED_REDIS")
ENDIF ()
IF (USED_SQLITE_CRYPTO)
LIST(APPEND COMMON_DEFINE "-DSQLITE_CRYPTO_ON")
MESSAGE("Select Option USED_SQLITE_CRYPTO")
ENDIF ()
IF (USED_LWIP OR VCPE_AGENT)
ADD_SUBDIRECTORY(srcs/lwip)
ENDIF ()
ADD_SUBDIRECTORY(srcs)
ADD_SUBDIRECTORY(srcs/libs)
ADD_SUBDIRECTORY(srcs/service)
IF (BUILD_TESTING)
ADD_SUBDIRECTORY(unit_test)
ENDIF ()