Skip to content

Commit

Permalink
removed conan and updated template (#2)
Browse files Browse the repository at this point in the history
* removed conan and updated template

* removed conan installation from github actions

* run test script from CI

* updated CI
  • Loading branch information
Husenap authored Sep 23, 2020
1 parent b61cc0b commit d420c9f
Show file tree
Hide file tree
Showing 23 changed files with 111 additions and 61 deletions.
18 changes: 13 additions & 5 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
AccessModifierOffset: '-4'
AllowShortFunctionsOnASingleLine: Inline
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true
BasedOnStyle: Google
BinPackArguments: false
BinPackParameters: false
BreakConstructorInitializers: BeforeComma
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ColumnLimit: 120
AccessModifierOffset: '-4'
IndentWidth: '4'
IndentPPDirectives: AfterHash
IndentCaseLabels: false
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^<.*\..*>'
Priority: 2
- Regex: '^<.*>'
Priority: 1
- Regex: '".*"'
Priority: 3
Language: Cpp
TabWidth: '4'
UseTab: ForIndentation
IndentPPDirectives: AfterHash
AlignConsecutiveAssignments: true
IndentCaseLabels: false
IncludeBlocks: Preserve
8 changes: 8 additions & 0 deletions .cmake-format.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
bullet_char: '*'
enum_char: .
line_width: 120
max_pargs_hwrap: 3
separate_ctrl_name_with_space: false
separate_fn_name_with_space: false
tab_size: 4
columnize: true
10 changes: 4 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: Install Conan
run: pip install conan

- name: Generate
run: cmake . -B.build
run: cmake . -B.build -Ax64 -DPROJECT_NAME_BUILD_TESTS=ON

- name: Build
run: cmake --build .build/

- name: Test
run: |
cd .build/
ctest .
ctest .
cd ..
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.build/
.vscode/
.vscode/
.deps/
25 changes: 16 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
cmake_minimum_required(VERSION 3.16)
set(PROJECT_NAME "project_name")
project(${PROJECT_NAME} C CXX)

project("project_name" C CXX)

include("cmake/prevent_in_source_builds.cmake")
include("cmake/standard_project_setup.cmake")

include("cmake/compiler_features.cmake")
include("cmake/compiler_warnings.cmake")
include("cmake/conan.cmake")

set_property(GLOBAL PROPERTY CXX_STANDARD 20)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "predefined")
add_subdirectory("app")

include(GoogleTest)
enable_testing()
set(PROJECT_NAME_FOLDER
${PROJECT_NAME}
CACHE STRING "The folder that ${PROJECT_NAME} projects will be placed in.")

add_subdirectory("app")
option(PROJECT_NAME_BUILD_TESTS "If unit tests should be build." OFF)
if(PROJECT_NAME_BUILD_TESTS)
enable_testing()
include(GoogleTest)
include("thirdparty/googletest.cmake")
add_subdirectory("test")
endif()
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# cmake-project-template

Uses CMake for generating and Conan for package management.
Uses CMake for generating.

![Build](https://github.com/Husenap/cmake-project-template/workflows/Build/badge.svg)
15 changes: 3 additions & 12 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
set(target_name "app")

set(src_files
"src/main.cpp")
set(src_files "src/main.cpp")

# Project
add_executable(${target_name} ${src_files})

target_link_libraries(${target_name} compiler_features compiler_warnings)

source_group("src" FILES "src/main.cpp")

set_target_properties(${target_name} PROPERTIES FOLDER ${PROJECT_NAME})
set_target_properties(${target_name} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}/bin)

# Tests
add_executable(${target_name}_test "test/test.cpp")

target_link_libraries(${target_name}_test CONAN_PKG::gtest)

set_target_properties(${target_name}_test PROPERTIES FOLDER ${PROJECT_NAME})

gtest_discover_tests(${target_name}_test)
2 changes: 1 addition & 1 deletion app/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <iostream>

