Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create version header and update readme #44

Merged
merged 6 commits into from
Jun 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ include(cmake/CPM.cmake)
CPMAddPackage(
NAME PackageProject.cmake
GITHUB_REPOSITORY TheLartians/PackageProject.cmake
VERSION 1.2.1
VERSION 1.3
)

# ---- Add source files ----
Expand Down Expand Up @@ -58,11 +58,16 @@ target_include_directories(Greeter
# ---- Create an installable target ----
# this allows users to install and find the library via `find_package()`.

# 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)

packageProject(
NAME ${PROJECT_NAME}
VERSION ${PROJECT_VERSION}
BINARY_DIR ${PROJECT_BINARY_DIR}
INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include
INCLUDE_DESTINATION include/${PROJECT_NAME}-${PROJECT_VERSION}
VERSION_HEADER "${VERSION_HEADER_LOCATION}"
DEPENDENCIES ""
)
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ This template is the result of learnings from many previous projects and should
- Code formatting enforced by [clang-format](https://clang.llvm.org/docs/ClangFormat.html) via [Format.cmake](https://github.com/TheLartians/Format.cmake)
- Reproducible dependency management via [CPM.cmake](https://github.com/TheLartians/CPM.cmake)
- Installable target with versioning information via [PackageProject.cmake](https://github.com/TheLartians/PackageProject.cmake)
- Automatic documentation generation with [Doxygen](https://www.doxygen.nl)
- Automatic documentation generation and deployment with [Doxygen](https://www.doxygen.nl) and [GitHub Pages](https://pages.github.com)
- Support for [sanitizer tools, and more](#additional-tools)

## Usage
Expand Down Expand Up @@ -84,7 +84,7 @@ See [Format.cmake](https://github.com/TheLartians/Format.cmake) for more options

### Build the documentation

The documentation is automatically built and updated after every [release](https://help.github.com/en/github/administering-a-repository/managing-releases-in-a-repository).
The documentation is automatically built and [published](https://thelartians.github.io/ModernCppStarter) whenever a [GitHub Release](https://help.github.com/en/github/administering-a-repository/managing-releases-in-a-repository) is created.
To manually build documentation, call the following command.

```bash
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion source/greeter.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <greeter.h>
#include <greeter/greeter.h>

using namespace greeter;

Expand Down
9 changes: 7 additions & 2 deletions standalone/source/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <greeter.h>
#include <greeter/greeter.h>
#include <greeter/version.h>

#include <cxxopts.hpp>
#include <iostream>
Expand All @@ -21,6 +22,7 @@ int main(int argc, char** argv) {
// clang-format off
options.add_options()
("h,help", "Show help")
("v,version", "Print the current version number")
("n,name", "Name to greet", cxxopts::value(name)->default_value("World"))
("l,lang", "Language code to use", cxxopts::value(language)->default_value("en"))
;
Expand All @@ -31,11 +33,14 @@ int main(int argc, char** argv) {
if (result["help"].as<bool>()) {
std::cout << options.help() << std::endl;
return 0;
} else if (result["version"].as<bool>()) {
std::cout << "Greeter, version " << GREETER_VERSION << std::endl;
return 0;
}

auto langIt = languages.find(language);
if (langIt == languages.end()) {
std::cout << "unknown language code: " << language << std::endl;
std::cerr << "unknown language code: " << language << std::endl;
return 1;
}

Expand Down
10 changes: 9 additions & 1 deletion test/source/greeter.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include <doctest/doctest.h>
#include <greeter.h>
#include <greeter/greeter.h>
#include <greeter/version.h>

#include <string>

TEST_CASE("Greeter") {
using namespace greeter;
Expand All @@ -11,3 +14,8 @@ TEST_CASE("Greeter") {
CHECK(greeter.greet(LanguageCode::ES) == "¡Hola Tests!");
CHECK(greeter.greet(LanguageCode::FR) == "Bonjour Tests!");
}

TEST_CASE("Greeter version") {
static_assert(std::string_view(GREETER_VERSION) == std::string_view("1.0"));
CHECK(std::string(GREETER_VERSION) == std::string("1.0"));
}