🎉 init(repo): first git commit
This commit is contained in:
26
CMakeLists.txt
Normal file
26
CMakeLists.txt
Normal file
@@ -0,0 +1,26 @@
|
||||
cmake_minimum_required(VERSION 3.14)
|
||||
project(vapp)
|
||||
|
||||
# GoogleTest requires at least C++11
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
|
||||
#find required package
|
||||
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
|
||||
include(Version)
|
||||
find_package(PkgConfig REQUIRED)
|
||||
find_package(Threads REQUIRED)
|
||||
find_package(PCAP REQUIRED)
|
||||
pkg_check_modules(SYSTEMD REQUIRED systemd)
|
||||
|
||||
#add vendor and source directory
|
||||
add_subdirectory(vendor)
|
||||
add_subdirectory(src)
|
||||
|
||||
|
||||
#add gtest
|
||||
enable_testing()
|
||||
add_subdirectory(test)
|
||||
|
||||
|
||||
|
||||
|
||||
74
cmake/FindPCAP.cmake
Normal file
74
cmake/FindPCAP.cmake
Normal file
@@ -0,0 +1,74 @@
|
||||
# - Try to find libpcap include dirs and libraries
|
||||
#
|
||||
# Usage of this module as follows:
|
||||
#
|
||||
# find_package(PCAP)
|
||||
#
|
||||
# Variables used by this module, they can change the default behaviour and need
|
||||
# to be set before calling find_package:
|
||||
#
|
||||
# PCAP_ROOT_DIR Set this variable to the root installation of
|
||||
# libpcap if the module has problems finding the
|
||||
# proper installation path.
|
||||
#
|
||||
# Variables defined by this module:
|
||||
#
|
||||
# PCAP_FOUND System has libpcap, include and library dirs found
|
||||
# PCAP_INCLUDE_DIR The libpcap include directories.
|
||||
# PCAP_LIBRARY The libpcap library (possibly includes a thread
|
||||
# library e.g. required by pf_ring's libpcap)
|
||||
# HAVE_PF_RING If a found version of libpcap supports PF_RING
|
||||
|
||||
find_path(PCAP_ROOT_DIR
|
||||
NAMES include/pcap.h
|
||||
)
|
||||
|
||||
find_path(PCAP_INCLUDE_DIR
|
||||
NAMES pcap.h
|
||||
HINTS ${PCAP_ROOT_DIR}/include
|
||||
)
|
||||
|
||||
find_library(PCAP_LIBRARY
|
||||
NAMES pcap
|
||||
HINTS ${PCAP_ROOT_DIR}/lib
|
||||
)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(PCAP DEFAULT_MSG
|
||||
PCAP_LIBRARY
|
||||
PCAP_INCLUDE_DIR
|
||||
)
|
||||
|
||||
include(CheckCSourceCompiles)
|
||||
set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARY})
|
||||
check_c_source_compiles("int main() { return 0; }" PCAP_LINKS_SOLO)
|
||||
set(CMAKE_REQUIRED_LIBRARIES)
|
||||
|
||||
# check if linking against libpcap also needs to link against a thread library
|
||||
if (NOT PCAP_LINKS_SOLO)
|
||||
find_package(Threads)
|
||||
if (THREADS_FOUND)
|
||||
set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARY} ${CMAKE_THREAD_LIBS_INIT})
|
||||
check_c_source_compiles("int main() { return 0; }" PCAP_NEEDS_THREADS)
|
||||
set(CMAKE_REQUIRED_LIBRARIES)
|
||||
endif ()
|
||||
if (THREADS_FOUND AND PCAP_NEEDS_THREADS)
|
||||
set(_tmp ${PCAP_LIBRARY} ${CMAKE_THREAD_LIBS_INIT})
|
||||
list(REMOVE_DUPLICATES _tmp)
|
||||
set(PCAP_LIBRARY ${_tmp}
|
||||
CACHE STRING "Libraries needed to link against libpcap" FORCE)
|
||||
else ()
|
||||
message(FATAL_ERROR "Couldn't determine how to link against libpcap")
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
include(CheckFunctionExists)
|
||||
set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARY})
|
||||
check_function_exists(pcap_get_pfring_id HAVE_PF_RING)
|
||||
set(CMAKE_REQUIRED_LIBRARIES)
|
||||
|
||||
mark_as_advanced(
|
||||
PCAP_ROOT_DIR
|
||||
PCAP_INCLUDE_DIR
|
||||
PCAP_LIBRARY
|
||||
)
|
||||
58
cmake/Version.cmake
Normal file
58
cmake/Version.cmake
Normal file
@@ -0,0 +1,58 @@
|
||||
|
||||
# Using autorevision.sh to generate version information
|
||||
|
||||
set(__SOURCE_AUTORESIVISION ${CMAKE_SOURCE_DIR}/cmake/autorevision.sh)
|
||||
set(__AUTORESIVISION ${CMAKE_BINARY_DIR}/autorevision.sh)
|
||||
set(__VERSION_CACHE ${CMAKE_BINARY_DIR}/version.txt)
|
||||
set(__VERSION_CONFIG ${CMAKE_BINARY_DIR}/version.cmake)
|
||||
|
||||
file(COPY ${__SOURCE_AUTORESIVISION} DESTINATION ${CMAKE_BINARY_DIR}
|
||||
FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE
|
||||
WORLD_READ WORLD_EXECUTE)
|
||||
|
||||
# execute autorevision.sh to generate version information
|
||||
execute_process(COMMAND ${__AUTORESIVISION} -t cmake -o ${__VERSION_CACHE}
|
||||
OUTPUT_FILE ${__VERSION_CONFIG} ERROR_QUIET)
|
||||
include(${__VERSION_CONFIG})
|
||||
|
||||
# extract major, minor, patch version from git tag
|
||||
string(REGEX REPLACE "^v([0-9]+)\\..*" "\\1" VERSION_MAJOR "${VCS_TAG}")
|
||||
string(REGEX REPLACE "^v[0-9]+\\.([0-9]+).*" "\\1" VERSION_MINOR "${VCS_TAG}")
|
||||
string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_PATCH "${VCS_TAG}")
|
||||
|
||||
string(REGEX REPLACE "[T\\:\\+\\-]" "" VERSION_DATE "${VCS_DATE}")
|
||||
|
||||
if(VERSION_DAILY_BUILD)
|
||||
set(VERSION_PATCH ${VERSION_PATCH}.${VERSION_DATE})
|
||||
endif()
|
||||
|
||||
|
||||
if(NOT VERSION_MAJOR)
|
||||
set(VERSION_MAJOR 1)
|
||||
endif()
|
||||
|
||||
if(NOT VERSION_MINOR)
|
||||
set(VERSION_MINOR 0)
|
||||
endif()
|
||||
|
||||
if(NOT VERSION_PATCH)
|
||||
set(VERSION_PATCH 0)
|
||||
endif()
|
||||
|
||||
set(VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
|
||||
set(VERSION_BUILD "${VCS_SHORT_HASH}")
|
||||
|
||||
# print information
|
||||
message(STATUS "Version: ${VERSION}-${VERSION_BUILD}")
|
||||
|
||||
option(DEFINE_GIT_VERSION "Set DEFINE_GIT_VERSION to TRUE or FALSE" TRUE)
|
||||
|
||||
if(DEFINE_GIT_VERSION)
|
||||
|
||||
set(GIT_VERSION "${VERSION}-${CMAKE_BUILD_TYPE}-${VERSION_BUILD}-${VCS_BRANCH}-${VCS_DATE}")
|
||||
message(STATUS "GIT_VERSION: ${GIT_VERSION}")
|
||||
string(REGEX REPLACE "[-:+/\\.]" "_" GIT_VERSION ${GIT_VERSION})
|
||||
|
||||
add_definitions(-DGIT_VERSION=\"${GIT_VERSION}\")
|
||||
|
||||
endif()
|
||||
1268
cmake/autorevision.sh
Normal file
1268
cmake/autorevision.sh
Normal file
File diff suppressed because it is too large
Load Diff
3
src/CMakeLists.txt
Normal file
3
src/CMakeLists.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
add_executable(vapp
|
||||
main
|
||||
)
|
||||
4
src/main.cc
Normal file
4
src/main.cc
Normal file
@@ -0,0 +1,4 @@
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
14
test/CMakeLists.txt
Normal file
14
test/CMakeLists.txt
Normal file
@@ -0,0 +1,14 @@
|
||||
|
||||
# 开启测试
|
||||
|
||||
add_executable(gtest_vapp
|
||||
gtest_main.cc
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
gtest_vapp
|
||||
gtest_main
|
||||
)
|
||||
|
||||
include(GoogleTest)
|
||||
gtest_discover_tests(gtest_vapp)
|
||||
14
test/gtest_main.cc
Normal file
14
test/gtest_main.cc
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
|
||||
TEST(EQ_Test, Always_True) {
|
||||
EXPECT_EQ(1, 1);
|
||||
}
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
int ret=0;
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
ret=RUN_ALL_TESTS();
|
||||
return ret;
|
||||
}
|
||||
10
vendor/CMakeLists.txt
vendored
Normal file
10
vendor/CMakeLists.txt
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
googletest
|
||||
#URL https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip
|
||||
URL ${CMAKE_CURRENT_SOURCE_DIR}/googletest-release-1.8.0.tar.gz
|
||||
URL_MD5 16877098823401d1bf2ed7891d7dce36
|
||||
)
|
||||
# For Windows: Prevent overriding the parent project's compiler/linker settings
|
||||
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
||||
FetchContent_MakeAvailable(googletest)
|
||||
BIN
vendor/googletest-release-1.8.0.tar.gz
vendored
Normal file
BIN
vendor/googletest-release-1.8.0.tar.gz
vendored
Normal file
Binary file not shown.
Reference in New Issue
Block a user