From 47fa7c6933bd38bc13c489284ebe5e49642c937c Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Fri, 12 Feb 2021 22:53:26 +0100 Subject: [PATCH 01/23] make it useable for me extent cmake-format config file use package-lock too --- .cmake-format | 4 ++ .gitignore | 4 +- CMakeLists.txt | 9 +++-- GNUmakefile | 27 ++++++------- all/CMakeLists.txt | 8 ++-- all/package-lock.cmake | 71 +++++++++++++++++++++++++++++++++++ cmake/tools.cmake | 8 ++++ documentation/CMakeLists.txt | 9 +++-- include/greeter/greeter.h | 2 +- package-lock.cmake | 24 ++++++++++++ standalone/CMakeLists.txt | 4 +- standalone/package-lock.cmake | 47 +++++++++++++++++++++++ test/CMakeLists.txt | 3 +- test/package-lock.cmake | 34 +++++++++++++++++ 14 files changed, 225 insertions(+), 29 deletions(-) create mode 100644 all/package-lock.cmake create mode 100644 package-lock.cmake create mode 100644 standalone/package-lock.cmake create mode 100644 test/package-lock.cmake 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" +) From 1aad14a6fac24d6ce8c48b835a0cab4e9d7a333f Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Fri, 12 Feb 2021 23:29:14 +0100 Subject: [PATCH 02/23] change github actions to develop branch set version to v1.0.1 --- .github/workflows/install.yml | 4 ++-- .github/workflows/macos.yml | 4 ++-- .github/workflows/standalone.yml | 4 ++-- .github/workflows/style.yml | 4 ++-- .github/workflows/ubuntu.yml | 4 ++-- .github/workflows/windows.yml | 4 ++-- CMakeLists.txt | 10 +++++----- test/CMakeLists.txt | 2 +- test/source/greeter.cpp | 4 ++-- 9 files changed, 20 insertions(+), 20 deletions(-) diff --git a/.github/workflows/install.yml b/.github/workflows/install.yml index 606dddd..8cb80aa 100644 --- a/.github/workflows/install.yml +++ b/.github/workflows/install.yml @@ -3,10 +3,10 @@ name: Install on: push: branches: - - master + - develop pull_request: branches: - - master + - develop env: CTEST_OUTPUT_ON_FAILURE: 1 diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index a2a098f..cba48ae 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -3,10 +3,10 @@ name: MacOS on: push: branches: - - master + - develop pull_request: branches: - - master + - develop env: CTEST_OUTPUT_ON_FAILURE: 1 diff --git a/.github/workflows/standalone.yml b/.github/workflows/standalone.yml index 5c3853e..bfb9c18 100644 --- a/.github/workflows/standalone.yml +++ b/.github/workflows/standalone.yml @@ -3,10 +3,10 @@ name: Standalone on: push: branches: - - master + - develop pull_request: branches: - - master + - develop env: CPM_SOURCE_CACHE: ${{ github.workspace }}/cpm_modules diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml index ba20a70..d3ed946 100644 --- a/.github/workflows/style.yml +++ b/.github/workflows/style.yml @@ -3,10 +3,10 @@ name: Style on: push: branches: - - master + - develop pull_request: branches: - - master + - develop env: CPM_SOURCE_CACHE: ${{ github.workspace }}/cpm_modules diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index a36711d..dfc2ec5 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -3,10 +3,10 @@ name: Ubuntu on: push: branches: - - master + - develop pull_request: branches: - - master + - develop env: CTEST_OUTPUT_ON_FAILURE: 1 diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index a52b0ae..23ebdfb 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -3,10 +3,10 @@ name: Windows on: push: branches: - - master + - develop pull_request: branches: - - master + - develop env: CTEST_OUTPUT_ON_FAILURE: 1 diff --git a/CMakeLists.txt b/CMakeLists.txt index 70cc295..bb7f411 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.14...3.19) # Note: update this to your new project's name and version project( Greeter - VERSION 1.0 + VERSION 1.0.1 LANGUAGES CXX ) @@ -64,12 +64,12 @@ add_library(Greeter SHARED ${headers} ${sources}) # EITHER: set_target_properties(Greeter PROPERTIES CXX_STANDARD ${CMAKE_CXX_STANDARD}) -# OR target_compile_features(Greeter PUBLIC cxx_std_17) +# 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>") +# being a cross-platform target, we enforce standards conformance on MSVC EITHER: +# target_compile_options(Greeter PUBLIC "$<$:/permissive>") OR: if(MSVC) - # target_compile_options(Greeter PUBLIC /permissive) + target_compile_options(Greeter PUBLIC /permissive) endif() # Link dependencies EITHER: diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 4e42348..ab9e791 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -42,7 +42,7 @@ file(GLOB sources CONFIGURE_DEPENDS source/*.cpp) add_executable(GreeterTests ${sources}) target_link_libraries(GreeterTests doctest::doctest Greeter::Greeter) -set_target_properties(GreeterTests PROPERTIES CXX_STANDARD 17) +set_target_properties(GreeterTests PROPERTIES CXX_STANDARD 20) # enable compiler warnings if(NOT TEST_INSTALLED_VERSION) diff --git a/test/source/greeter.cpp b/test/source/greeter.cpp index 10a1242..f39eb74 100644 --- a/test/source/greeter.cpp +++ b/test/source/greeter.cpp @@ -20,7 +20,7 @@ TEST_CASE("Greeter version") { static_assert(std::string_view(GREETER_VERSION).starts_with("1.0")); // TBD C++20 only CHECK(std::string(GREETER_VERSION).starts_with("1.0")); // SameMajorVersion #else - static_assert(std::string_view(GREETER_VERSION) == std::string_view("1.0")); - CHECK(std::string(GREETER_VERSION) == std::string("1.0")); + static_assert(std::string_view(GREETER_VERSION) == std::string_view("1.0.1")); + CHECK(std::string(GREETER_VERSION) == std::string("1.0.1")); #endif } From 7f36b7cb866f07d7c628c74356c3cfa592bd6871 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Sat, 13 Feb 2021 21:56:31 +0100 Subject: [PATCH 03/23] cleanup build files use strict -std=c++20 update cmake-format config file --- .cmake-format | 21 ++++++++--- .gitignore | 2 +- CMakeLists.txt | 6 ++-- GNUmakefile | 22 +++++++----- all/package-lock.cmake | 66 ++++------------------------------- cmake/tools.cmake | 6 ++++ package-lock.cmake | 21 ++--------- standalone/CMakeLists.txt | 8 +++-- standalone/package-lock.cmake | 44 ++--------------------- test/CMakeLists.txt | 5 +-- test/package-lock.cmake | 31 ++++------------ test/source/greeter.cpp | 2 +- 12 files changed, 70 insertions(+), 164 deletions(-) diff --git a/.cmake-format b/.cmake-format index f80a668..02aa5d3 100644 --- a/.cmake-format +++ b/.cmake-format @@ -5,10 +5,6 @@ format: parse: additional_commands: - cpmdeclarepackage: - spelling: CPMDeclarePackage - cpmusepackagelock: - spelling: CPMUsePackageLock cpmaddpackage: pargs: nargs: '*' @@ -44,10 +40,16 @@ parse: flags: [] spelling: CPMFindPackage kwargs: *cpmaddpackagekwargs - packageproject: + cpmdeclarepackage: pargs: nargs: '*' flags: [] + spelling: CPMDeclarePackage + kwargs: *cpmaddpackagekwargs + packageproject: + pargs: + nargs: '*' + flags: [NO_VERSION_SUFFIX] spelling: packageProject kwargs: NAME: 1 @@ -59,3 +61,12 @@ parse: COMPATIBILITY: 1 VERSION_HEADER: 1 DEPENDENCIES: + + cpmusepackagelock: + pargs: 1 + spelling: CPMUsePackageLock + cpmregisterpackage: + pargs: 1 + spelling: CPMRegisterPackage + cpmgetpackageversion: + pargs: 2 + spelling: CPMGetPackageVersion diff --git a/.gitignore b/.gitignore index ce97fea..b8bd7ae 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -root/ +stagedir/ build/ /build* /.vscode diff --git a/CMakeLists.txt b/CMakeLists.txt index bb7f411..b413604 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,8 @@ endif() # ---- Project settings ---- +option(BUILD_SHARED_LIBS "Create shared libraries if ON" OFF) + if(NOT DEFINED CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) @@ -60,11 +62,11 @@ file(GLOB_RECURSE sources CONFIGURE_DEPENDS source/*.cpp) # Note: for header-only libraries change all PUBLIC flags to INTERFACE and create an interface # target! EITHER: add_library(Greeter INTERFACE) OR: -add_library(Greeter SHARED ${headers} ${sources}) +add_library(Greeter ${headers} ${sources}) # EITHER: set_target_properties(Greeter PROPERTIES CXX_STANDARD ${CMAKE_CXX_STANDARD}) -# OR: target_compile_features(Greeter PUBLIC cxx_std_17) +# OR: target_compile_features(Greeter PUBLIC cxx_std_20) # being a cross-platform target, we enforce standards conformance on MSVC EITHER: # target_compile_options(Greeter PUBLIC "$<$:/permissive>") OR: diff --git a/GNUmakefile b/GNUmakefile index efac9c6..ee367dc 100755 --- a/GNUmakefile +++ b/GNUmakefile @@ -1,8 +1,11 @@ # # CURDIR=$(/bin/pwd) -# -# GENERATOR="Unix Makefiles" -GENERATOR=Ninja +# On UNIX one can use the DESTDIR mechanism in order to relocate the whole installation. +DESTDIR?=${CURDIR}/stagedir +export DESTDIR + +# GENERATOR?="Unix Makefiles" +GENERATOR?=Ninja export CPM_SOURCE_CACHE=${HOME}/.cache/CPM export CPM_USE_LOCAL_PACKAGES=1 @@ -12,8 +15,11 @@ export CPM_USE_LOCAL_PACKAGES=1 # the default target does just all all: +clean: + find . -type d -name build | xargs rm -rf + distclean: clean - rm -rf build root + rm -rf build ${DESTDIR} # update CPM.cmake update: @@ -27,18 +33,18 @@ lock: standalone all # install the library install: - cmake -S . -B build/install -G "${GENERATOR}" -DCMAKE_PREFIX_PATH=${CURDIR}/root -DCMAKE_INSTALL_PREFIX=${CURDIR}/root -DCMAKE_CXX_STANDARD=20 # --trace-expand + cmake -S . -B build/install -G "${GENERATOR}" -DCMAKE_PREFIX_PATH=${DESTDIR} # --trace-expand cmake --build build/install --target install # test the library test: install - cmake -S test -B build/test -G "${GENERATOR}" -DCMAKE_PREFIX_PATH=${CURDIR}/root -DTEST_INSTALLED_VERSION=1 + cmake -S test -B build/test -G "${GENERATOR}" -DCMAKE_PREFIX_PATH=${DESTDIR} -DTEST_INSTALLED_VERSION=1 cmake --build build/test cmake --build build/test --target test # all together all: test - cmake -S all -B build/all -G "${GENERATOR}" -DCMAKE_PREFIX_PATH=${CURDIR}/root -DTEST_INSTALLED_VERSION=1 -DENABLE_TEST_COVERAGE=1 + cmake -S all -B build/all -G "${GENERATOR}" -DCMAKE_PREFIX_PATH=${DESTDIR} -DTEST_INSTALLED_VERSION=1 -DENABLE_TEST_COVERAGE=1 cmake --build build/all cmake --build build/all --target test cmake --build build/all --target GenerateDocs @@ -51,7 +57,7 @@ format: distclean find . -name '*.h' | xargs clang-format -i standalone: - cmake -S standalone -B build/standalone -G "${GENERATOR}" -DCMAKE_PREFIX_PATH=${CURDIR}/root -DCMAKE_EXPORT_COMPILE_COMMANDS=1 + cmake -S standalone -B build/standalone -G "${GENERATOR}" -DCMAKE_PREFIX_PATH=${DESTDIR} -DCMAKE_EXPORT_COMPILE_COMMANDS=1 cmake --build build/standalone --target all # check the library diff --git a/all/package-lock.cmake b/all/package-lock.cmake index 4c633e6..5e0bc01 100644 --- a/all/package-lock.cmake +++ b/all/package-lock.cmake @@ -3,69 +3,17 @@ # 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 + NAME Ccache.cmake + VERSION 1.2.1 + GITHUB_REPOSITORY TheLartians/Ccache.cmake ) # Format.cmake CPMDeclarePackage( Format.cmake - NAME - Format.cmake - VERSION - 1.6 - GITHUB_REPOSITORY - TheLartians/Format.cmake - OPTIONS - "FORMAT_CHECK_CMAKE ON" + 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 b2f9134..3d87468 100644 --- a/cmake/tools.cmake +++ b/cmake/tools.cmake @@ -9,6 +9,12 @@ endif() include(${CMAKE_CURRENT_LIST_DIR}/CPM.cmake) CPMUsePackageLock(package-lock.cmake) +if(NOT DEFINED CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 20) + set(CMAKE_CXX_STANDARD_REQUIRED ON) + set(CMAKE_CXX_EXTENSIONS NO) +endif() + # option: default not set set(USE_STATIC_ANALYZER "" diff --git a/package-lock.cmake b/package-lock.cmake index 65e1818..6d59719 100644 --- a/package-lock.cmake +++ b/package-lock.cmake @@ -3,22 +3,7 @@ # 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" + NAME PackageProject.cmake + VERSION 1.4.1 + GITHUB_REPOSITORY TheLartians/PackageProject.cmake ) diff --git a/standalone/CMakeLists.txt b/standalone/CMakeLists.txt index 187fe6a..003cf8a 100644 --- a/standalone/CMakeLists.txt +++ b/standalone/CMakeLists.txt @@ -26,10 +26,12 @@ 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") +# TODO: why rename in this way? Seems only for CI with GitHub actions! CK +set_target_properties( + GreeterStandalone PROPERTIES CXX_STANDARD ${CMAKE_CXX_STANDARD} OUTPUT_NAME "Greeter" +) -# WORKAROUND for ALIAS target is missing error! CK +# WORKAROUND missing ALIAS target error! CK if(NOT TARGET cxxopts::cxxopts) add_library(cxxopts::cxxopts ALIAS cxxopts) endif() diff --git a/standalone/package-lock.cmake b/standalone/package-lock.cmake index b6824c5..bf1e9d9 100644 --- a/standalone/package-lock.cmake +++ b/standalone/package-lock.cmake @@ -3,45 +3,7 @@ # 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" + NAME Ccache.cmake + VERSION 1.2.1 + GITHUB_REPOSITORY TheLartians/Ccache.cmake ) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ab9e791..1b93cd2 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -41,8 +41,9 @@ CPMAddPackage( file(GLOB sources CONFIGURE_DEPENDS source/*.cpp) add_executable(GreeterTests ${sources}) target_link_libraries(GreeterTests doctest::doctest Greeter::Greeter) - -set_target_properties(GreeterTests PROPERTIES CXX_STANDARD 20) +# EITHER: +set_target_properties(GreeterTests PROPERTIES CXX_STANDARD ${CMAKE_CXX_STANDARD}) +# OR: target_compile_features(GreeterTests PUBLIC cxx_std_20) # enable compiler warnings if(NOT TEST_INSTALLED_VERSION) diff --git a/test/package-lock.cmake b/test/package-lock.cmake index 193cfdc..efa8ce4 100644 --- a/test/package-lock.cmake +++ b/test/package-lock.cmake @@ -3,32 +3,15 @@ # 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 + NAME Ccache.cmake + VERSION 1.2.1 + GITHUB_REPOSITORY TheLartians/Ccache.cmake ) # Format.cmake CPMDeclarePackage( Format.cmake - NAME - Format.cmake - VERSION - 1.6 - GITHUB_REPOSITORY - TheLartians/Format.cmake - OPTIONS - "FORMAT_CHECK_CMAKE ON" + NAME Format.cmake + VERSION 1.6 + GITHUB_REPOSITORY TheLartians/Format.cmake + OPTIONS "FORMAT_CHECK_CMAKE ON" ) diff --git a/test/source/greeter.cpp b/test/source/greeter.cpp index f39eb74..e3f23b7 100644 --- a/test/source/greeter.cpp +++ b/test/source/greeter.cpp @@ -16,7 +16,7 @@ TEST_CASE("Greeter") { } TEST_CASE("Greeter version") { -#if (__cpp_lib_starts_ends_with) +#if ((__cplusplus >= 201907L) || __cpp_lib_starts_ends_with) static_assert(std::string_view(GREETER_VERSION).starts_with("1.0")); // TBD C++20 only CHECK(std::string(GREETER_VERSION).starts_with("1.0")); // SameMajorVersion #else From 0bad72b51e34d2fe656968ba08b69dd049cd5ade Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Sun, 14 Feb 2021 23:44:26 +0100 Subject: [PATCH 04/23] support dynamic library too generate export header needed and install it --- CMakeLists.txt | 23 ++++++++++++++++++----- GNUmakefile | 29 +++++++++++++++-------------- include/greeter/greeter.h | 4 +++- test/source/greeter.cpp | 2 +- 4 files changed, 37 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b413604..b4da9d3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,7 +20,7 @@ endif() # ---- Project settings ---- -option(BUILD_SHARED_LIBS "Create shared libraries if ON" OFF) +option(BUILD_SHARED_LIBS "Create shared libraries if ON" YES) if(NOT DEFINED CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 20) @@ -28,6 +28,10 @@ if(NOT DEFINED CMAKE_CXX_STANDARD) set(CMAKE_CXX_EXTENSIONS NO) endif() +# Set default visibility to hidden for all targets +set(CMAKE_CXX_VISIBILITY_PRESET hidden) +set(CMAKE_VISIBILITY_INLINES_HIDDEN YES) + # ---- Add dependencies via CPM ---- # see https://github.com/cpm-cmake/CPM.cmake for more info @@ -78,9 +82,10 @@ endif() target_link_libraries(Greeter PRIVATE $) # OR: target_link_libraries(Greeter PUBLIC fmt::fmt) +set(INCLUDE_INSTALL_DIR include/${PROJECT_NAME}-${PROJECT_VERSION}) target_include_directories( - Greeter PUBLIC $ - $ + Greeter BEFORE PUBLIC $ + $ ) # ---- Create an installable target ---- @@ -89,6 +94,14 @@ target_include_directories( # the location where the project's version header will be placed should match the project's regular # header paths string(TOLOWER ${PROJECT_NAME}/version.h VERSION_HEADER_LOCATION) +string(TOLOWER ${PROJECT_NAME}/greeter_export.h EXPORT_HEADER_LOCATION) + +# TODO: should be done in packageProject() +include(GenerateExportHeader) +generate_export_header( + ${PROJECT_NAME} EXPORT_FILE_NAME PackageProjectInclude/${EXPORT_HEADER_LOCATION} +) +# Note: the export header will be installed while installing the version header! CK packageProject( NAME ${PROJECT_NAME} @@ -96,8 +109,8 @@ packageProject( NAMESPACE ${PROJECT_NAME} BINARY_DIR ${PROJECT_BINARY_DIR} INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include - INCLUDE_DESTINATION include/${PROJECT_NAME}-${PROJECT_VERSION} + INCLUDE_DESTINATION ${INCLUDE_INSTALL_DIR} VERSION_HEADER "${VERSION_HEADER_LOCATION}" COMPATIBILITY SameMajorVersion - # NOTE: not needed DEPENDENCIES "fmt 7.1.3" + # Note: not needed DEPENDENCIES "fmt 7.1.3" ) diff --git a/GNUmakefile b/GNUmakefile index ee367dc..77888a8 100755 --- a/GNUmakefile +++ b/GNUmakefile @@ -1,25 +1,24 @@ # # CURDIR=$(/bin/pwd) -# On UNIX one can use the DESTDIR mechanism in order to relocate the whole installation. -DESTDIR?=${CURDIR}/stagedir -export DESTDIR +ROOT?=${CURDIR}/stagedir -# GENERATOR?="Unix Makefiles" +#XXX GENERATOR?="Unix Makefiles" GENERATOR?=Ninja -export CPM_SOURCE_CACHE=${HOME}/.cache/CPM +#XXX export CXX=clang++ export CPM_USE_LOCAL_PACKAGES=1 +export CPM_SOURCE_CACHE=${HOME}/.cache/CPM -.PHONY: update format all test standalone check clean distclean lock +.PHONY: update format all test standalone doc check clean distclean lock -# the default target does just all +# the default target does just all, but neither standalone nor doc all: clean: find . -type d -name build | xargs rm -rf distclean: clean - rm -rf build ${DESTDIR} + rm -rf build ${ROOT} # update CPM.cmake update: @@ -31,25 +30,27 @@ lock: standalone all cmake --build build/install --target cpm-update-package-lock cmake --build build/standalone --target cpm-update-package-lock -# install the library +# install the library to stagedir install: - cmake -S . -B build/install -G "${GENERATOR}" -DCMAKE_PREFIX_PATH=${DESTDIR} # --trace-expand + cmake -S . -B build/install -G "${GENERATOR}" -DCMAKE_PREFIX_PATH=${ROOT} -DCMAKE_INSTALL_PREFIX=${ROOT} # --trace-expand cmake --build build/install --target install # test the library test: install - cmake -S test -B build/test -G "${GENERATOR}" -DCMAKE_PREFIX_PATH=${DESTDIR} -DTEST_INSTALLED_VERSION=1 + cmake -S test -B build/test -G "${GENERATOR}" -DCMAKE_PREFIX_PATH=${ROOT} -DTEST_INSTALLED_VERSION=1 cmake --build build/test cmake --build build/test --target test # all together all: test - cmake -S all -B build/all -G "${GENERATOR}" -DCMAKE_PREFIX_PATH=${DESTDIR} -DTEST_INSTALLED_VERSION=1 -DENABLE_TEST_COVERAGE=1 + cmake -S all -B build/all -G "${GENERATOR}" -DCMAKE_PREFIX_PATH=${ROOT} -DTEST_INSTALLED_VERSION=1 -DENABLE_TEST_COVERAGE=1 cmake --build build/all cmake --build build/all --target test - cmake --build build/all --target GenerateDocs cmake --build build/all --target check-format +doc: all + cmake --build build/all --target GenerateDocs + format: distclean find . -name CMakeLists.txt | xargs cmake-format -i find . -name '*.cmake' | xargs cmake-format -i @@ -57,7 +58,7 @@ format: distclean find . -name '*.h' | xargs clang-format -i standalone: - cmake -S standalone -B build/standalone -G "${GENERATOR}" -DCMAKE_PREFIX_PATH=${DESTDIR} -DCMAKE_EXPORT_COMPILE_COMMANDS=1 + cmake -S standalone -B build/standalone -G "${GENERATOR}" -DCMAKE_PREFIX_PATH=${ROOT} -DCMAKE_EXPORT_COMPILE_COMMANDS=1 cmake --build build/standalone --target all # check the library diff --git a/include/greeter/greeter.h b/include/greeter/greeter.h index 8c41203..0e2b8d6 100644 --- a/include/greeter/greeter.h +++ b/include/greeter/greeter.h @@ -1,5 +1,7 @@ #pragma once +#include + #include namespace greeter { @@ -10,7 +12,7 @@ namespace greeter { /** * @brief A class for saying hello in multiple languages */ - class Greeter { + class GREETER_EXPORT Greeter { std::string name; public: diff --git a/test/source/greeter.cpp b/test/source/greeter.cpp index e3f23b7..4873653 100644 --- a/test/source/greeter.cpp +++ b/test/source/greeter.cpp @@ -16,7 +16,7 @@ TEST_CASE("Greeter") { } TEST_CASE("Greeter version") { -#if ((__cplusplus >= 201907L) || __cpp_lib_starts_ends_with) +#if (__APPLE__ || __cpp_lib_starts_ends_with) static_assert(std::string_view(GREETER_VERSION).starts_with("1.0")); // TBD C++20 only CHECK(std::string(GREETER_VERSION).starts_with("1.0")); // SameMajorVersion #else From fe76a4416cc053ee19c81e337069fad1c9d52ca3 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Mon, 15 Feb 2021 00:05:17 +0100 Subject: [PATCH 05/23] export all, but not privates --- include/greeter/greeter.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/greeter/greeter.h b/include/greeter/greeter.h index 0e2b8d6..02c906b 100644 --- a/include/greeter/greeter.h +++ b/include/greeter/greeter.h @@ -7,12 +7,13 @@ namespace greeter { /** Language codes to be used with the Greeter class */ - enum class LanguageCode { EN, DE, ES, FR }; + enum class GREETER_EXPORT LanguageCode { EN, DE, ES, FR }; /** * @brief A class for saying hello in multiple languages */ class GREETER_EXPORT Greeter { + private: std::string name; public: From 0322f4eeedc52dd0b68b1fd3e8ee35f25e1cb8e1 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Mon, 15 Feb 2021 09:28:30 +0100 Subject: [PATCH 06/23] perfect, dynamic libray suppart added SOVERSION 1 used and requered except for windoof! --- CMakeLists.txt | 11 ++++++----- include/greeter/greeter.h | 1 - test/CMakeLists.txt | 6 +++++- test/source/greeter.cpp | 6 ++---- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b4da9d3..2aa0ed1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,7 +20,9 @@ endif() # ---- Project settings ---- -option(BUILD_SHARED_LIBS "Create shared libraries if ON" YES) +if(NOT MSVC) + option(BUILD_SHARED_LIBS "Create shared libraries if ON" YES) +endif() if(NOT DEFINED CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 20) @@ -67,16 +69,15 @@ file(GLOB_RECURSE sources CONFIGURE_DEPENDS source/*.cpp) # Note: for header-only libraries change all PUBLIC flags to INTERFACE and create an interface # target! EITHER: add_library(Greeter INTERFACE) OR: add_library(Greeter ${headers} ${sources}) +set_target_properties(Greeter PROPERTIES SOVERSION 1 VERSION ${PROJECT_VERSION}) # EITHER: set_target_properties(Greeter PROPERTIES CXX_STANDARD ${CMAKE_CXX_STANDARD}) # OR: target_compile_features(Greeter PUBLIC cxx_std_20) # being a cross-platform target, we enforce standards conformance on MSVC EITHER: -# target_compile_options(Greeter PUBLIC "$<$:/permissive>") OR: -if(MSVC) - target_compile_options(Greeter PUBLIC /permissive) -endif() +target_compile_options(Greeter PUBLIC "$<$:/permissive>") +# OR: if(MSVC) target_compile_options(Greeter PUBLIC /permissive) endif() # Link dependencies EITHER: target_link_libraries(Greeter PRIVATE $) diff --git a/include/greeter/greeter.h b/include/greeter/greeter.h index 02c906b..3c8c1e8 100644 --- a/include/greeter/greeter.h +++ b/include/greeter/greeter.h @@ -13,7 +13,6 @@ namespace greeter { * @brief A class for saying hello in multiple languages */ class GREETER_EXPORT Greeter { - private: std::string name; public: diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 1b93cd2..22195f2 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,6 +1,10 @@ cmake_minimum_required(VERSION 3.14...3.19) -project(GreeterTests LANGUAGES CXX) +project( + GreeterTests + VERSION 1 + LANGUAGES CXX +) # ---- Options ---- diff --git a/test/source/greeter.cpp b/test/source/greeter.cpp index 4873653..6fabbb5 100644 --- a/test/source/greeter.cpp +++ b/test/source/greeter.cpp @@ -2,8 +2,6 @@ #include #include -#include - TEST_CASE("Greeter") { using namespace greeter; @@ -17,8 +15,8 @@ TEST_CASE("Greeter") { TEST_CASE("Greeter version") { #if (__APPLE__ || __cpp_lib_starts_ends_with) - static_assert(std::string_view(GREETER_VERSION).starts_with("1.0")); // TBD C++20 only - CHECK(std::string(GREETER_VERSION).starts_with("1.0")); // SameMajorVersion + static_assert(std::string_view(GREETER_VERSION).starts_with("1")); // TBD C++20 only + CHECK(std::string(GREETER_VERSION).starts_with("1")); // SameMajorVersion #else static_assert(std::string_view(GREETER_VERSION) == std::string_view("1.0.1")); CHECK(std::string(GREETER_VERSION) == std::string("1.0.1")); From 498caed2864c27f5329f2dd4849ab9024ad99f6c Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Mon, 15 Feb 2021 17:22:57 +0100 Subject: [PATCH 07/23] prevent warnings for windoof --- CMakeLists.txt | 6 +++--- test/CMakeLists.txt | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2aa0ed1..b8a4dff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,9 +20,9 @@ endif() # ---- Project settings ---- -if(NOT MSVC) - option(BUILD_SHARED_LIBS "Create shared libraries if ON" YES) -endif() +# XXX if(NOT MSVC) +option(BUILD_SHARED_LIBS "Create shared libraries if ON" YES) +# XXX endif() if(NOT DEFINED CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 20) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 22195f2..0ea6a09 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -54,7 +54,7 @@ if(NOT TEST_INSTALLED_VERSION) if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU") target_compile_options(Greeter PUBLIC -Wall -Wpedantic -Wextra -Werror) elseif(MSVC) - target_compile_options(Greeter PUBLIC /W4 /WX) + # XXX target_compile_options(Greeter PUBLIC /W4 /WX) target_compile_definitions(GreeterTests PUBLIC DOCTEST_CONFIG_USE_STD_HEADERS) endif() endif() From ab83f20c292f90ff964c4a77f7ac11eb0e0c5f4e Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Mon, 15 Feb 2021 17:33:17 +0100 Subject: [PATCH 08/23] it is a nightmare with windoof! ctest should be verbose --- .github/workflows/windows.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 23ebdfb..926aa11 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -33,4 +33,4 @@ jobs: - name: test run: | cd build - ctest --build-config Debug + ctest --build-config Debug --verbose From ae2d022801f6b04ef691b63789fc55697b4f7b73 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Mon, 15 Feb 2021 19:50:26 +0100 Subject: [PATCH 09/23] windoof dll export is not as easy as it should! --- include/greeter/greeter.h | 3 ++- test/CMakeLists.txt | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/include/greeter/greeter.h b/include/greeter/greeter.h index 3c8c1e8..64b6446 100644 --- a/include/greeter/greeter.h +++ b/include/greeter/greeter.h @@ -13,6 +13,7 @@ namespace greeter { * @brief A class for saying hello in multiple languages */ class GREETER_EXPORT Greeter { + protected: std::string name; public: @@ -20,7 +21,7 @@ namespace greeter { * @brief Creates a new greeter * @param name the name to greet */ - explicit Greeter(std::string name); + explicit Greeter(std::string _name); /** * @brief Creates a localized string containing the greeting diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 0ea6a09..22195f2 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -54,7 +54,7 @@ if(NOT TEST_INSTALLED_VERSION) if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU") target_compile_options(Greeter PUBLIC -Wall -Wpedantic -Wextra -Werror) elseif(MSVC) - # XXX target_compile_options(Greeter PUBLIC /W4 /WX) + target_compile_options(Greeter PUBLIC /W4 /WX) target_compile_definitions(GreeterTests PUBLIC DOCTEST_CONFIG_USE_STD_HEADERS) endif() endif() From ee5c92ff16d6e6648848373c5927dd2bb46d2bdc Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Mon, 15 Feb 2021 20:16:55 +0100 Subject: [PATCH 10/23] last try ... --- include/greeter/greeter.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/greeter/greeter.h b/include/greeter/greeter.h index 64b6446..02b91cb 100644 --- a/include/greeter/greeter.h +++ b/include/greeter/greeter.h @@ -14,7 +14,7 @@ namespace greeter { */ class GREETER_EXPORT Greeter { protected: - std::string name; + std::string GREETER_EXPORT name; public: /** From 4f66d198b95411adea3bc1abe6ee0222cfae8ba6 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Mon, 15 Feb 2021 20:26:33 +0100 Subject: [PATCH 11/23] usec ClangCL instead of MVC --- .github/workflows/windows.yml | 2 +- include/greeter/greeter.h | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 926aa11..e5e2ed8 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -25,7 +25,7 @@ jobs: key: ${{ github.workflow }}-cpm-modules-${{ hashFiles('**/CMakeLists.txt', '**/*.cmake') }} - name: configure - run: cmake -Stest -Bbuild + run: cmake -Stest -Bbuild -G "Visual Studio 16 2019" -T ClangCL - name: build run: cmake --build build --config Debug -j4 diff --git a/include/greeter/greeter.h b/include/greeter/greeter.h index 02b91cb..36edcfe 100644 --- a/include/greeter/greeter.h +++ b/include/greeter/greeter.h @@ -13,8 +13,7 @@ namespace greeter { * @brief A class for saying hello in multiple languages */ class GREETER_EXPORT Greeter { - protected: - std::string GREETER_EXPORT name; + std::string name; public: /** From 2b09a8dcb67fc7d0a3177386c4dc3cc40865d227 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Mon, 15 Feb 2021 20:35:09 +0100 Subject: [PATCH 12/23] be less pedantic for ClangCL --- test/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 22195f2..f101f83 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -52,7 +52,7 @@ set_target_properties(GreeterTests PROPERTIES CXX_STANDARD ${CMAKE_CXX_STANDARD} # enable compiler warnings if(NOT TEST_INSTALLED_VERSION) if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU") - target_compile_options(Greeter PUBLIC -Wall -Wpedantic -Wextra -Werror) + target_compile_options(Greeter PUBLIC -Wall -Wextra -Werror) elseif(MSVC) target_compile_options(Greeter PUBLIC /W4 /WX) target_compile_definitions(GreeterTests PUBLIC DOCTEST_CONFIG_USE_STD_HEADERS) From e537d11f1de093015db7aa15768ff0f0e7f84772 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Mon, 15 Feb 2021 20:50:34 +0100 Subject: [PATCH 13/23] extend compiler detection for ClangCL --- test/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f101f83..ce90721 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -51,7 +51,7 @@ set_target_properties(GreeterTests PROPERTIES CXX_STANDARD ${CMAKE_CXX_STANDARD} # enable compiler warnings if(NOT TEST_INSTALLED_VERSION) - if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU") + if(CMAKE_CXX_COMPILER_ID MATCHES "(Apple)?[Cc]lang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU") target_compile_options(Greeter PUBLIC -Wall -Wextra -Werror) elseif(MSVC) target_compile_options(Greeter PUBLIC /W4 /WX) From b727eadfc71dff8dabce7bdc3da3aeed6476d9a2 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Mon, 15 Feb 2021 21:01:56 +0100 Subject: [PATCH 14/23] back to c++17 --- CMakeLists.txt | 2 +- cmake/tools.cmake | 2 +- test/source/greeter.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b8a4dff..f04a2cb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,7 +25,7 @@ option(BUILD_SHARED_LIBS "Create shared libraries if ON" YES) # XXX endif() if(NOT DEFINED CMAKE_CXX_STANDARD) - set(CMAKE_CXX_STANDARD 20) + set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS NO) endif() diff --git a/cmake/tools.cmake b/cmake/tools.cmake index 3d87468..3ed235e 100644 --- a/cmake/tools.cmake +++ b/cmake/tools.cmake @@ -10,7 +10,7 @@ include(${CMAKE_CURRENT_LIST_DIR}/CPM.cmake) CPMUsePackageLock(package-lock.cmake) if(NOT DEFINED CMAKE_CXX_STANDARD) - set(CMAKE_CXX_STANDARD 20) + set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS NO) endif() diff --git a/test/source/greeter.cpp b/test/source/greeter.cpp index 6fabbb5..ff3204b 100644 --- a/test/source/greeter.cpp +++ b/test/source/greeter.cpp @@ -14,7 +14,7 @@ TEST_CASE("Greeter") { } TEST_CASE("Greeter version") { -#if (__APPLE__ || __cpp_lib_starts_ends_with) +#if (__cpp_lib_starts_ends_with) static_assert(std::string_view(GREETER_VERSION).starts_with("1")); // TBD C++20 only CHECK(std::string(GREETER_VERSION).starts_with("1")); // SameMajorVersion #else From d7a5e850a02defcd453f8934788236f4b31d1cc5 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Mon, 15 Feb 2021 21:14:51 +0100 Subject: [PATCH 15/23] giv it up, no DLL with windoof --- .github/workflows/windows.yml | 3 ++- CMakeLists.txt | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index e5e2ed8..8501585 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -1,3 +1,4 @@ +--- name: Windows on: @@ -25,7 +26,7 @@ jobs: key: ${{ github.workflow }}-cpm-modules-${{ hashFiles('**/CMakeLists.txt', '**/*.cmake') }} - name: configure - run: cmake -Stest -Bbuild -G "Visual Studio 16 2019" -T ClangCL + run: cmake -Stest -Bbuild # XXX -G "Visual Studio 16 2019" -T ClangCL - name: build run: cmake --build build --config Debug -j4 diff --git a/CMakeLists.txt b/CMakeLists.txt index f04a2cb..20bd590 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,9 +20,9 @@ endif() # ---- Project settings ---- -# XXX if(NOT MSVC) -option(BUILD_SHARED_LIBS "Create shared libraries if ON" YES) -# XXX endif() +if(NOT MSVC) + option(BUILD_SHARED_LIBS "Create shared libraries if ON" YES) +endif() if(NOT DEFINED CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 17) From f59c0cfbee7343a610fd15a24309da44965d75de Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Tue, 16 Feb 2021 18:25:02 +0100 Subject: [PATCH 16/23] one more try with dll on windows cleanup code too --- CMakeLists.txt | 16 +++++----------- include/greeter/greeter.h | 9 +++++---- standalone/source/main.cpp | 5 ----- test/CMakeLists.txt | 2 -- 4 files changed, 10 insertions(+), 22 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 20bd590..45135f6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,9 +20,9 @@ endif() # ---- Project settings ---- -if(NOT MSVC) - option(BUILD_SHARED_LIBS "Create shared libraries if ON" YES) -endif() +# XXX if(NOT MSVC) +option(BUILD_SHARED_LIBS "Create shared libraries if ON" YES) +# XXX endif() if(NOT DEFINED CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 17) @@ -44,12 +44,9 @@ CPMUsePackageLock(package-lock.cmake) CPMAddPackage( NAME PackageProject.cmake GITHUB_REPOSITORY TheLartians/PackageProject.cmake - VERSION 1.4.1 + VERSION 1.5.0 ) -# Note: If fmt is not imported, this is needed to prevent: CMake Error: install(EXPORT -# "GreeterTargets" ...) includes target "Greeter" which requires target "fmt" that is not in any -# export set. see too https://gitlab.kitware.com/cmake/cmake/-/issues/15415 CPMAddPackage( NAME fmt GIT_TAG 7.1.3 @@ -71,13 +68,10 @@ file(GLOB_RECURSE sources CONFIGURE_DEPENDS source/*.cpp) add_library(Greeter ${headers} ${sources}) set_target_properties(Greeter PROPERTIES SOVERSION 1 VERSION ${PROJECT_VERSION}) -# EITHER: set_target_properties(Greeter PROPERTIES CXX_STANDARD ${CMAKE_CXX_STANDARD}) -# OR: target_compile_features(Greeter PUBLIC cxx_std_20) -# being a cross-platform target, we enforce standards conformance on MSVC EITHER: +# being a cross-platform target, we enforce standards conformance on MSVC: target_compile_options(Greeter PUBLIC "$<$:/permissive>") -# OR: if(MSVC) target_compile_options(Greeter PUBLIC /permissive) endif() # Link dependencies EITHER: target_link_libraries(Greeter PRIVATE $) diff --git a/include/greeter/greeter.h b/include/greeter/greeter.h index 36edcfe..1266283 100644 --- a/include/greeter/greeter.h +++ b/include/greeter/greeter.h @@ -7,12 +7,12 @@ namespace greeter { /** Language codes to be used with the Greeter class */ - enum class GREETER_EXPORT LanguageCode { EN, DE, ES, FR }; + enum class LanguageCode { EN, DE, ES, FR }; /** * @brief A class for saying hello in multiple languages */ - class GREETER_EXPORT Greeter { + class Greeter { std::string name; public: @@ -20,14 +20,15 @@ namespace greeter { * @brief Creates a new greeter * @param name the name to greet */ - explicit Greeter(std::string _name); + explicit GREETER_EXPORT Greeter(std::string _name); /** * @brief Creates a localized string containing the greeting * @param lang the language to greet in * @return a string containing the greeting */ - [[nodiscard]] auto greet(LanguageCode lang = LanguageCode::EN) const -> std::string; + [[nodiscard]] auto GREETER_EXPORT greet(LanguageCode lang = LanguageCode::EN) const + -> std::string; }; } // namespace greeter diff --git a/standalone/source/main.cpp b/standalone/source/main.cpp index 6874460..55588bb 100644 --- a/standalone/source/main.cpp +++ b/standalone/source/main.cpp @@ -8,8 +8,6 @@ // NOLINTNEXTLINE(modernize-use-trailing-return-type) int main(int argc, char** argv) { - // prevent warning: initialization of 'languages' with static storage duration may throw an - // exception that cannot be caught [cert-err58-cpp] const std::unordered_map languages{ {"en", greeter::LanguageCode::EN}, {"de", greeter::LanguageCode::DE}, @@ -17,8 +15,6 @@ int main(int argc, char** argv) { {"fr", greeter::LanguageCode::FR}, }; - // prevent warning: do not use pointer arithmetic - // [cppcoreguidelines-pro-bounds-pointer-arithmetic] cxxopts::Options options(*argv, "A program to welcome the world!"); std::string language; @@ -40,7 +36,6 @@ int main(int argc, char** argv) { return 0; } - // prevent warning: do not use 'else' after 'return' [readability-else-after-return] if (result["version"].as()) { std::cout << "Greeter, version " << GREETER_VERSION << std::endl; return 0; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ce90721..de24d8e 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -45,9 +45,7 @@ CPMAddPackage( file(GLOB sources CONFIGURE_DEPENDS source/*.cpp) add_executable(GreeterTests ${sources}) target_link_libraries(GreeterTests doctest::doctest Greeter::Greeter) -# EITHER: set_target_properties(GreeterTests PROPERTIES CXX_STANDARD ${CMAKE_CXX_STANDARD}) -# OR: target_compile_features(GreeterTests PUBLIC cxx_std_20) # enable compiler warnings if(NOT TEST_INSTALLED_VERSION) From fd7e1b94b3c627918a52fa301490863b272985fd Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Tue, 16 Feb 2021 18:45:15 +0100 Subject: [PATCH 17/23] Windoof for unix geeks ... I will be crazy! --- .github/workflows/windows.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 8501585..d8387c9 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -34,4 +34,6 @@ jobs: - name: test run: | cd build + dir + Debug\GreeterTests.exe -s ctest --build-config Debug --verbose From 5c08961b72ef7b4b6f344395c7e33ddbb04b92a6 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Tue, 16 Feb 2021 18:57:14 +0100 Subject: [PATCH 18/23] the last try to solve this miracle --- .github/workflows/windows.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index d8387c9..2853f15 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -34,6 +34,8 @@ jobs: - name: test run: | cd build - dir - Debug\GreeterTests.exe -s + dir bin + dir x64 + dir Debug + Debug/GreeterTests.exe -s ctest --build-config Debug --verbose From a13fc3b9f87418c65dff1aa5191211c15ffe413f Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Tue, 16 Feb 2021 19:07:48 +0100 Subject: [PATCH 19/23] where is the dll? --- .github/workflows/windows.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 2853f15..6725b37 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -34,8 +34,8 @@ jobs: - name: test run: | cd build - dir bin - dir x64 + tree bin/Debug + tree x64/Debug dir Debug Debug/GreeterTests.exe -s ctest --build-config Debug --verbose From 78b430b172a3f0b98c58cabcec590791ad88e93f Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Tue, 16 Feb 2021 19:13:14 +0100 Subject: [PATCH 20/23] I hate backslashes --- .github/workflows/windows.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 6725b37..1f5f100 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -34,8 +34,8 @@ jobs: - name: test run: | cd build - tree bin/Debug - tree x64/Debug + tree bin\Debug + tree x64\Debug dir Debug Debug/GreeterTests.exe -s ctest --build-config Debug --verbose From 56a3c22ad9a8befb372a7f1e2b4829f48f18c810 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Wed, 17 Feb 2021 00:51:29 +0100 Subject: [PATCH 21/23] build all dll and executable at bin directory --- .github/workflows/install.yml | 7 +++++-- .github/workflows/macos.yml | 5 ++++- .github/workflows/standalone.yml | 5 +++-- .github/workflows/style.yml | 5 ++++- .github/workflows/ubuntu.yml | 5 ++++- .github/workflows/windows.yml | 9 ++++----- CMakeLists.txt | 5 +++-- GNUmakefile | 2 +- cmake/tools.cmake | 4 ++++ test/CMakeLists.txt | 2 +- 10 files changed, 33 insertions(+), 16 deletions(-) diff --git a/.github/workflows/install.yml b/.github/workflows/install.yml index 8cb80aa..d8186f6 100644 --- a/.github/workflows/install.yml +++ b/.github/workflows/install.yml @@ -1,11 +1,14 @@ +--- name: Install on: push: branches: + - master - develop pull_request: branches: + - master - develop env: @@ -26,12 +29,12 @@ jobs: - name: build and install library run: | - cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release + cmake -S . -B build -DCMAKE_BUILD_TYPE=Release sudo cmake --build build --target install rm -rf build - name: configure - run: cmake -Stest -Bbuild -DTEST_INSTALLED_VERSION=1 + run: cmake -S test -B build -DTEST_INSTALLED_VERSION=1 - name: build run: cmake --build build --config Debug -j4 diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index cba48ae..bbe6b24 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -1,11 +1,14 @@ +--- name: MacOS on: push: branches: + - master - develop pull_request: branches: + - master - develop env: @@ -25,7 +28,7 @@ jobs: key: ${{ github.workflow }}-cpm-modules-${{ hashFiles('**/CMakeLists.txt', '**/*.cmake') }} - name: configure - run: cmake -Stest -Bbuild -DCMAKE_BUILD_TYPE=Debug + run: cmake -S test -B build -DCMAKE_BUILD_TYPE=Debug - name: build run: cmake --build build -j4 diff --git a/.github/workflows/standalone.yml b/.github/workflows/standalone.yml index bfb9c18..988163d 100644 --- a/.github/workflows/standalone.yml +++ b/.github/workflows/standalone.yml @@ -1,3 +1,4 @@ +--- name: Standalone on: @@ -24,10 +25,10 @@ jobs: key: ${{ github.workflow }}-cpm-modules-${{ hashFiles('**/CMakeLists.txt', '**/*.cmake') }} - name: configure - run: cmake -Sstandalone -Bbuild -DCMAKE_BUILD_TYPE=Debug -DCMAKE_BUILD_TYPE=Debug + run: cmake -S standalone -B build -DCMAKE_BUILD_TYPE=Debug -DCMAKE_BUILD_TYPE=Debug - name: build run: cmake --build build -j4 - name: run - run: ./build/Greeter + run: ./build/bin/Greeter diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml index d3ed946..9fabf78 100644 --- a/.github/workflows/style.yml +++ b/.github/workflows/style.yml @@ -1,11 +1,14 @@ +--- name: Style on: push: branches: + - master - develop pull_request: branches: + - master - develop env: @@ -29,7 +32,7 @@ jobs: pip3 install cmake_format==0.6.11 pyyaml - name: configure - run: cmake -Stest -Bbuild + run: cmake -S test -B build - name: check style run: cmake --build build --target check-format diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index dfc2ec5..ad04e6a 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -1,11 +1,14 @@ +--- name: Ubuntu on: push: branches: + - master - develop pull_request: branches: + - master - develop env: @@ -26,7 +29,7 @@ jobs: key: ${{ github.workflow }}-cpm-modules-${{ hashFiles('**/CMakeLists.txt', '**/*.cmake') }} - name: configure - run: cmake -Stest -Bbuild -DENABLE_TEST_COVERAGE=1 -DCMAKE_BUILD_TYPE=Debug + run: cmake -S test -B build -DENABLE_TEST_COVERAGE=1 -DCMAKE_BUILD_TYPE=Debug - name: build run: cmake --build build -j4 diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 1f5f100..2459373 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -4,9 +4,11 @@ name: Windows on: push: branches: + - master - develop pull_request: branches: + - master - develop env: @@ -26,7 +28,7 @@ jobs: key: ${{ github.workflow }}-cpm-modules-${{ hashFiles('**/CMakeLists.txt', '**/*.cmake') }} - name: configure - run: cmake -Stest -Bbuild # XXX -G "Visual Studio 16 2019" -T ClangCL + run: cmake -S test -B build # XXX -G "Visual Studio 16 2019" -T ClangCL - name: build run: cmake --build build --config Debug -j4 @@ -34,8 +36,5 @@ jobs: - name: test run: | cd build - tree bin\Debug - tree x64\Debug - dir Debug - Debug/GreeterTests.exe -s + tree ctest --build-config Debug --verbose diff --git a/CMakeLists.txt b/CMakeLists.txt index 45135f6..6de268a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,9 +20,10 @@ endif() # ---- Project settings ---- -# XXX if(NOT MSVC) option(BUILD_SHARED_LIBS "Create shared libraries if ON" YES) -# XXX endif() +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) if(NOT DEFINED CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 17) diff --git a/GNUmakefile b/GNUmakefile index 77888a8..3b6fca9 100755 --- a/GNUmakefile +++ b/GNUmakefile @@ -6,7 +6,7 @@ ROOT?=${CURDIR}/stagedir GENERATOR?=Ninja #XXX export CXX=clang++ -export CPM_USE_LOCAL_PACKAGES=1 +export CPM_USE_LOCAL_PACKAGES=0 export CPM_SOURCE_CACHE=${HOME}/.cache/CPM .PHONY: update format all test standalone doc check clean distclean lock diff --git a/cmake/tools.cmake b/cmake/tools.cmake index 3ed235e..bf2216f 100644 --- a/cmake/tools.cmake +++ b/cmake/tools.cmake @@ -9,6 +9,10 @@ endif() include(${CMAKE_CURRENT_LIST_DIR}/CPM.cmake) CPMUsePackageLock(package-lock.cmake) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) + if(NOT DEFINED CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index de24d8e..f3810b0 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -61,7 +61,7 @@ endif() enable_testing() -add_test(greeterTests GreeterTests) +add_test(NAME greeterTests COMMAND GreeterTests) # ---- code coverage ---- From 9391ce636a344383a6520f74757259595688b887 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Wed, 17 Feb 2021 01:11:36 +0100 Subject: [PATCH 22/23] cleanup the test output again --- .github/workflows/windows.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 2459373..d8d09e3 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -36,5 +36,4 @@ jobs: - name: test run: | cd build - tree ctest --build-config Debug --verbose From 6ea6bdd2ea267ead418b1b0514dae58615dd14dd Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Wed, 17 Feb 2021 10:31:56 +0100 Subject: [PATCH 23/23] add options.cmake project config file common options used for every cmake project prevent reame of standalone executable via cmake properties --- .github/workflows/standalone.yml | 6 ++-- CMakeLists.txt | 20 +++---------- GNUmakefile | 35 ++++++++++++---------- all/package-lock.cmake | 19 ------------ cmake/options.cmake | 50 ++++++++++++++++++++++++++++++++ cmake/tools.cmake | 10 +------ package-lock.cmake | 9 ------ standalone/CMakeLists.txt | 10 +++---- standalone/package-lock.cmake | 9 ------ test/CMakeLists.txt | 2 +- test/package-lock.cmake | 17 ----------- 11 files changed, 84 insertions(+), 103 deletions(-) delete mode 100644 all/package-lock.cmake create mode 100644 cmake/options.cmake delete mode 100644 package-lock.cmake delete mode 100644 standalone/package-lock.cmake delete mode 100644 test/package-lock.cmake diff --git a/.github/workflows/standalone.yml b/.github/workflows/standalone.yml index 988163d..ca2d2f1 100644 --- a/.github/workflows/standalone.yml +++ b/.github/workflows/standalone.yml @@ -30,5 +30,7 @@ jobs: - name: build run: cmake --build build -j4 - - name: run - run: ./build/bin/Greeter + - name: test + run: | + cd build + ctest --build-config Debug --verbose diff --git a/CMakeLists.txt b/CMakeLists.txt index 6de268a..959bb14 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,20 +20,7 @@ endif() # ---- Project settings ---- -option(BUILD_SHARED_LIBS "Create shared libraries if ON" YES) -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) -set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) - -if(NOT DEFINED CMAKE_CXX_STANDARD) - set(CMAKE_CXX_STANDARD 17) - set(CMAKE_CXX_STANDARD_REQUIRED ON) - set(CMAKE_CXX_EXTENSIONS NO) -endif() - -# Set default visibility to hidden for all targets -set(CMAKE_CXX_VISIBILITY_PRESET hidden) -set(CMAKE_VISIBILITY_INLINES_HIDDEN YES) +include(cmake/options.cmake) # ---- Add dependencies via CPM ---- # see https://github.com/cpm-cmake/CPM.cmake for more info @@ -67,10 +54,11 @@ file(GLOB_RECURSE sources CONFIGURE_DEPENDS source/*.cpp) # Note: for header-only libraries change all PUBLIC flags to INTERFACE and create an interface # target! EITHER: add_library(Greeter INTERFACE) OR: add_library(Greeter ${headers} ${sources}) -set_target_properties(Greeter PROPERTIES SOVERSION 1 VERSION ${PROJECT_VERSION}) - set_target_properties(Greeter PROPERTIES CXX_STANDARD ${CMAKE_CXX_STANDARD}) +# for SameMajorVersion upgrade stategie +set_target_properties(Greeter PROPERTIES SOVERSION 1 VERSION ${PROJECT_VERSION}) + # being a cross-platform target, we enforce standards conformance on MSVC: target_compile_options(Greeter PUBLIC "$<$:/permissive>") diff --git a/GNUmakefile b/GNUmakefile index 3b6fca9..edf5402 100755 --- a/GNUmakefile +++ b/GNUmakefile @@ -1,6 +1,6 @@ # -# CURDIR=$(/bin/pwd) -ROOT?=${CURDIR}/stagedir +# Note: make var CURDIR:=$(/bin/pwd) +ROOT?=$(CURDIR)/stagedir #XXX GENERATOR?="Unix Makefiles" GENERATOR?=Ninja @@ -24,32 +24,35 @@ distclean: clean update: wget -q -O cmake/CPM.cmake https://github.com/cpm-cmake/CPM.cmake/releases/latest/download/get_cpm.cmake -lock: standalone all +lock: all standalone doc 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 + cmake --build build/documentation --target cpm-update-package-lock # install the library to stagedir install: - cmake -S . -B build/install -G "${GENERATOR}" -DCMAKE_PREFIX_PATH=${ROOT} -DCMAKE_INSTALL_PREFIX=${ROOT} # --trace-expand - cmake --build build/install --target install + cmake -S . -B build/$@ -G "${GENERATOR}" -DCMAKE_PREFIX_PATH=${ROOT} -DCMAKE_INSTALL_PREFIX=${ROOT} # --trace-expand + cmake --build build/$@ --target $@ # test the library test: install - cmake -S test -B build/test -G "${GENERATOR}" -DCMAKE_PREFIX_PATH=${ROOT} -DTEST_INSTALLED_VERSION=1 - cmake --build build/test - cmake --build build/test --target test + cmake -S $@ -B build/$@ -G "${GENERATOR}" -DCMAKE_PREFIX_PATH=${ROOT} -DTEST_INSTALLED_VERSION=1 + cmake --build build/$@ + cmake --build build/$@ --target $@ # all together all: test - cmake -S all -B build/all -G "${GENERATOR}" -DCMAKE_PREFIX_PATH=${ROOT} -DTEST_INSTALLED_VERSION=1 -DENABLE_TEST_COVERAGE=1 - cmake --build build/all - cmake --build build/all --target test - cmake --build build/all --target check-format + cmake -S $@ -B build/$@ -G "${GENERATOR}" -DCMAKE_PREFIX_PATH=${ROOT} -DTEST_INSTALLED_VERSION=1 -DENABLE_TEST_COVERAGE=1 + cmake --build build/$@ + cmake --build build/$@ --target test + cmake --build build/$@ --target check-format -doc: all - cmake --build build/all --target GenerateDocs +# GenerateDocs +doc: + cmake -S documentation -B build/documentation -G "${GENERATOR}" + cmake --build build/documentation --target GenerateDocs format: distclean find . -name CMakeLists.txt | xargs cmake-format -i @@ -58,8 +61,8 @@ format: distclean find . -name '*.h' | xargs clang-format -i standalone: - cmake -S standalone -B build/standalone -G "${GENERATOR}" -DCMAKE_PREFIX_PATH=${ROOT} -DCMAKE_EXPORT_COMPILE_COMMANDS=1 - cmake --build build/standalone --target all + cmake -S $@ -B build/$@ -G "${GENERATOR}" -DCMAKE_PREFIX_PATH=${ROOT} -DCMAKE_EXPORT_COMPILE_COMMANDS=1 + cmake --build build/$@ # check the library check: standalone diff --git a/all/package-lock.cmake b/all/package-lock.cmake deleted file mode 100644 index 5e0bc01..0000000 --- a/all/package-lock.cmake +++ /dev/null @@ -1,19 +0,0 @@ -# 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 -) -# 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/options.cmake b/cmake/options.cmake new file mode 100644 index 0000000..8650052 --- /dev/null +++ b/cmake/options.cmake @@ -0,0 +1,50 @@ +# only activate options for top level project +if(NOT PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) + return() +endif() + +option(BUILD_SHARED_LIBS "Create shared libraries" YES) + +# Set default visibility to hidden for all targets +set(CMAKE_CXX_VISIBILITY_PRESET hidden) +set(CMAKE_VISIBILITY_INLINES_HIDDEN YES) + +# build the dynamic libraries and executables together at bin directory +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) + +if(NOT DEFINED CMAKE_CXX_STANDARD) + option(CXX_STANDARD_REQUIRED "Require c++ standard" YES) + set(CMAKE_CXX_STANDARD 17) + set(CMAKE_CXX_EXTENSIONS NO) +endif() + +# this reduce build time if using Nina generators +option(CMAKE_DEPENDS_IN_PROJECT_ONLY "do NOT use system header files for dependency checking" YES) +if(NOT MSVC) + if(CMAKE_DEPENDS_IN_PROJECT_ONLY) + set(CMAKE_DEPFILE_FLAGS_C + "-MMD" + CACHE STRING "dependency flag" FORCE + ) + set(CMAKE_DEPFILE_FLAGS_CXX + "-MMD" + CACHE STRING "dependency flag" FORCE + ) + else() + set(CMAKE_DEPFILE_FLAGS_C + "-MD" + CACHE STRING "dependency flag" FORCE + ) + set(CMAKE_DEPFILE_FLAGS_CXX + "-MD" + CACHE STRING "dependency flag" FORCE + ) + endif() +endif() + +option(CMAKE_EXPORT_COMPILE_COMMANDS "support clang-tidy, cppcheck, ..." YES) +if(CMAKE_EXPORT_COMPILE_COMMANDS) + set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES}) +endif() diff --git a/cmake/tools.cmake b/cmake/tools.cmake index bf2216f..a5d1f1f 100644 --- a/cmake/tools.cmake +++ b/cmake/tools.cmake @@ -9,15 +9,7 @@ endif() include(${CMAKE_CURRENT_LIST_DIR}/CPM.cmake) CPMUsePackageLock(package-lock.cmake) -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) -set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) - -if(NOT DEFINED CMAKE_CXX_STANDARD) - set(CMAKE_CXX_STANDARD 17) - set(CMAKE_CXX_STANDARD_REQUIRED ON) - set(CMAKE_CXX_EXTENSIONS NO) -endif() +include(${CMAKE_CURRENT_LIST_DIR}/options.cmake) # option: default not set set(USE_STATIC_ANALYZER diff --git a/package-lock.cmake b/package-lock.cmake deleted file mode 100644 index 6d59719..0000000 --- a/package-lock.cmake +++ /dev/null @@ -1,9 +0,0 @@ -# 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 -) diff --git a/standalone/CMakeLists.txt b/standalone/CMakeLists.txt index 003cf8a..f80a0d7 100644 --- a/standalone/CMakeLists.txt +++ b/standalone/CMakeLists.txt @@ -25,14 +25,14 @@ CPMAddPackage(NAME Greeter SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/..) file(GLOB sources CONFIGURE_DEPENDS source/*.cpp) add_executable(GreeterStandalone ${sources}) - -# TODO: why rename in this way? Seems only for CI with GitHub actions! CK -set_target_properties( - GreeterStandalone PROPERTIES CXX_STANDARD ${CMAKE_CXX_STANDARD} OUTPUT_NAME "Greeter" -) +set_target_properties(GreeterStandalone PROPERTIES CXX_STANDARD ${CMAKE_CXX_STANDARD}) # WORKAROUND missing ALIAS target error! CK if(NOT TARGET cxxopts::cxxopts) add_library(cxxopts::cxxopts ALIAS cxxopts) endif() target_link_libraries(GreeterStandalone Greeter::Greeter cxxopts::cxxopts) + +# ---- run the standalone executable ---- +enable_testing() +add_test(NAME GreeterStandalone COMMAND GreeterStandalone) diff --git a/standalone/package-lock.cmake b/standalone/package-lock.cmake deleted file mode 100644 index bf1e9d9..0000000 --- a/standalone/package-lock.cmake +++ /dev/null @@ -1,9 +0,0 @@ -# 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 -) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f3810b0..b86c7e0 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -61,7 +61,7 @@ endif() enable_testing() -add_test(NAME greeterTests COMMAND GreeterTests) +add_test(NAME greeterTests COMMAND GreeterTests -s false) # ---- code coverage ---- diff --git a/test/package-lock.cmake b/test/package-lock.cmake deleted file mode 100644 index efa8ce4..0000000 --- a/test/package-lock.cmake +++ /dev/null @@ -1,17 +0,0 @@ -# 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 -) -# Format.cmake -CPMDeclarePackage( - Format.cmake - NAME Format.cmake - VERSION 1.6 - GITHUB_REPOSITORY TheLartians/Format.cmake - OPTIONS "FORMAT_CHECK_CMAKE ON" -)