Skip to content

Commit a26b9f2

Browse files
committed
first commit
0 parents  commit a26b9f2

File tree

7 files changed

+188
-0
lines changed

7 files changed

+188
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build/

.vscode/settings.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"C_Cpp.intelliSenseEngineFallback": "Enabled",
3+
"cmake.configureArgs": [],
4+
"cmake.configureEnvironment": {},
5+
"cmake.buildArgs": [],
6+
"cmake.buildEnvironment": {},
7+
"cmake.debugConfig": {
8+
"args": []
9+
}
10+
}

CMakeLists.txt

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
cmake_minimum_required(VERSION 3.10)
2+
3+
set(PROJECT_NAME cpp_template)
4+
set(CMAKE_CXX_STANDARD 17)
5+
6+
project(${PROJECT_NAME})
7+
include(Dependency.cmake)
8+
9+
add_executable(${PROJECT_NAME}
10+
src/main.cpp
11+
)
12+
13+
target_include_directories(${PROJECT_NAME} PUBLIC
14+
${DEPENDENCY_INCLUDE_DIR}
15+
)
16+
17+
target_link_libraries(${PROJECT_NAME} PUBLIC
18+
${DEPENDENCY_LIBS}
19+
)
20+
21+
add_dependencies(${PROJECT_NAME}
22+
${DEPENDENCY_LIST}
23+
)
24+
25+
if (MSVC)
26+
target_compile_options(${PROJECT_NAME} PUBLIC /wd4566 /wd4819 /wd4251 /wd4244 /wd4267)
27+
endif(MSVC)

Dependency.cmake

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
include(ExternalProject)
2+
3+
if (MSVC)
4+
set(LINK_DIR_OPTION -LIBPATH:)
5+
elseif()
6+
set(LINK_DIR_OPTION -L)
7+
endif()
8+
9+
set(DEPENDENCY_INSTALL_DIR ${PROJECT_BINARY_DIR}/install)
10+
set(DEPENDENCY_INCLUDE_DIR ${DEPENDENCY_INSTALL_DIR}/include)
11+
set(DEPENDENCY_LIBS ${LINK_DIR_OPTION}${DEPENDENCY_INSTALL_DIR}/lib)
12+
13+
# spdlog: fast logger library
14+
ExternalProject_Add(
15+
dep-spdlog
16+
GIT_REPOSITORY "https://github.com/gabime/spdlog.git"
17+
GIT_TAG "v1.x"
18+
GIT_SHALLOW 1
19+
UPDATE_COMMAND ""
20+
PATCH_COMMAND ""
21+
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${DEPENDENCY_INSTALL_DIR}
22+
TEST_COMMAND ""
23+
)
24+
set(DEPENDENCY_LIST ${DEPENDENCY_LIST} dep-spdlog)
25+
set(DEPENDENCY_LIBS ${DEPENDENCY_LIBS} spdlog$<$<CONFIG:Debug>:d>)
26+
27+
# clipp: header-only good c++ argument parser
28+
ExternalProject_Add(
29+
dep-clipp
30+
GIT_REPOSITORY "https://github.com/muellan/clipp.git"
31+
GIT_TAG "v1.2.2"
32+
GIT_SHALLOW 1
33+
UPDATE_COMMAND ""
34+
PATCH_COMMAND ""
35+
CONFIGURE_COMMAND ""
36+
BUILD_COMMAND ""
37+
INSTALL_COMMAND
38+
${CMAKE_COMMAND} -E make_directory ${DEPENDENCY_INSTALL_DIR}/include &&
39+
${CMAKE_COMMAND} -E copy
40+
${CMAKE_CURRENT_BINARY_DIR}/dep-clipp-prefix/src/dep-clipp/include/clipp.h
41+
${DEPENDENCY_INSTALL_DIR}/include
42+
TEST_COMMAND ""
43+
)
44+
set(DEPENDENCY_LIST ${DEPENDENCY_LIST} dep-clipp)
45+
46+
# json: header-only json parser using modern c++
47+
ExternalProject_Add(
48+
dep-json
49+
GIT_REPOSITORY "https://github.com/nlohmann/json.git"
50+
GIT_TAG "v3.9.0"
51+
GIT_SHALLOW 1
52+
UPDATE_COMMAND ""
53+
PATCH_COMMAND ""
54+
CMAKE_ARGS
55+
-DCMAKE_INSTALL_PREFIX=${DEPENDENCY_INSTALL_DIR}
56+
-DJSON_BuildTests=OFF
57+
TEST_COMMAND ""
58+
)
59+
set(DEPENDENCY_LIST ${DEPENDENCY_LIST} dep-json)
60+
61+
# magic_enum: header-only enum class utility
62+
ExternalProject_Add(
63+
dep_magic_enum
64+
GIT_REPOSITORY "https://github.com/Neargye/magic_enum.git"
65+
GIT_TAG "v0.6.6"
66+
GIT_SHALLOW 1
67+
UPDATE_COMMAND ""
68+
PATCH_COMMAND ""
69+
CMAKE_ARGS
70+
-DCMAKE_INSTALL_PREFIX=${DEPENDENCY_INSTALL_DIR}
71+
-DMAGIC_ENUM_OPT_BUILD_EXAMPLES=OFF
72+
-DMAGIC_ENUM_OPT_BUILD_TESTS=OFF
73+
TEST_COMMAND ""
74+
)
75+
set(DEPENDENCY_LIST ${DEPENDENCY_LIST} dep_magic_enum)
76+
77+
# filesystem: c++14-based filesystem that implements c++17 filesystem
78+
ExternalProject_Add(
79+
dep_filesystem
80+
GIT_REPOSITORY "https://github.com/gulrak/filesystem.git"
81+
GIT_TAG "v1.3.2"
82+
GIT_SHALLOW 1
83+
UPDATE_COMMAND ""
84+
PATCH_COMMAND ""
85+
CMAKE_ARGS
86+
-DCMAKE_INSTALL_PREFIX=${DEPENDENCY_INSTALL_DIR}
87+
-DGHC_FILESYSTEM_BUILD_TESTING=OFF
88+
-DGHC_FILESYSTEM_BUILD_EXAMPLES=OFF
89+
TEST_COMMAND ""
90+
)
91+
set(DEPENDENCY_LIST ${DEPENDENCY_LIST} dep_filesystem)

