Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize a cmake project with google test #1

Merged
merged 1 commit into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -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
36 changes: 36 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -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\/.*)$'
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,13 @@
*.exe
*.out
*.app

# build
*build*/

# vscode
*.vscode*/

# cache
*.cache*/
*__pycache__*/
32 changes: 32 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
Empty file added include/mca.h
Empty file.
Empty file added src/mca.cpp
Empty file.
35 changes: 35 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
1 change: 1 addition & 0 deletions test/src/mca_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <gtest/gtest.h>