int main() {
std::cout << "Hello World!" << std::endl;
std::cout << "This will become something epic!" << std::endl;

return 0;
}
Empty file removed bin/.gitkeep
Empty file.
8 changes: 2 additions & 6 deletions cmake/compiler_features.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
if (MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++latest")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++2a")
endif()
add_library(compiler_features INTERFACE)

message("-- CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
target_compile_features(compiler_features INTERFACE cxx_std_20)
13 changes: 9 additions & 4 deletions cmake/compiler_warnings.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
add_library(compiler-warnings INTERFACE)
add_library(compiler_warnings INTERFACE)

# cmake-format: off

if (MSVC)
target_compile_options(compiler-warnings INTERFACE
target_compile_options(compiler_warnings INTERFACE
/WX # treat warnings as errors
/W4 # warning level 4
/permissive- # standards conformance https://docs.microsoft.com/en-us/cpp/build/reference/permissive-standards-conformance?view=vs-2017
/w14242 # 'identfier': conversion from 'type1' to 'type1', possible loss of data
Expand All @@ -28,7 +31,7 @@ if (MSVC)
/wd4201 # nonstandard extension used : nameless struct/union
)
else()
target_compile_options(compiler-warnings INTERFACE
target_compile_options(compiler_warnings INTERFACE
-Wall # reasonable and standard
-Wextra # reasonable and standard
-Wshadow # warn the user if a variable declaration shadows one from a parent context
Expand All @@ -48,4 +51,6 @@ else()
-Wuseless-cast # warn if you perform a cast to the same type
-Wdouble-promotion # warn if float is implicit promoted to double
-Wformat=2) # warn on security issues around functions that format output (ie printf)
endif()
endif()

# cmake-format: on
10 changes: 0 additions & 10 deletions cmake/conan.cmake

This file was deleted.

10 changes: 10 additions & 0 deletions cmake/prevent_in_source_builds.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
get_filename_component(srcdir "${CMAKE_SOURCE_DIR}" REALPATH)
get_filename_component(bindir "${CMAKE_BINARY_DIR}" REALPATH)

if("${srcdir}" STREQUAL "${bindir}")
message("=========================================================")
message("Warning: in-source builds are disabled!")
message("Please create a separate build folder using the -B flag")
message("=========================================================")
message(FATAL_ERROR "Quitting configuration!")
endif()
2 changes: 2 additions & 0 deletions cmake/standard_project_setup.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "predefined")
5 changes: 0 additions & 5 deletions conanfile.txt

This file was deleted.

1 change: 0 additions & 1 deletion gen.bat

This file was deleted.

1 change: 1 addition & 0 deletions scripts/build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cmake --build .build/
1 change: 1 addition & 0 deletions scripts/gen.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cmake . -B.build -Ax64 -DPROJECT_NAME_BUILD_TESTS=OFF
1 change: 1 addition & 0 deletions scripts/open.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cmake --open .build/
7 changes: 7 additions & 0 deletions scripts/test.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@echo off

cmake . -B.build -Ax64 -DPROJECT_NAME_BUILD_TESTS=ON
cmake --build .build/
cd .build/
ctest .
cd ..
15 changes: 15 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
set(target_name "app_test")

set(src_files "src/unit.cpp")

add_executable(${target_name} ${src_files})

target_link_libraries(
${target_name}
gtest
gmock
gmock_main)

set_target_properties(${target_name} PROPERTIES FOLDER ${PROJECT_NAME}/test)

gtest_discover_tests(${target_name})
File renamed without changes.
15 changes: 15 additions & 0 deletions thirdparty/googletest.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
message("-- External Project: googletest")
include(FetchContent)

FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG a4ab0ab # This includes a fix when using C++20
)

FetchContent_MakeAvailable(googletest)

set_target_properties("gtest" PROPERTIES FOLDER "thirdparty/googletest")
set_target_properties("gmock" PROPERTIES FOLDER "thirdparty/googletest")
set_target_properties("gtest_main" PROPERTIES FOLDER "thirdparty/googletest")
set_target_properties("gmock_main" PROPERTIES FOLDER "thirdparty/googletest")

0 comments on commit d420c9f

Please sign in to comment.