diff --git a/CMakeLists.txt b/CMakeLists.txt index f1c8427..67ee139 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,60 +12,59 @@ OPTION(USED_REDIS "Add redis database support for vCPE" OFF) OPTION(USED_MYSQL "Add mysql database support for vCPE" OFF) OPTION(USED_SQLITE "Add sqlite3 database support for vCPE" OFF) - SET(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:/usr/local/lib/pkgconfig") SET(URI_HOME "${CMAKE_SOURCE_DIR}/libs") EXECUTE_PROCESS(COMMAND git describe --tags --always --dirty=-dev - OUTPUT_VARIABLE GIT_TAG) + OUTPUT_VARIABLE GIT_TAG) -if ("${GIT_TAG}" STREQUAL "") +IF ("${GIT_TAG}" STREQUAL "") STRING(TIMESTAMP COMPILE_TIME %Y-%m-%d_%H:%M:%S) SET(GIT_VERSION ${COMPILE_TIME}) -else () +ELSE () STRING(REGEX REPLACE "\n$" "" GIT_TAG ${GIT_TAG}) SET(GIT_VERSION ${GIT_TAG}) -endif () +ENDIF () MESSAGE("Version: " ${GIT_VERSION}) -if (USED_LWIP) +IF (USED_LWIP) LIST(APPEND COMMON_DEFINE "-DLWIP_ON") -endif () +ENDIF () -if (USED_OPENDHCPD) +IF (USED_OPENDHCPD) LIST(APPEND COMMON_DEFINE "-DOPENDHCPD_ON") -endif () +ENDIF () -if (USED_OPENDHCPDDNS) +IF (USED_OPENDHCPDDNS) LIST(APPEND COMMON_DEFINE "-DOPENDHCPDDNS_ON") -endif () +ENDIF () -if (VCPE_AGENT) +IF (VCPE_AGENT) MESSAGE("Select Option VCPE_AGENT") -endif () +ENDIF () -if (USED_LWIP) +IF (USED_LWIP) MESSAGE("Select Option USED_LWIP") -endif () +ENDIF () -if (USED_SQLITE) +IF (USED_SQLITE) MESSAGE("Select Option USED_SQLITE") -endif () +ENDIF () -if (USED_OPENDHCPD) +IF (USED_OPENDHCPD) MESSAGE("Select Option USED_OPENDHCPD") ADD_SUBDIRECTORY(srcs/open_dhcp) -endif () +ENDIF () -if (USED_OPENDHCPDDNS) +IF (USED_OPENDHCPDDNS) MESSAGE("Select Option USED_OPENDHCPDDNS") ADD_SUBDIRECTORY(srcs/dual_server) -endif () +ENDIF () -if (USED_LWIP OR VCPE_AGENT) +IF (USED_LWIP OR VCPE_AGENT) ADD_SUBDIRECTORY(srcs/lwip) -endif () +ENDIF () ADD_SUBDIRECTORY(srcs) ADD_SUBDIRECTORY(srcs/libs) diff --git a/srcs/CMakeLists.txt b/srcs/CMakeLists.txt index 7e2a354..20048d2 100644 --- a/srcs/CMakeLists.txt +++ b/srcs/CMakeLists.txt @@ -1,12 +1,12 @@ SET(PROJECT_TARGET vcpe_main) -if (VCPE_AGENT) +IF (VCPE_AGENT) SET(PROJECT_TARGET_AGENT vcpe_agent) -endif () +ENDIF () PROJECT(${PROJECT_TARGET}) -include(ExternalProject) +INCLUDE(ExternalProject) # 判断依赖库是否存在 FIND_PACKAGE(PkgConfig) @@ -22,55 +22,53 @@ LIST(APPEND COMMON_LIBS "-lpthread") ADD_DEFINITIONS(${COMMON_DEFINE}) INCLUDE_DIRECTORIES(include ./ ./include ./libs/include ./lwip/src/include ./lwip/src/arch_linux/include - ./httpserver/include ${COMMON_INCLUDE}) + ./httpserver/include ${COMMON_INCLUDE}) SET(CMAKE_C_STANDARD 99) FILE(GLOB VCPE_HEADS include/*.h include/uthash/*.h include/s2j/*.h - ./httpserver/include/*.h ./httpserver/src/haywire/*.h ./httpserver/src/haywire/configuration/*.h) + ./httpserver/include/*.h ./httpserver/src/haywire/*.h ./httpserver/src/haywire/configuration/*.h) -if (USED_LWIP) +IF (USED_LWIP) AUX_SOURCE_DIRECTORY(pppoe VCPE_SRC) AUX_SOURCE_DIRECTORY(user VCPE_SRC) -endif () - +ENDIF () ADD_EXECUTABLE(${PROJECT_TARGET} ${VCPE_SRC} ${VCPE_HEADS} vcpe_main.c) -if (VCPE_AGENT) +IF (VCPE_AGENT) ADD_EXECUTABLE(${PROJECT_TARGET_AGENT} ${VCPE_HEADS} vcpe_agent.c) -endif () +ENDIF () -if (USED_LWIP) +IF (USED_LWIP) TARGET_LINK_LIBRARIES(${PROJECT_TARGET} lwip_linux) -endif () +ENDIF () -if (USED_OPENDHCPDDNS) +IF (USED_OPENDHCPDDNS) TARGET_LINK_LIBRARIES(${PROJECT_TARGET} dualserverd) -else () +ELSE () TARGET_LINK_LIBRARIES(${PROJECT_TARGET} opendhcpd) -endif () +ENDIF () TARGET_LINK_LIBRARIES(${PROJECT_TARGET} common) TARGET_LINK_LIBRARIES(${PROJECT_TARGET} ${COMMON_LIBS}) - -if (VCPE_AGENT) +IF (VCPE_AGENT) TARGET_LINK_LIBRARIES(${PROJECT_TARGET_AGENT} common ${COMMON_LIBS}) -endif () +ENDIF () # 自动复制配置文件到运行路径 ADD_CUSTOM_COMMAND(TARGET ${PROJECT_TARGET} - POST_BUILD - COMMAND ${CMAKE_COMMAND} -E - make_directory "${CMAKE_CURRENT_BINARY_DIR}/config/" - COMMAND ${CMAKE_COMMAND} -E - make_directory "${CMAKE_CURRENT_BINARY_DIR}/log/" - COMMAND ${CMAKE_COMMAND} -E - copy_if_different "${PROJECT_SOURCE_DIR}/../config/opendhcp.ini" "${CMAKE_CURRENT_BINARY_DIR}/config/" - COMMAND ${CMAKE_COMMAND} -E - copy_if_different "${PROJECT_SOURCE_DIR}/../config/vcpe.cfg" "${CMAKE_CURRENT_BINARY_DIR}/config/" - COMMAND ${CMAKE_COMMAND} -E - copy_if_different "${PROJECT_SOURCE_DIR}/../config/zlog.conf" "${CMAKE_CURRENT_BINARY_DIR}/config/" - COMMAND ${CMAKE_COMMAND} -E - copy_if_different "${PROJECT_SOURCE_DIR}/../config/banner.txt" "${CMAKE_CURRENT_BINARY_DIR}/config/") + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E + make_directory "${CMAKE_CURRENT_BINARY_DIR}/config/" + COMMAND ${CMAKE_COMMAND} -E + make_directory "${CMAKE_CURRENT_BINARY_DIR}/log/" + COMMAND ${CMAKE_COMMAND} -E + copy_if_different "${PROJECT_SOURCE_DIR}/../config/opendhcp.ini" "${CMAKE_CURRENT_BINARY_DIR}/config/" + COMMAND ${CMAKE_COMMAND} -E + copy_if_different "${PROJECT_SOURCE_DIR}/../config/vcpe.cfg" "${CMAKE_CURRENT_BINARY_DIR}/config/" + COMMAND ${CMAKE_COMMAND} -E + copy_if_different "${PROJECT_SOURCE_DIR}/../config/zlog.conf" "${CMAKE_CURRENT_BINARY_DIR}/config/" + COMMAND ${CMAKE_COMMAND} -E + copy_if_different "${PROJECT_SOURCE_DIR}/../config/banner.txt" "${CMAKE_CURRENT_BINARY_DIR}/config/") diff --git a/srcs/httpserver/CMakeLists.txt b/srcs/httpserver/CMakeLists.txt index 79f17cd..9d662bf 100644 --- a/srcs/httpserver/CMakeLists.txt +++ b/srcs/httpserver/CMakeLists.txt @@ -3,28 +3,28 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.10 FATAL_ERROR) # ---------------------------------------- # Haywire # ---------------------------------------- -project(haywire C) +PROJECT(haywire C) #set(CMAKE_BUILD_TYPE RelWithDebInfo) -add_definitions(-std=gnu99) +ADD_DEFINITIONS(-std=gnu99) #add_definitions(-mavx) -add_definitions(-msse4.1) -add_definitions(-pedantic) -add_definitions(-O3) -add_definitions(-Wall) -add_definitions(-Wextra) -add_definitions(-Wcast-align) -add_definitions(-w) +ADD_DEFINITIONS(-msse4.1) +ADD_DEFINITIONS(-pedantic) +ADD_DEFINITIONS(-O3) +ADD_DEFINITIONS(-Wall) +ADD_DEFINITIONS(-Wextra) +ADD_DEFINITIONS(-Wcast-align) +ADD_DEFINITIONS(-w) -if (UNIX) - add_definitions(-DUNIX) -endif (UNIX) +IF (UNIX) + ADD_DEFINITIONS(-DUNIX) +ENDIF (UNIX) INCLUDE_DIRECTORIES(./include ./src ../libs/include) -file(GLOB_RECURSE HW_HEADS - ./src/haywire/*.h - ./src/haywire/configuration/*.h) +FILE(GLOB_RECURSE HW_HEADS + ./src/haywire/*.h + ./src/haywire/configuration/*.h) AUX_SOURCE_DIRECTORY(src/haywire HW_SRC) AUX_SOURCE_DIRECTORY(src/haywire/configuration HW_SRC) @@ -33,7 +33,7 @@ INCLUDE_DIRECTORIES(. ./include) #find_package(Threads REQUIRED) -add_library(haywire STATIC ${HW_SRC} ${HW_HEADS}) -target_link_libraries(haywire -luv -pthread) +ADD_LIBRARY(haywire STATIC ${HW_SRC} ${HW_HEADS}) +TARGET_LINK_LIBRARIES(haywire -luv -pthread) diff --git a/srcs/libs/CMakeLists.txt b/srcs/libs/CMakeLists.txt index 42b3c77..2950bd6 100644 --- a/srcs/libs/CMakeLists.txt +++ b/srcs/libs/CMakeLists.txt @@ -2,11 +2,9 @@ SET(LIB_PROJECT_TARGET common) PROJECT(${LIB_PROJECT_TARGET}) -include(ExternalProject) - INCLUDE_DIRECTORIES(include - ./ ./include ../lwip/src/include ../lwip/src/arch_linux/include ../include - ../httpserver/include ../httpserver/src/haywire ../httpserver/src/haywire/configuration) + ./ ./include ../lwip/src/include ../lwip/src/arch_linux/include ../include + ../httpserver/include ../httpserver/src/haywire ../httpserver/src/haywire/configuration) FILE(GLOB C_HEADS include/*.h include/uthash/*.h include/s2j/*.h vector/*.h) AUX_SOURCE_DIRECTORY(json C_SRC) @@ -23,35 +21,34 @@ AUX_SOURCE_DIRECTORY(cmdline C_SRC) AUX_SOURCE_DIRECTORY(crypto C_SRC) AUX_SOURCE_DIRECTORY(hardware C_SRC) -if (USED_REDIS) +IF (USED_REDIS) ADD_DEFINITIONS(-DUSED_REDIS) -endif () +ENDIF () -if (USED_SQLITE) +IF (USED_SQLITE) ADD_DEFINITIONS(-DUSED_SQLITE) AUX_SOURCE_DIRECTORY(database/sqlite3 C_SRC) -endif () +ENDIF () -if (USED_MYSQL) +IF (USED_MYSQL) ADD_DEFINITIONS(-DUSED_MYSQL) -endif () +ENDIF () SET(CMAKE_C_STANDARD 99) SET_SOURCE_FILES_PROPERTIES(misc/zvector.c PROPERTIES COMPILE_FLAGS "-Wall -Wextra -flto") -if (USED_SQLITE) +IF (USED_SQLITE) SET_SOURCE_FILES_PROPERTIES(database/sqlite3/sqlite3.c PROPERTIES - COMPILE_FLAGS "-DSQLITE_HAS_CODEC \ + COMPILE_FLAGS "-DSQLITE_HAS_CODEC \ -DSQLCIPHER_CRYPTO_OPENSSL -DSQLITE_OS_UNIX=1 \ -D_HAVE_SQLITE_CONFIG_H -DBUILD_sqlite -DNDEBUG -DSQLITE_THREADSAFE=1 \ -DSQLITE_ENABLE_MATH_FUNCTIONS -DSQLITE_ENABLE_UPDATE_DELETE_LIMIT \ -DSQLITE_ENABLE_MATH_FUNCTIONS -DSQLITE_ENABLE_UPDATE_DELETE_LIMIT \ -DSQLITE_HAVE_ZLIB=1 -DSQLITE_TEMP_STORE=2") -endif () +ENDIF () ADD_DEFINITIONS(-DBUILD_VERSION="${GIT_VERSION}" ${COMMON_DEFINE}) - LINK_LIBRARIES(${COMMON_LIBS}) ADD_LIBRARY(${LIB_PROJECT_TARGET} ${C_SRC} ${C_HEADS})