Skip to content

Commit 1828e0c

Browse files
authored
Merge pull request #2 from cpp-gamedev/lib
Convert pini to a library
2 parents 9e1bfe8 + fe9494b commit 1828e0c

File tree

8 files changed

+58
-26
lines changed

8 files changed

+58
-26
lines changed

.editorconfig

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[*]
2+
insert_final_newline = true
3+
charset = utf-8
4+
indent_size = 4
5+
indent_style = tab
6+
# Optional: git will commit as lf, this will only affect local files
7+
end_of_line = lf
8+
9+
[*.{py,md,yml,sh,cmake}]
10+
indent_style = space
11+
indent_size = 2
12+
13+
[*.{py,md,yml,sh}.in]
14+
indent_style = space
15+
indent_size = 2
16+
17+
[CMakeLists.txt]
18+
indent_style = space
19+
indent_size = 2

CMakeLists.txt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
cmake_minimum_required(VERSION 3.19)
22

33
project(pini)
4-
add_executable(${PROJECT_NAME} src/main.cpp
5-
src/util.cpp
6-
src/pini.cpp)
4+
add_library(${PROJECT_NAME} src/util.cpp
5+
src/util.hpp
6+
src/pini.cpp
7+
include/pini/pini.hpp)
8+
add_library(pini::pini ALIAS pini)
9+
target_include_directories(${PROJECT_NAME} PRIVATE src PUBLIC include)
710
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Werror=return-type)
811
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
912

13+
option(PINI_BUILD_TESTS "Build tests" ON)
14+
15+
if(PINI_BUILD_TESTS)
16+
enable_testing()
17+
add_subdirectory(test)
18+
endif()
19+
1020
set(CCJSON "${CMAKE_CURRENT_BINARY_DIR}/compile_commands.json")
1121
if(EXISTS "${CCJSON}")
1222
message(STATUS "Copying ${CCJSON} to project root")
1323
file(COPY "${CCJSON}" DESTINATION "${PROJECT_SOURCE_DIR}")
14-
endif()
24+
endif()

src/pini.hpp renamed to include/pini/pini.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include <string_view>
77
#include <unordered_map>
88
#include <vector>
9-
#include "util.hpp"
109

1110
namespace pn {
1211
class pini {

src/main.cpp

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/pini.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
#include "pini.hpp"
21
#include <cstddef>
32
#include <cstdint>
43
#include <sstream>
54
#include <string_view>
65
#include <vector>
7-
#include "util.hpp"
6+
#include <pini/pini.hpp>
7+
#include <util.hpp>
8+
89

910
namespace pn {
1011
namespace {

src/util.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#include "util.hpp"
21
#include <cassert>
2+
#include <util.hpp>
33

44
namespace util {
55

test/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
cmake_minimum_required(VERSION 3.19)
2+
3+
project(pini-test)
4+
add_executable(${PROJECT_NAME} pini_test.cpp)
5+
target_link_libraries(${PROJECT_NAME} PRIVATE pini::pini)
6+
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Werror=return-type)
7+
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
8+
9+
add_test(pini-test pini-test)

test/pini_test.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <ios>
2+
#include <iostream>
3+
#include <pini/pini.hpp>
4+
5+
int main() {
6+
pn::pini pin;
7+
8+
std::string_view raw_input{"a=5\nb=10\n23=c"};
9+
// std::filesystem::path filename{"/test/test.ini"};
10+
if (!pin.load_text(raw_input)) { return 1; }
11+
if (pin.get_int32("a") != 5) { return 1; }
12+
}

0 commit comments

Comments
 (0)