Skip to content

Commit e16063a

Browse files
authored
Merge pull request #31 from acd1034/30-fix-ci-and-cmakelists
Resolve: Fix CI and CMakeLists
2 parents bb5a5b3 + 141b484 commit e16063a

File tree

15 files changed

+169
-89
lines changed

15 files changed

+169
-89
lines changed

.github/workflows/gen-docs.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,32 @@ name: Generate Documents
66
on:
77
push:
88
branches: [ main ]
9-
pull_request:
10-
branches: [ main ]
119

1210
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
1311
jobs:
1412
# This workflow contains a single job called "build"
1513
build:
1614
# The type of runner that the job will run on
1715
runs-on: ubuntu-latest
16+
timeout-minutes: 10
1817

1918
# Steps represent a sequence of tasks that will be executed as part of the job
2019
steps:
2120
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
22-
- name: Checkout
23-
uses: actions/checkout@v2
21+
- uses: actions/checkout@v2
22+
with:
23+
submodules: recursive
2424

2525
- name: Build by Doxygen
2626
uses: mattnotmitt/[email protected]
2727
with:
28-
working-directory: '.'
2928
doxyfile-path: 'Doxyfile'
29+
working-directory: '.'
3030

3131
- name: Deploy
3232
uses: JamesIves/github-pages-deploy-action@releases/v3
3333
with:
3434
ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3535
BRANCH: gh-pages # The branch the action should deploy to
36-
FOLDER: docs # The folder the action should deploy. Specified by HTML_OUTPUT in Doxyfile
36+
FOLDER: html # The folder the action should deploy. Specified by HTML_OUTPUT in Doxyfile
3737
TARGET_FOLDER: docs

.github/workflows/linux-build.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ on:
1111
jobs:
1212
build:
1313
name: ${{matrix.pkg_name}}, C++${{matrix.std}}, ${{matrix.build_type}} build
14-
runs-on: ubuntu-20.04
14+
runs-on: ubuntu-latest
15+
timeout-minutes: 30
1516
strategy:
1617
matrix:
1718
pkg_name:

.github/workflows/macos-build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
name: ${{matrix.compiler}} ${{matrix.build_type}}
1717
# The type of runner that the job will run on
1818
runs-on: macos-latest
19+
timeout-minutes: 30
1920
# A matrix allows you to create multiple jobs by performing variable substitution
2021
# in a single job definition
2122
strategy:

CMakeLists.txt

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,58 @@
1-
cmake_minimum_required(VERSION 3.8)
2-
project(iris CXX)
1+
cmake_minimum_required(VERSION 3.12)
2+
project(StrTpl
3+
VERSION 0.1.0
4+
LANGUAGES CXX
5+
)
6+
include(GNUInstallDirs)
37

4-
# Specify build type if not
8+
# Creates a library StrTpl which is an interface (header files only)
9+
add_library(StrTpl INTERFACE)
10+
# If you want to use StrTpl prefer to link against StrTpl using this alias target
11+
add_library(StrTpl::StrTpl ALIAS StrTpl)
12+
13+
# Specify build type ifnot
514
if(NOT CMAKE_BUILD_TYPE)
615
set(CMAKE_BUILD_TYPE "Release")
716
message(STATUS "CMAKE_BUILD_TYPE not specified: Use Release by default.")
817
endif(NOT CMAKE_BUILD_TYPE)
918

1019
# Determine whether this is a standalone project or included by other projects
11-
set(IRIS_STANDALONE_PROJECT OFF)
12-
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
13-
set(IRIS_STANDALONE_PROJECT ON)
20+
set(STRTPL_STANDALONE_PROJECT OFF)
21+
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
22+
set(STRTPL_STANDALONE_PROJECT ON)
1423
endif()
1524

