From adf4694c5ddd67220e9f566029ca5ca0370f1cc7 Mon Sep 17 00:00:00 2001 From: Kaiser-Yang <624626089@qq.com> Date: Fri, 3 May 2024 15:09:03 +0800 Subject: [PATCH] Initialize a cmake project with google test Finish initialization. We add google test, .clang-tidy and .clang-format. And we finish CMakeLists.txt in root directory and test directory. --- .clang-format | 23 +++++++++++++++++++++++ .clang-tidy | 36 ++++++++++++++++++++++++++++++++++++ .gitignore | 10 ++++++++++ CMakeLists.txt | 32 ++++++++++++++++++++++++++++++++ include/mca.h | 0 src/mca.cpp | 0 test/CMakeLists.txt | 35 +++++++++++++++++++++++++++++++++++ test/src/mca_test.cpp | 1 + 8 files changed, 137 insertions(+) create mode 100644 .clang-format create mode 100644 .clang-tidy create mode 100644 CMakeLists.txt create mode 100644 include/mca.h create mode 100644 src/mca.cpp create mode 100644 test/CMakeLists.txt create mode 100644 test/src/mca_test.cpp diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..ddc8e2d --- /dev/null +++ b/.clang-format @@ -0,0 +1,23 @@ +--- +Language: Cpp +BasedOnStyle: Google +AlignConsecutiveAssignments: true +AlignConsecutiveDeclarations: false +AlignConsecutiveMacros: true +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortFunctionsOnASingleLine: All +AllowShortBlocksOnASingleLine: true +AllowShortCaseLabelsOnASingleLine: true +AllowShortIfStatementsOnASingleLine: true +AllowShortLoopsOnASingleLine: true +AlwaysBreakAfterReturnType: None +AlwaysBreakTemplateDeclarations: true +BreakBeforeTernaryOperators: false +BinPackArguments: false +BinPackParameters: false +ColumnLimit: 100 +DerivePointerAlignment: false +IndentWidth: 4 +MaxEmptyLinesToKeep: 1 +PointerAlignment: Right +SortIncludes: true diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..45f6067 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,36 @@ +Checks: > + -*, + cppcoreguidelines-no-malloc, modernize-deprecated-headers, + modernize-loop-convert, modernize-make-shared, modernize-pass-by-value, modernize-make-unique, + modernize-raw-string-literal, modernize-redundant-void-arg, modernize-replace-auto-ptr, + modernize-replace-random-shuffle, modernize-return-braced-init-list, modernize-shrink-to-fit, + modernize-unary-static-assert, modernize-use-bool-literals, modernize-use-default-member-init, + modernize-use-emplace, modernize-use-equals-default, modernize-use-equals-delete, + modernize-use-noexcept, modernize-use-nullptr, modernize-use-override, + modernize-use-transparent-functors, modernize-use-using, + performance-faster-string-find, performance-for-range-copy, + performance-implicit-conversion-in-loop, performance-inefficient-algorithm, + performance-inefficient-string-concatenation, performance-trivially-destructible, + performance-inefficient-vector-operation, performance-move-const-arg, + performance-move-constructor-init, performance-noexcept-move-constructor, + performance-no-automatic-move, performance-unnecessary-copy-initialization, + performance-type-promotion-in-math-fn, performance-unnecessary-value-param + +WarningsAsErrors: > + cppcoreguidelines-no-malloc, modernize-deprecated-headers, + modernize-loop-convert, modernize-make-shared, modernize-pass-by-value, modernize-make-unique, + modernize-raw-string-literal, modernize-redundant-void-arg, modernize-replace-auto-ptr, + modernize-replace-random-shuffle, modernize-return-braced-init-list, modernize-shrink-to-fit, + modernize-unary-static-assert, modernize-use-bool-literals, modernize-use-default-member-init, + modernize-use-emplace, modernize-use-equals-default, modernize-use-equals-delete, + modernize-use-noexcept, modernize-use-nullptr, modernize-use-override, + modernize-use-transparent-functors, modernize-use-using, + performance-faster-string-find, performance-for-range-copy, + performance-implicit-conversion-in-loop, performance-inefficient-algorithm, + performance-inefficient-string-concatenation, performance-trivially-destructible, + performance-inefficient-vector-operation, performance-move-const-arg, + performance-move-constructor-init, performance-noexcept-move-constructor, + performance-no-automatic-move, performance-unnecessary-copy-initialization, + performance-type-promotion-in-math-fn, performance-unnecessary-value-param + +HeaderFilterRegex: '^(src\/.*|include\/.*)$' diff --git a/.gitignore b/.gitignore index 259148f..c7419b8 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,13 @@ *.exe *.out *.app + +# build +*build*/ + +# vscode +*.vscode*/ + +# cache +*.cache*/ +*__pycache__*/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..9f4d38e --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,32 @@ +cmake_minimum_required(VERSION 3.14) + +project(mca) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_C_STANDARD_REQUIRED on) +set(CMAKE_EXPORT_COMPILE_COMMANDS on) +set(CMAKE_CXX_EXTENSIONS off) + +if (WIN32) + set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) +endif() + +option(MCA_BUILD_SHARE_LIB "Build shared libraries rather than static libraries" on) +option(MCA_BUILD_TEST "Whether or not to build unit test" on) + +aux_source_directory(src MCA_SOURCE) +set(LIBRARY_OUTPUT_PATH lib) +if (MCA_BUILD_SHARE_LIB) + add_library(mca SHARED ${MCA_SOURCE}) +else() + add_library(mca STATIC ${MCA_SOURCE}) +endif() + +find_program(CLANG_TIDY_EXE NAMES clang-tidy) +if (NOT CLANG_TIDY_EXE STREQUAL "CLANG_TIDY_EXE-NOTFOUND") + set_target_properties(mca PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_EXE}") +endif() + +if (MCA_BUILD_TEST) + add_subdirectory(test) +endif() diff --git a/include/mca.h b/include/mca.h new file mode 100644 index 0000000..e69de29 diff --git a/src/mca.cpp b/src/mca.cpp new file mode 100644 index 0000000..e69de29 diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..383ec9a --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,35 @@ +cmake_minimum_required(VERSION 3.14) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_C_STANDARD_REQUIRED on) +set(CMAKE_EXPORT_COMPILE_COMMANDS on) +set(CMAKE_CXX_EXTENSIONS off) + +if (WIN32) + set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) +endif() + + +include(FetchContent) +FetchContent_Declare( + googletest + URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip) + +set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) +FetchContent_MakeAvailable(googletest) +# enable testing in cmake +enable_testing() +include(GoogleTest) + +aux_source_directory(src UNIT_TEST_SOURCE) +add_executable(${PROJECT_NAME}_unit_test ${UNIT_TEST_SOURCE}) +target_link_libraries( + ${PROJECT_NAME}_unit_test + GTest::gtest_main + mca) +gtest_discover_tests(${PROJECT_NAME}_unit_test) + +find_program(CLANG_TIDY_EXE NAMES clang-tidy) +if (NOT CLANG_TIDY_EXE STREQUAL "CLANG_TIDY_EXE-NOTFOUND") + set_target_properties(${PROJECT_NAME}_unit_test PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_EXE}") +endif() diff --git a/test/src/mca_test.cpp b/test/src/mca_test.cpp new file mode 100644 index 0000000..2180533 --- /dev/null +++ b/test/src/mca_test.cpp @@ -0,0 +1 @@ +#include