LICENSE.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2020 Jiyong Kwon ([email protected])
4+
5+
Permission is hereby granted, free of charge, to any person obtaining
6+
a copy of this software and associated documentation files (the "Software"),
7+
to deal in the Software without restriction, including without limitation
8+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
9+
and/or sell copies of the Software, and to permit persons to whom
10+
the Software is furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included
13+
in all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21+
DEALINGS IN THE SOFTWARE.

README.md

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# cpp_template
2+
3+
cmake-based c++ project template
4+
5+
### Feature
6+
7+
- Easy integration with 3rd-party projects using `ExternalProject_Add()`
8+
(See `Dependency.cmake`)
9+
- Can be used in Windows/MSVC, macOS/clang, and linux/gcc
10+
- Provide collections of good 3rd-party libraries
11+
- [spdlog](https://github.com/gabime/spdlog.git): logging
12+
- [clipp](https://github.com/muellan/clipp.git): argument parsing
13+
- [json](https://github.com/nlohmann/json.git): json parsing
14+
- [magic_enum](https://github.com/Neargye/magic_enum.git): enum utility
15+
- [filesystem](https://github.com/gulrak/filesystem.git): c++17 filesystem implementation
16+
- Optimal setting for VSCode (includes `.vscode/settings.json`)
17+
18+
### How to use
19+
20+
- Clone this project
21+
- Copy whole files in the projects
22+
- Open your project on VSCode
23+
- Edit project name in `CMakeLists.txt`
24+
- Enjoy!

src/main.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#if WIN32
2+
#define NOMINMAX
3+
#endif
4+
5+
#include <spdlog/spdlog.h>
6+
#include <nlohmann/json.hpp>
7+
#include <ghc/filesystem.hpp>
8+
#include <magic_enum.hpp>
9+
#include <clipp.h>
10+
11+
int main(int argc, const char** argv) {
12+
SPDLOG_INFO("Hello, world!");
13+
return 0;
14+
}

0 commit comments

Comments
 (0)