1625
# Project options
17-
option(IRIS_TEST "Build and perform iris tests" ${IRIS_STANDALONE_PROJECT})
26+
option(STRTPL_INSTALL "Generate and install StrTpl target" ${STRTPL_STANDALONE_PROJECT})
27+
option(STRTPL_TEST "Build and perform StrTpl tests" ${STRTPL_STANDALONE_PROJECT})
1828

1929
# Setup include directory
2030
add_subdirectory(include)
2131

22-
# Setup test directory
23-
if (IRIS_TEST)
32+
if(STRTPL_INSTALL)
33+
install(
34+
TARGETS StrTpl
35+
EXPORT StrTplConfig
36+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
37+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
38+
# RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
39+
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
40+
)
41+
install(
42+
DIRECTORY include/strtpl
43+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
44+
)
45+
# Make library importable by other projects
46+
install(
47+
EXPORT StrTplConfig
48+
NAMESPACE StrTpl::
49+
FILE StrTplConfig.cmake
50+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/StrTpl
51+
# EXPORT_LINK_INTERFACE_LIBRARIES
52+
)
53+
endif()
54+
55+
if(STRTPL_TEST)
2456
include(CTest)
2557
add_subdirectory(tests)
2658
endif()

README.md

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,47 @@
11
# String Template in C++
22
[![Linux build status](https://github.com/acd1034/cpp-string-template/actions/workflows/linux-build.yml/badge.svg)](https://github.com/acd1034/cpp-string-template/actions/workflows/linux-build.yml)
3-
<!--
4-
[![macOS build status](https://github.com/acd1034/cpp-string-template/actions/workflows/macos-build.yml/badge.svg)](https://github.com/acd1034/cpp-string-template/actions/workflows/macos-build.yml)
5-
-->
63

7-
Click [here](https://acd1034.github.io/cpp-string-template/index.html) to see the HTML documentation generated by Doxygen.
4+
## Quick example
5+
```cpp
6+
#include <iostream>
7+
#include <string_view>
8+
#include <unordered_map>
9+
#include <strtpl/string_template.hpp>
810

9-
## Noteworthy Features
11+
int main() {
12+
std::unordered_map<std::string_view, std::string_view> map{
13+
{"who", "Alice"},
14+
{"what", "bananas"},
15+
{"verb", "run"},
16+
};
17+
{ // '$' に続く単語を発見した場合、その単語を map の key として得られる値で置き換えます。
18+
std::cout << strtpl::substitute("$who likes $what.", map) << std::endl;
19+
// → Alice likes bananas.
20+
}
21+
{ // '$' と単語の後にアルファベットが続く場合は、単語を "{}" で囲みます。
22+
std::cout << strtpl::substitute("$who ${verb}s fast.", map) << std::endl;
23+
// → Alice runs fast.
24+
}
25+
// '$' に続く単語が map に含まれない場合、例外を送出します。
26+
try {
27+
std::cout << strtpl::substitute("$who likes $where.", map) << std::endl;
28+
} catch (const std::exception& e) {
29+
std::cout << e.what() << std::endl;
30+
// → strtpl::at: index out of range
31+
}
32+
// '$' に続く文字が無効な場合も、例外を送出します。エラーメッセージにはエラーが生じた文字の行番号と列番号を含みます。
33+
try {
34+
std::cout << strtpl::substitute("$who likes $.", map) << std::endl;
35+
} catch (const std::exception& e) {
36+
std::cout << e.what() << std::endl;
37+
// → Invalid placeholder in string: line 1, col 12
38+
}
39+
}
40+
```
1041

11-
## Supported Compilers
12-
<!--
13-
The code will work on the following compilers:
14-
- GCC (latest)
15-
- Clang (latest)
16-
- Apple clang (version 11.0.0 or later)
17-
-->
18-
19-
## Library Dependencies
42+
## Note
43+
- [`include/strtpl/string_template.hpp`](https://github.com/acd1034/cpp-string-template/blob/main/include/strtpl/string_template.hpp)
44+
→ 文字列置換を行う関数 (`strtpl::substitute` および `wchar_t` に対応した `strtpl::wsubstitute`) が実装されています。
45+
- [`include/strtpl/regex.hpp`](https://github.com/acd1034/cpp-string-template/blob/main/include/strtpl/regex.hpp),
46+
[`include/strtpl/trailing_view.hpp`](https://github.com/acd1034/cpp-string-template/blob/main/include/strtpl/trailing_view.hpp)
47+
→ std の正規表現ライブラリを range のように扱うためのモジュールで、まだ試験実装です。

examples/quick_example.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include <iostream>
2+
#include <string_view>
3+
#include <unordered_map>
4+
#include <strtpl/string_template.hpp>
5+
6+
int main() {
7+
std::unordered_map<std::string_view, std::string_view> map{
8+
{"who", "Alice"},
9+
{"what", "bananas"},
10+
{"verb", "run"},
11+
};
12+
{ // '$' に続く単語を発見した場合、その単語を map の key として得られる値で置き換えます。
13+
std::cout << strtpl::substitute("$who likes $what.", map) << std::endl;
14+
// → Alice likes bananas.
15+
}
16+
{ // '$' と単語の後にアルファベットが続く場合は、単語を "{}" で囲みます。
17+
std::cout << strtpl::substitute("$who ${verb}s fast.", map) << std::endl;
18+
// → Alice runs fast.
19+
}
20+
// '$' に続く単語が map に含まれない場合、例外を送出します。
21+
try {
22+
std::cout << strtpl::substitute("$who likes $where.", map) << std::endl;
23+
} catch (const std::exception& e) {
24+
std::cout << e.what() << std::endl;
25+
// → strtpl::at: index out of range
26+
}
27+
// '$' に続く文字が無効な場合も、例外を送出します。エラーメッセージにはエラーが生じた文字の行番号と列番号を含みます。
28+
try {
29+
std::cout << strtpl::substitute("$who likes $.", map) << std::endl;
30+
} catch (const std::exception& e) {
31+
std::cout << e.what() << std::endl;
32+
// → Invalid placeholder in string: line 1, col 12
33+
}
34+
}

include/CMakeLists.txt

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,13 @@
1-
# Creates a library iris which is an interface (header files only)
2-
add_library(iris INTERFACE)
3-
# If you want to use iris prefer to link against iris using this alias target
4-
add_library(iris::iris ALIAS iris)
5-
# Set C++ version
6-
target_compile_features(iris INTERFACE cxx_std_20)
7-
set_target_properties(iris PROPERTIES
8-
CXX_STANDARD_REQUIRED ON
9-
CXX_EXTENSIONS OFF
10-
)
11-
121
# Add include folders to the library and targets that consume it the SYSTEM
132
# keyword suppresses warnings for users of the library
14-
if(IRIS_STANDALONE_PROJECT)
15-
target_include_directories(iris INTERFACE
3+
if(STRTPL_STANDALONE_PROJECT)
4+
target_include_directories(StrTpl INTERFACE
165
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
176
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
187
)
198
else()
20-
target_include_directories(iris SYSTEM INTERFACE
9+
target_include_directories(StrTpl SYSTEM INTERFACE
2110
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
2211
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
2312
)
2413
endif()
25-
26-
# Add (header only) external libraries
27-
# find_package(Boost 1.61.0 REQUIRED)
28-
# target_link_libraries(iris SYSTEM INTERFACE Boost::boost)

include/strtpl/string_template.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ namespace strtpl {
179179
at(Map& map, const Key& key) {
180180
auto i = map.find(key);
181181
using std::end;
182-
return i == end(map) ? throw std::out_of_range("strtpl::at") : get<1>(*i);
182+
return i == end(map) ? throw std::out_of_range("strtpl::at: index out of range") : get<1>(*i);
183183
}
184184

185185
template <class BiIter>

tests/CMakeLists.txt

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
1-
cmake_minimum_required(VERSION 3.8)
2-
project(iris_tests CXX)
1+
cmake_minimum_required(VERSION 3.12)
2+
project(StrTplTests
3+
LANGUAGES CXX
4+
)
35
include(CTest)
46

7+
# Import the globally installed StrTpl ifCMake has been started independently in
8+
# this directory with tests
9+
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
10+
find_package(StrTpl REQUIRED)
11+
endif()
12+
513
# This interface adds compile options to how the tests are run
6-
add_library(iris_tests_config INTERFACE)
7-
target_compile_options(iris_tests_config INTERFACE
14+
add_library(StrTplTestsConfig INTERFACE)
15+
target_compile_features(StrTplTestsConfig INTERFACE cxx_std_20)
16+
set_target_properties(StrTplTestsConfig PROPERTIES
17+
CXX_STANDARD_REQUIRED ON
18+
CXX_EXTENSIONS OFF
19+
)
20+
target_compile_options(StrTplTestsConfig INTERFACE
821
-fno-strict-aliasing
922
-Wall
1023
-Wcast-align
@@ -31,12 +44,12 @@ target_compile_options(iris_tests_config INTERFACE
3144
>
3245
# $<$<CXX_COMPILER_ID:Clang>:
3346
# $<$<AND:$<VERSION_GREATER:$<CXX_COMPILER_VERSION>,4.99>,$<VERSION_LESS:$<CXX_COMPILER_VERSION>,6>>:
34-
# $<$<EQUAL:${IRIS_CXX_STANDARD},17>:-Wno-undefined-func-template>
47+
# $<$<EQUAL:${STRTPL_CXX_STANDARD},17>:-Wno-undefined-func-template>
3548
# >
3649
# >
3750
# $<$<CXX_COMPILER_ID:AppleClang>:
3851
# $<$<AND:$<VERSION_GREATER:$<CXX_COMPILER_VERSION>,9.1>,$<VERSION_LESS:$<CXX_COMPILER_VERSION>,10>>:
39-
# $<$<EQUAL:${IRIS_CXX_STANDARD},17>:-Wno-undefined-func-template>
52+
# $<$<EQUAL:${STRTPL_CXX_STANDARD},17>:-Wno-undefined-func-template>
4053
# >
4154
# >
4255
$<$<CXX_COMPILER_ID:GNU>:
@@ -53,21 +66,12 @@ target_compile_options(iris_tests_config INTERFACE
5366
>
5467
)
5568

56-
# Import the globally installed iris if CMake has been started independently in
57-
# this directory with tests
58-
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
59-
find_package(iris::iris REQUIRED)
60-
endif()
61-
62-
# Use Catch2 as a unit testing framework
63-
# find_package(Catch2)
64-
6569
Include(FetchContent)
6670
FetchContent_Declare(Catch2
6771
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
68-
GIT_TAG v2.13.6)
72+
GIT_TAG v3.0.1)
6973
FetchContent_MakeAvailable(Catch2)
7074

71-
add_subdirectory(main)
7275
add_subdirectory(regex)
76+
add_subdirectory(string_template)
7377
add_subdirectory(trailing_view)

tests/regex/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.8)
1+
cmake_minimum_required(VERSION 3.12)
22
project(regex_tests CXX)
33

44
# ${CMAKE_PROJECT_NAME}: project name of the root CMakeLists.txt
@@ -8,9 +8,9 @@ add_executable(${PROJECT_NAME}
88
)
99

1010
target_link_libraries(${PROJECT_NAME} PRIVATE
11-
iris_tests_config
12-
iris::iris
13-
Catch2::Catch2
11+
StrTpl::StrTpl
12+
StrTplTestsConfig
13+
Catch2::Catch2WithMain
1414
)
1515

1616
add_test(${PROJECT_NAME} ${PROJECT_NAME})

0 commit comments

Comments
 (0)