Skip to content

Commit 318451e

Browse files
committed
Add version, expand example
1 parent 018b1f0 commit 318451e

File tree

5 files changed

+30
-6
lines changed

5 files changed

+30
-6
lines changed

CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ if("${CMAKE_BUILD_TYPE}" STREQUAL "")
1212
endif()
1313

1414
# build version
15-
set(build_version 0.2.0)
15+
set(build_version 0.3.0)
1616

1717
# project parameters
1818
set(project_name forest)
@@ -63,6 +63,9 @@ target_include_directories(${PROJECT_NAME} INTERFACE
6363
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>"
6464
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
6565
)
66+
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" FILES include/forest/forest.hpp)
67+
68+
configure_file(cmake/forest_version.hpp.in "${CMAKE_CURRENT_BINARY_DIR}/include/forest/forest_version.hpp" @ONLY)
6669

6770
# examples
6871
if(FOREST_BUILD_EXAMPLE)

cmake/forest_version.hpp.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include <string_view>
2+
3+
namespace forest {
4+
inline constexpr std::string_view version_v = "@PROJECT_VERSION@";
5+
}

example/CMakeLists.txt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1-
add_executable(forest-example)
2-
target_link_libraries(forest-example PRIVATE forest::forest)
3-
target_sources(forest-example PRIVATE forest-example.cpp)
1+
cmake_minimum_required(VERSION 3.17 FATAL_ERROR)
2+
3+
project(forest-example)
4+
5+
if(NOT TARGET forest)
6+
find_package(forest REQUIRED CONFIG)
7+
endif()
8+
9+
add_executable(${PROJECT_NAME})
10+
target_link_libraries(${PROJECT_NAME} PRIVATE forest::forest)
11+
target_sources(${PROJECT_NAME} PRIVATE forest-example.cpp)
12+
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" FILES forest-example.cpp)
413

514
if(CMAKE_CXX_COMPILER_ID MATCHES "^Clang$" OR CMAKE_CXX_COMPILER_ID MATCHES "^GNU$")
6-
target_compile_options(forest-example PRIVATE -Wall -Wextra -Wpedantic)
15+
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Wpedantic)
716
endif()

example/forest-example.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@ constexpr auto foo = forest::literal<64>("<rgb=500><b><i>hello</b></i></rgb> wor
55

66
int main() {
77
std::cout << foo << '\n';
8-
forest::print("<invert>forest</invert>\n");
8+
auto str = std::string("<invert>forest</invert> <dim>v");
9+
str += forest::version_v;
10+
str += "</dim>\n";
11+
forest::print(str);
912
}

include/forest/forest.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
#include <iterator>
77
#include <string>
88

9+
#if __has_include(<forest/forest_version.hpp>)
10+
#include <forest/forest_version.hpp>
11+
#endif
12+
913
namespace forest {
1014
///
1115
/// \brief Interpolate escape sequences through text and write characters to out

0 commit comments

Comments
 (0)