From 1a1ba0434b9e4c640feb739db58538f8561f288f Mon Sep 17 00:00:00 2001 From: jinhai Date: Fri, 12 Apr 2019 20:58:45 +0800 Subject: [PATCH] Add cpp source code Former-commit-id: d2df17911de6634f70dfa812211d0a6f52aadb18 --- cpp/CMakeLists.txt | 66 +++++++++++++++++++ cpp/README.md | 0 cpp/cmake/Modules/ConfigureGoogleTest.cmake | 59 +++++++++++++++++ .../Templates/GoogleTest.CMakeLists.txt.cmake | 12 ++++ cpp/src/CMakeLists.txt | 11 ++++ cpp/src/main.cpp | 9 +++ cpp/unittest/CMakeLists.txt | 19 ++++++ cpp/unittest/log/CMakeLists.txt | 10 +++ cpp/unittest/log/log_tests.cpp | 11 ++++ cpp/unittest/vecwise_test.cpp | 12 ++++ 10 files changed, 209 insertions(+) create mode 100644 cpp/CMakeLists.txt create mode 100644 cpp/README.md create mode 100644 cpp/cmake/Modules/ConfigureGoogleTest.cmake create mode 100644 cpp/cmake/Templates/GoogleTest.CMakeLists.txt.cmake create mode 100644 cpp/src/CMakeLists.txt create mode 100644 cpp/src/main.cpp create mode 100644 cpp/unittest/CMakeLists.txt create mode 100644 cpp/unittest/log/CMakeLists.txt create mode 100644 cpp/unittest/log/log_tests.cpp create mode 100644 cpp/unittest/vecwise_test.cpp diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt new file mode 100644 index 0000000000..93a0f0138e --- /dev/null +++ b/cpp/CMakeLists.txt @@ -0,0 +1,66 @@ +#------------------------------------------------------------------------------- +# Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved +# Unauthorized copying of this file, via any medium is strictly prohibited. +# Proprietary and confidential. +#------------------------------------------------------------------------------- + +cmake_minimum_required(VERSION 3.12) + +project(vecwise_engine) + +set(CMAKE_CXX_STANDARD 14) + +if(CMAKE_SYSTEM_PROCESSOR MATCHES "(x86)|(X86)|(amd64)|(AMD64)") + message("building vecwise_engine on x86 architecture") + set(VECWISE_BUILD_ARCH x86_64) +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "(ppc)") + message("building vecwise_engine on ppc architecture") + set(VECWISE_BUILD_ARCH ppc64le) +else() + message("unknown processor type") + message("CMAKE_SYSTEM_PROCESSOR=${CMAKE_SYSTEM_PROCESSOR}") + set(VECWISE_BUILD_ARCH unknown) +endif() + +if(DEFINED UNIX) + message("building vecwise on Unix") + set(VECWISE_BUILD_SYSTEM macos) +elseif(DEFINED APPLE) + message("building vecwise on MacOS") + set(VECWISE_BUILD_SYSTEM unix) +else() + message("unknown OS") + set(VECWISE_BUILD_SYSTEM unknown) +endif () + +if(CMAKE_BUILD_TYPE STREQUAL "Release") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -fPIC") +else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g -fPIC") +endif() + +set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/" ${CMAKE_MODULE_PATH}) + +set(VECWISE_ENGINE_INCLUDE ${PROJECT_SOURCE_DIR}/include) +set(VECWISE_ENGINE_SRC ${PROJECT_SOURCE_DIR}/src) + +add_compile_definitions(PROFILER=${PROFILER}) + +include_directories(${VECWISE_ENGINE_INCLUDE}) +include_directories(${VECWISE_ENGINE_SRC}) + +add_subdirectory(src) + +if (BUILD_UNIT_TEST) + include(CTest) + include(ConfigureGoogleTest) + + if(GTEST_FOUND) + message(STATUS "Google C++ Testing Framework (Google Test) found in ${GTEST_ROOT}") + include_directories(${GTEST_INCLUDE_DIR}) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/unittest) + else() + message(AUTHOR_WARNING "Google C++ Testing Framework (Google Test) not found: automated tests are disabled.") + endif(GTEST_FOUND) + +endif(BUILD_UNIT_TEST) diff --git a/cpp/README.md b/cpp/README.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/cpp/cmake/Modules/ConfigureGoogleTest.cmake b/cpp/cmake/Modules/ConfigureGoogleTest.cmake new file mode 100644 index 0000000000..d2f2f2c666 --- /dev/null +++ b/cpp/cmake/Modules/ConfigureGoogleTest.cmake @@ -0,0 +1,59 @@ +set(GTEST_ROOT "${CMAKE_BINARY_DIR}/googletest") + +set(GTEST_CMAKE_ARGS "") + # " -Dgtest_build_samples=ON" + # " -DCMAKE_VERBOSE_MAKEFILE=ON") + +if(NOT CMAKE_CXX11_ABI) + message(STATUS "GTEST: Disabling the GLIBCXX11 ABI") + list(APPEND GTEST_CMAKE_ARGS " -DCMAKE_C_FLAGS=-D_GLIBCXX_USE_CXX11_ABI=0") + list(APPEND GTEST_CMAKE_ARGS " -DCMAKE_CXX_FLAGS=-D_GLIBCXX_USE_CXX11_ABI=0") +elseif(CMAKE_CXX11_ABI) + message(STATUS "GTEST: Enabling the GLIBCXX11 ABI") + list(APPEND GTEST_CMAKE_ARGS " -DCMAKE_C_FLAGS=-D_GLIBCXX_USE_CXX11_ABI=1") + list(APPEND GTEST_CMAKE_ARGS " -DCMAKE_CXX_FLAGS=-D_GLIBCXX_USE_CXX11_ABI=1") +endif(NOT CMAKE_CXX11_ABI) + +configure_file("${CMAKE_SOURCE_DIR}/cmake/Templates/GoogleTest.CMakeLists.txt.cmake" + "${GTEST_ROOT}/CMakeLists.txt") + +file(MAKE_DIRECTORY "${GTEST_ROOT}/build") +file(MAKE_DIRECTORY "${GTEST_ROOT}/install") + +execute_process(COMMAND ${CMAKE_COMMAND} -G ${CMAKE_GENERATOR} . + RESULT_VARIABLE GTEST_CONFIG + WORKING_DIRECTORY ${GTEST_ROOT}) + +if(GTEST_CONFIG) + message(FATAL_ERROR "Configuring GoogleTest failed: " ${GTEST_CONFIG}) +endif(GTEST_CONFIG) + +set(PARALLEL_BUILD -j) +if($ENV{PARALLEL_LEVEL}) + set(NUM_JOBS $ENV{PARALLEL_LEVEL}) + set(PARALLEL_BUILD "${PARALLEL_BUILD}${NUM_JOBS}") +endif($ENV{PARALLEL_LEVEL}) + +if(${NUM_JOBS}) + if(${NUM_JOBS} EQUAL 1) + message(STATUS "GTEST BUILD: Enabling Sequential CMake build") + elseif(${NUM_JOBS} GREATER 1) + message(STATUS "GTEST BUILD: Enabling Parallel CMake build with ${NUM_JOBS} jobs") + endif(${NUM_JOBS} EQUAL 1) +else() + message(STATUS "GTEST BUILD: Enabling Parallel CMake build with all threads") +endif(${NUM_JOBS}) + +execute_process(COMMAND ${CMAKE_COMMAND} --build .. -- ${PARALLEL_BUILD} + RESULT_VARIABLE GTEST_BUILD + WORKING_DIRECTORY ${GTEST_ROOT}/build) + +if(GTEST_BUILD) + message(FATAL_ERROR "Building GoogleTest failed: " ${GTEST_BUILD}) +endif(GTEST_BUILD) + +message(STATUS "GoogleTest installed here: " ${GTEST_ROOT}/install) +set(GTEST_INCLUDE_DIR "${GTEST_ROOT}/install/include") +set(GTEST_LIBRARY_DIR "${GTEST_ROOT}/install/lib") +set(GTEST_FOUND TRUE) + diff --git a/cpp/cmake/Templates/GoogleTest.CMakeLists.txt.cmake b/cpp/cmake/Templates/GoogleTest.CMakeLists.txt.cmake new file mode 100644 index 0000000000..fe0035e240 --- /dev/null +++ b/cpp/cmake/Templates/GoogleTest.CMakeLists.txt.cmake @@ -0,0 +1,12 @@ +cmake_minimum_required(VERSION 3.12) + +include(ExternalProject) + +ExternalProject_Add(GoogleTest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG release-1.8.0 + SOURCE_DIR "${GTEST_ROOT}/googletest" + BINARY_DIR "${GTEST_ROOT}/build" + INSTALL_DIR "${GTEST_ROOT}/install" + CMAKE_ARGS ${GTEST_CMAKE_ARGS} -DCMAKE_INSTALL_PREFIX=${GTEST_ROOT}/install) + diff --git a/cpp/src/CMakeLists.txt b/cpp/src/CMakeLists.txt new file mode 100644 index 0000000000..5b1d303ada --- /dev/null +++ b/cpp/src/CMakeLists.txt @@ -0,0 +1,11 @@ +#------------------------------------------------------------------------------- +# Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved +# Unauthorized copying of this file, via any medium is strictly prohibited. +# Proprietary and confidential. +#------------------------------------------------------------------------------- + +set(vecwise_engine_src + ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp + ) + +add_library(vecwise_engine SHARED ${vecwise_engine_src}) \ No newline at end of file diff --git a/cpp/src/main.cpp b/cpp/src/main.cpp new file mode 100644 index 0000000000..41c259a45b --- /dev/null +++ b/cpp/src/main.cpp @@ -0,0 +1,9 @@ +//////////////////////////////////////////////////////////////////////////////// +// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved +// Unauthorized copying of this file, via any medium is strictly prohibited. +// Proprietary and confidential. +//////////////////////////////////////////////////////////////////////////////// + +void test() { + return ; +} \ No newline at end of file diff --git a/cpp/unittest/CMakeLists.txt b/cpp/unittest/CMakeLists.txt new file mode 100644 index 0000000000..945bf887cb --- /dev/null +++ b/cpp/unittest/CMakeLists.txt @@ -0,0 +1,19 @@ +#------------------------------------------------------------------------------- +# Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved +# Unauthorized copying of this file, via any medium is strictly prohibited. +# Proprietary and confidential. +#------------------------------------------------------------------------------- +link_directories( + "${CMAKE_BINARY_DIR}/lib" + "${GTEST_LIBRARY_DIR}" +) + +set(unittest_srcs + ${CMAKE_CURRENT_SOURCE_DIR}/vecwise_test.cpp) + +set(unittest_libs + gtest + gmock + pthread) + +add_subdirectory(log) \ No newline at end of file diff --git a/cpp/unittest/log/CMakeLists.txt b/cpp/unittest/log/CMakeLists.txt new file mode 100644 index 0000000000..cd677ab495 --- /dev/null +++ b/cpp/unittest/log/CMakeLists.txt @@ -0,0 +1,10 @@ +#------------------------------------------------------------------------------- +# Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved +# Unauthorized copying of this file, via any medium is strictly prohibited. +# Proprietary and confidential. +#------------------------------------------------------------------------------- +set(log_test_src ${unittest_srcs} log_tests.cpp) + +add_executable(log_tests ${log_test_src}) + +target_link_libraries(log_tests ${unittest_libs}) diff --git a/cpp/unittest/log/log_tests.cpp b/cpp/unittest/log/log_tests.cpp new file mode 100644 index 0000000000..df9e581959 --- /dev/null +++ b/cpp/unittest/log/log_tests.cpp @@ -0,0 +1,11 @@ +//////////////////////////////////////////////////////////////////////////////// +// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved +// Unauthorized copying of this file, via any medium is strictly prohibited. +// Proprietary and confidential. +//////////////////////////////////////////////////////////////////////////////// +#include + + +TEST(LOG_TESTS, INIT_TEST) { + ASSERT_EQ(true); +} \ No newline at end of file diff --git a/cpp/unittest/vecwise_test.cpp b/cpp/unittest/vecwise_test.cpp new file mode 100644 index 0000000000..55620d9f9d --- /dev/null +++ b/cpp/unittest/vecwise_test.cpp @@ -0,0 +1,12 @@ +//////////////////////////////////////////////////////////////////////////////// +// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved +// Unauthorized copying of this file, via any medium is strictly prohibited. +// Proprietary and confidential. +//////////////////////////////////////////////////////////////////////////////// +#include + + +int main(int argc, char **argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +}