diff --git a/.cmake-format b/.cmake-format index 8c355cf..f80a668 100644 --- a/.cmake-format +++ b/.cmake-format @@ -5,6 +5,10 @@ format: parse: additional_commands: + cpmdeclarepackage: + spelling: CPMDeclarePackage + cpmusepackagelock: + spelling: CPMUsePackageLock cpmaddpackage: pargs: nargs: '*' diff --git a/.gitignore b/.gitignore index d54a4f4..ce97fea 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ +root/ +build/ /build* /.vscode /cpm_modules -.DS_Store \ No newline at end of file +.DS_Store diff --git a/CMakeLists.txt b/CMakeLists.txt index cde9bf8..70cc295 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 "$<$:/permissive>") if(MSVC) - target_compile_options(Greeter PUBLIC /permissive) + # target_compile_options(Greeter PUBLIC /permissive) endif() # Link dependencies EITHER: diff --git a/GNUmakefile b/GNUmakefile index a177583..efac9c6 100755 --- a/GNUmakefile +++ b/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 diff --git a/all/CMakeLists.txt b/all/CMakeLists.txt index db5f5fb..0737fd5 100644 --- a/all/CMakeLists.txt +++ b/all/CMakeLists.txt @@ -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) diff --git a/all/package-lock.cmake b/all/package-lock.cmake new file mode 100644 index 0000000..4c633e6 --- /dev/null +++ b/all/package-lock.cmake @@ -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 ) diff --git a/cmake/tools.cmake b/cmake/tools.cmake index 4029e37..b2f9134 100644 --- a/cmake/tools.cmake +++ b/cmake/tools.cmake @@ -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 diff --git a/documentation/CMakeLists.txt b/documentation/CMakeLists.txt index b3717dc..18c999e 100644 --- a/documentation/CMakeLists.txt +++ b/documentation/CMakeLists.txt @@ -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}" ) diff --git a/include/greeter/greeter.h b/include/greeter/greeter.h index 19569eb..8c41203 100644 --- a/include/greeter/greeter.h +++ b/include/greeter/greeter.h @@ -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 diff --git a/package-lock.cmake b/package-lock.cmake new file mode 100644 index 0000000..65e1818 --- /dev/null +++ b/package-lock.cmake @@ -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" +) diff --git a/standalone/CMakeLists.txt b/standalone/CMakeLists.txt index bcf0be6..187fe6a 100644 --- a/standalone/CMakeLists.txt +++ b/standalone/CMakeLists.txt @@ -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 diff --git a/standalone/package-lock.cmake b/standalone/package-lock.cmake new file mode 100644 index 0000000..b6824c5 --- /dev/null +++ b/standalone/package-lock.cmake @@ -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" +) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 5fa8612..4e42348 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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) diff --git a/test/package-lock.cmake b/test/package-lock.cmake new file mode 100644 index 0000000..193cfdc --- /dev/null +++ b/test/package-lock.cmake @@ -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" +)