mirror of
https://github.com/TheLartians/ModernCppStarter.git
synced 2025-08-30 21:51:12 +02:00
make it useable for me
extent cmake-format config file use package-lock too
This commit is contained in:
parent
d4c654f026
commit
47fa7c6933
14 changed files with 225 additions and 29 deletions
|
@ -5,6 +5,10 @@ format:
|
|||
|
||||
parse:
|
||||
additional_commands:
|
||||
cpmdeclarepackage:
|
||||
spelling: CPMDeclarePackage
|
||||
cpmusepackagelock:
|
||||
spelling: CPMUsePackageLock
|
||||
cpmaddpackage:
|
||||
pargs:
|
||||
nargs: '*'
|
||||
|
|
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -1,4 +1,6 @@
|
|||
root/
|
||||
build/
|
||||
/build*
|
||||
/.vscode
|
||||
/cpm_modules
|
||||
.DS_Store
|
||||
.DS_Store
|
||||
|
|
|
@ -30,7 +30,7 @@ endif()
|
|||
# see https://github.com/cpm-cmake/CPM.cmake for more info
|
||||
|
||||
include(cmake/CPM.cmake)
|
||||
cpmusepackagelock(package-lock.cmake)
|
||||
CPMUsePackageLock(package-lock.cmake)
|
||||
|
||||
# PackageProject.cmake will be used to make our target installable
|
||||
CPMAddPackage(
|
||||
|
@ -53,8 +53,8 @@ CPMAddPackage(
|
|||
|
||||
# Note: globbing sources is considered bad practice as CMake's generators may not detect new files
|
||||
# automatically. Keep that in mind when changing files, or explicitly mention them here.
|
||||
file(GLOB_RECURSE headers CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/include/*.h")
|
||||
file(GLOB_RECURSE sources CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp")
|
||||
file(GLOB_RECURSE headers CONFIGURE_DEPENDS include/*.h)
|
||||
file(GLOB_RECURSE sources CONFIGURE_DEPENDS source/*.cpp)
|
||||
|
||||
# ---- Create library ----
|
||||
|
||||
|
@ -67,8 +67,9 @@ set_target_properties(Greeter PROPERTIES CXX_STANDARD ${CMAKE_CXX_STANDARD})
|
|||
# OR target_compile_features(Greeter PUBLIC cxx_std_17)
|
||||
|
||||
# being a cross-platform target, we enforce standards conformance on MSVC
|
||||
target_compile_options(Greeter PUBLIC "$<$<COMPILE_LANG_AND_ID:CXX,MSVC>:/permissive>")
|
||||
if(MSVC)
|
||||
target_compile_options(Greeter PUBLIC /permissive)
|
||||
# target_compile_options(Greeter PUBLIC /permissive)
|
||||
endif()
|
||||
|
||||
# Link dependencies EITHER:
|
||||
|
|
27
GNUmakefile
27
GNUmakefile
|
@ -7,25 +7,23 @@ GENERATOR=Ninja
|
|||
export CPM_SOURCE_CACHE=${HOME}/.cache/CPM
|
||||
export CPM_USE_LOCAL_PACKAGES=1
|
||||
|
||||
.PHONY: update format all test check clean distclean lock
|
||||
.PHONY: update format all test standalone check clean distclean lock
|
||||
|
||||
# the default target does just all
|
||||
check: all
|
||||
all:
|
||||
|
||||
all: test
|
||||
|
||||
test: install
|
||||
|
||||
|
||||
distclean:
|
||||
distclean: clean
|
||||
rm -rf build root
|
||||
|
||||
# update CPM.cmake
|
||||
update:
|
||||
wget -q -O cmake/CPM.cmake https://github.com/cpm-cmake/CPM.cmake/releases/latest/download/get_cpm.cmake
|
||||
|
||||
lock: install
|
||||
lock: standalone all
|
||||
cmake --build build/all --target cpm-update-package-lock
|
||||
cmake --build build/test --target cpm-update-package-lock
|
||||
cmake --build build/install --target cpm-update-package-lock
|
||||
cmake --build build/standalone --target cpm-update-package-lock
|
||||
|
||||
# install the library
|
||||
install:
|
||||
|
@ -33,13 +31,13 @@ install:
|
|||
cmake --build build/install --target install
|
||||
|
||||
# test the library
|
||||
test:
|
||||
test: install
|
||||
cmake -S test -B build/test -G "${GENERATOR}" -DCMAKE_PREFIX_PATH=${CURDIR}/root -DTEST_INSTALLED_VERSION=1
|
||||
cmake --build build/test
|
||||
cmake --build build/test --target test
|
||||
|
||||
# all together
|
||||
all:
|
||||
all: test
|
||||
cmake -S all -B build/all -G "${GENERATOR}" -DCMAKE_PREFIX_PATH=${CURDIR}/root -DTEST_INSTALLED_VERSION=1 -DENABLE_TEST_COVERAGE=1
|
||||
cmake --build build/all
|
||||
cmake --build build/all --target test
|
||||
|
@ -48,11 +46,14 @@ all:
|
|||
|
||||
format: distclean
|
||||
find . -name CMakeLists.txt | xargs cmake-format -i
|
||||
find . -name '*.cmake' | xargs cmake-format -i
|
||||
find . -name '*.cpp' | xargs clang-format -i
|
||||
find . -name '*.h' | xargs clang-format -i
|
||||
|
||||
# check the library
|
||||
check:
|
||||
standalone:
|
||||
cmake -S standalone -B build/standalone -G "${GENERATOR}" -DCMAKE_PREFIX_PATH=${CURDIR}/root -DCMAKE_EXPORT_COMPILE_COMMANDS=1
|
||||
cmake --build build/standalone --target all
|
||||
|
||||
# check the library
|
||||
check: standalone
|
||||
run-clang-tidy.py -p build/standalone -checks='-*,modernize-*,misc-*,hicpp-*,cert-*,readability-*,portability-*,performance-*,google-*' standalone
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# this script adds all subprojects to a single build to allow IDEs understand the full project
|
||||
# structure.
|
||||
|
||||
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
|
||||
cmake_minimum_required(VERSION 3.14...3.19)
|
||||
|
||||
project(BuildAll LANGUAGES CXX)
|
||||
|
||||
|
@ -10,6 +10,6 @@ include(../cmake/tools.cmake)
|
|||
# needed to generate test target
|
||||
enable_testing()
|
||||
|
||||
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../standalone ${CMAKE_BINARY_DIR}/standalone)
|
||||
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../test ${CMAKE_BINARY_DIR}/test)
|
||||
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../documentation ${CMAKE_BINARY_DIR}/documentation)
|
||||
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../standalone standalone)
|
||||
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../test test)
|
||||
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../documentation documentation)
|
||||
|
|
71
all/package-lock.cmake
Normal file
71
all/package-lock.cmake
Normal file
|
@ -0,0 +1,71 @@
|
|||
# CPM Package Lock This file should be committed to version control
|
||||
|
||||
# Ccache.cmake
|
||||
CPMDeclarePackage(
|
||||
Ccache.cmake
|
||||
NAME
|
||||
Ccache.cmake
|
||||
VERSION
|
||||
1.2.1
|
||||
GITHUB_REPOSITORY
|
||||
TheLartians/Ccache.cmake
|
||||
)
|
||||
# cxxopts
|
||||
CPMDeclarePackage(
|
||||
cxxopts
|
||||
NAME
|
||||
cxxopts
|
||||
VERSION
|
||||
2.2.0
|
||||
GITHUB_REPOSITORY
|
||||
jarro2783/cxxopts
|
||||
OPTIONS
|
||||
"CXXOPTS_BUILD_EXAMPLES Off"
|
||||
"CXXOPTS_BUILD_TESTS Off"
|
||||
)
|
||||
# Greeter (unversioned) CPMDeclarePackage(Greeter local directory ) PackageProject.cmake
|
||||
CPMDeclarePackage(
|
||||
PackageProject.cmake
|
||||
NAME
|
||||
PackageProject.cmake
|
||||
VERSION
|
||||
1.4.1
|
||||
GITHUB_REPOSITORY
|
||||
TheLartians/PackageProject.cmake
|
||||
)
|
||||
# fmt
|
||||
CPMDeclarePackage(
|
||||
fmt
|
||||
NAME
|
||||
fmt
|
||||
GIT_TAG
|
||||
7.1.3
|
||||
GITHUB_REPOSITORY
|
||||
fmtlib/fmt
|
||||
OPTIONS
|
||||
"FMT_INSTALL YES"
|
||||
)
|
||||
# doctest
|
||||
CPMDeclarePackage(
|
||||
doctest
|
||||
NAME
|
||||
doctest
|
||||
GIT_TAG
|
||||
2.4.5
|
||||
GITHUB_REPOSITORY
|
||||
onqtam/doctest
|
||||
)
|
||||
# Format.cmake
|
||||
CPMDeclarePackage(
|
||||
Format.cmake
|
||||
NAME
|
||||
Format.cmake
|
||||
VERSION
|
||||
1.6
|
||||
GITHUB_REPOSITORY
|
||||
TheLartians/Format.cmake
|
||||
OPTIONS
|
||||
"FORMAT_CHECK_CMAKE ON"
|
||||
)
|
||||
# MCSS (unversioned) CPMDeclarePackage(MCSS NAME MCSS GIT_TAG
|
||||
# 42d4a9a48f31f5df6e246c948403b54b50574a2a DOWNLOAD_ONLY YES GITHUB_REPOSITORY mosra/m.css )
|
|
@ -7,6 +7,13 @@ if(NOT PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
|
|||
endif()
|
||||
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/CPM.cmake)
|
||||
CPMUsePackageLock(package-lock.cmake)
|
||||
|
||||
# option: default not set
|
||||
set(USE_STATIC_ANALYZER
|
||||
""
|
||||
CACHE STRING "clang-tidy;cppcheck;iwyu"
|
||||
)
|
||||
|
||||
# enables sanitizers support using the the `USE_SANITIZER` flag available values are: Address,
|
||||
# Memory, MemoryWithOrigins, Undefined, Thread, Leak, 'Address;Undefined'
|
||||
|
@ -65,6 +72,7 @@ if(USE_SANITIZER OR USE_STATIC_ANALYZER)
|
|||
endif()
|
||||
|
||||
# enables CCACHE support through the USE_CCACHE flag possible values are: YES, NO or equivalent
|
||||
option(USE_CCACHE "use ccache" YES)
|
||||
if(USE_CCACHE)
|
||||
CPMAddPackage(
|
||||
NAME Ccache.cmake
|
||||
|
|
|
@ -5,6 +5,7 @@ project(GreeterDocs)
|
|||
# ---- Dependencies ----
|
||||
|
||||
include(../cmake/CPM.cmake)
|
||||
CPMUsePackageLock(package-lock.cmake)
|
||||
|
||||
CPMAddPackage(NAME Greeter SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/..)
|
||||
|
||||
|
@ -21,16 +22,16 @@ CPMAddPackage(
|
|||
set(DOXYGEN_PROJECT_NAME Greeter)
|
||||
set(DOXYGEN_PROJECT_VERSION ${Greeter_VERSION})
|
||||
set(DOXYGEN_PROJECT_ROOT "${CMAKE_CURRENT_LIST_DIR}/..")
|
||||
set(DOXYGEN_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/doxygen")
|
||||
set(DOXYGEN_OUTPUT_DIRECTORY doxygen)
|
||||
|
||||
configure_file(${CMAKE_CURRENT_LIST_DIR}/Doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
|
||||
configure_file(${CMAKE_CURRENT_LIST_DIR}/Doxyfile Doxyfile)
|
||||
|
||||
configure_file(${CMAKE_CURRENT_LIST_DIR}/conf.py ${CMAKE_CURRENT_BINARY_DIR}/conf.py)
|
||||
configure_file(${CMAKE_CURRENT_LIST_DIR}/conf.py conf.py)
|
||||
|
||||
add_custom_target(
|
||||
GenerateDocs
|
||||
${CMAKE_COMMAND} -E make_directory "${DOXYGEN_OUTPUT_DIRECTORY}"
|
||||
COMMAND "${MCSS_SOURCE_DIR}/documentation/doxygen.py" "${CMAKE_CURRENT_BINARY_DIR}/conf.py"
|
||||
COMMAND "${MCSS_SOURCE_DIR}/documentation/doxygen.py" conf.py
|
||||
COMMAND echo "Docs written to: ${DOXYGEN_OUTPUT_DIRECTORY}"
|
||||
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
|
||||
)
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace greeter {
|
|||
* @param lang the language to greet in
|
||||
* @return a string containing the greeting
|
||||
*/
|
||||
[[nodiscard]] std::string greet(LanguageCode lang = LanguageCode::EN) const;
|
||||
[[nodiscard]] auto greet(LanguageCode lang = LanguageCode::EN) const -> std::string;
|
||||
};
|
||||
|
||||
} // namespace greeter
|
||||
|
|
24
package-lock.cmake
Normal file
24
package-lock.cmake
Normal file
|
@ -0,0 +1,24 @@
|
|||
# CPM Package Lock This file should be committed to version control
|
||||
|
||||
# PackageProject.cmake
|
||||
CPMDeclarePackage(
|
||||
PackageProject.cmake
|
||||
NAME
|
||||
PackageProject.cmake
|
||||
VERSION
|
||||
1.4.1
|
||||
GITHUB_REPOSITORY
|
||||
TheLartians/PackageProject.cmake
|
||||
)
|
||||
# fmt
|
||||
CPMDeclarePackage(
|
||||
fmt
|
||||
NAME
|
||||
fmt
|
||||
GIT_TAG
|
||||
7.1.3
|
||||
GITHUB_REPOSITORY
|
||||
fmtlib/fmt
|
||||
OPTIONS
|
||||
"FMT_INSTALL YES"
|
||||
)
|
|
@ -9,6 +9,7 @@ include(../cmake/tools.cmake)
|
|||
# ---- Dependencies ----
|
||||
|
||||
include(../cmake/CPM.cmake)
|
||||
CPMUsePackageLock(package-lock.cmake)
|
||||
|
||||
CPMAddPackage(
|
||||
NAME cxxopts
|
||||
|
@ -21,10 +22,11 @@ CPMAddPackage(NAME Greeter SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/..)
|
|||
|
||||
# ---- Create standalone executable ----
|
||||
|
||||
file(GLOB sources CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp)
|
||||
file(GLOB sources CONFIGURE_DEPENDS source/*.cpp)
|
||||
|
||||
add_executable(GreeterStandalone ${sources})
|
||||
|
||||
# TODO: why rename in this way?
|
||||
set_target_properties(GreeterStandalone PROPERTIES CXX_STANDARD 17 OUTPUT_NAME "Greeter")
|
||||
|
||||
# WORKAROUND for ALIAS target is missing error! CK
|
||||
|
|
47
standalone/package-lock.cmake
Normal file
47
standalone/package-lock.cmake
Normal file
|
@ -0,0 +1,47 @@
|
|||
# CPM Package Lock This file should be committed to version control
|
||||
|
||||
# Ccache.cmake
|
||||
CPMDeclarePackage(
|
||||
Ccache.cmake
|
||||
NAME
|
||||
Ccache.cmake
|
||||
VERSION
|
||||
1.2.1
|
||||
GITHUB_REPOSITORY
|
||||
TheLartians/Ccache.cmake
|
||||
)
|
||||
# cxxopts
|
||||
CPMDeclarePackage(
|
||||
cxxopts
|
||||
NAME
|
||||
cxxopts
|
||||
VERSION
|
||||
2.2.0
|
||||
GITHUB_REPOSITORY
|
||||
jarro2783/cxxopts
|
||||
OPTIONS
|
||||
"CXXOPTS_BUILD_EXAMPLES Off"
|
||||
"CXXOPTS_BUILD_TESTS Off"
|
||||
)
|
||||
# Greeter (unversioned) CPMDeclarePackage(Greeter local directory ) PackageProject.cmake
|
||||
CPMDeclarePackage(
|
||||
PackageProject.cmake
|
||||
NAME
|
||||
PackageProject.cmake
|
||||
VERSION
|
||||
1.4.1
|
||||
GITHUB_REPOSITORY
|
||||
TheLartians/PackageProject.cmake
|
||||
)
|
||||
# fmt
|
||||
CPMDeclarePackage(
|
||||
fmt
|
||||
NAME
|
||||
fmt
|
||||
GIT_TAG
|
||||
7.1.3
|
||||
GITHUB_REPOSITORY
|
||||
fmtlib/fmt
|
||||
OPTIONS
|
||||
"FMT_INSTALL YES"
|
||||
)
|
|
@ -14,6 +14,7 @@ include(../cmake/tools.cmake)
|
|||
# ---- Dependencies ----
|
||||
|
||||
include(../cmake/CPM.cmake)
|
||||
CPMUsePackageLock(package-lock.cmake)
|
||||
|
||||
CPMAddPackage(
|
||||
NAME doctest
|
||||
|
@ -37,7 +38,7 @@ CPMAddPackage(
|
|||
|
||||
# ---- Create binary ----
|
||||
|
||||
file(GLOB sources CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp)
|
||||
file(GLOB sources CONFIGURE_DEPENDS source/*.cpp)
|
||||
add_executable(GreeterTests ${sources})
|
||||
target_link_libraries(GreeterTests doctest::doctest Greeter::Greeter)
|
||||
|
||||
|
|
34
test/package-lock.cmake
Normal file
34
test/package-lock.cmake
Normal file
|
@ -0,0 +1,34 @@
|
|||
# CPM Package Lock This file should be committed to version control
|
||||
|
||||
# Ccache.cmake
|
||||
CPMDeclarePackage(
|
||||
Ccache.cmake
|
||||
NAME
|
||||
Ccache.cmake
|
||||
VERSION
|
||||
1.2.1
|
||||
GITHUB_REPOSITORY
|
||||
TheLartians/Ccache.cmake
|
||||
)
|
||||
# doctest
|
||||
CPMDeclarePackage(
|
||||
doctest
|
||||
NAME
|
||||
doctest
|
||||
GIT_TAG
|
||||
2.4.5
|
||||
GITHUB_REPOSITORY
|
||||
onqtam/doctest
|
||||
)
|
||||
# Format.cmake
|
||||
CPMDeclarePackage(
|
||||
Format.cmake
|
||||
NAME
|
||||
Format.cmake
|
||||
VERSION
|
||||
1.6
|
||||
GITHUB_REPOSITORY
|
||||
TheLartians/Format.cmake
|
||||
OPTIONS
|
||||
"FORMAT_CHECK_CMAKE ON"
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue