Skip to content

Commit

Permalink
Making it a header-only library
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaweees committed Nov 23, 2024
1 parent 7053309 commit 6791d4a
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 31 deletions.
13 changes: 12 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,18 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Library target
add_subdirectory(src)
add_library(
${PROJECT_NAME}
INTERFACE
)

target_include_directories(
${PROJECT_NAME}
INTERFACE
"$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include>"
)


# Optional builds
option(BUILD_EXAMPLES "Build examples" ON)
Expand Down
8 changes: 4 additions & 4 deletions examples/example1.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include <iostream>

#include "kiwicpp/library.hpp"
#include <kiwicpp/kiwicpp.hpp>
using namespace kiwicpp;

int main() {
std::cout << "Sum: " << KiwiCPP::add(2, 3) << std::endl;
std::cout << "Sum: " << add(2, 3) << std::endl;
return 0;
}
}
3 changes: 3 additions & 0 deletions include/kiwicpp/kiwicpp.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

#include <kiwicpp/math.hpp>
5 changes: 0 additions & 5 deletions include/kiwicpp/library.hpp

This file was deleted.

5 changes: 5 additions & 0 deletions include/kiwicpp/math.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

namespace kiwicpp {
inline int add(int a, int b) { return a + b; }
} // namespace kiwicpp
11 changes: 0 additions & 11 deletions src/CMakeLists.txt

This file was deleted.

5 changes: 0 additions & 5 deletions src/library.cpp

This file was deleted.

11 changes: 6 additions & 5 deletions tests/test_library.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#include <gtest/gtest.h>

#include "../include/kiwicpp/library.hpp"
#include <kiwicpp/kiwicpp.hpp>
using namespace kiwicpp;

TEST(LibraryTest, Add) {
// Consider adding more test cases
EXPECT_EQ(KiwiCPP::add(2, 3), 5);
EXPECT_EQ(KiwiCPP::add(-1, 1), 0);
EXPECT_EQ(KiwiCPP::add(0, 0), 0);
EXPECT_EQ(KiwiCPP::add(-2, -3), -5);
EXPECT_EQ(add(2, 3), 5);
EXPECT_EQ(add(-1, 1), 0);
EXPECT_EQ(add(0, 0), 0);
EXPECT_EQ(add(-2, -3), -5);
}

0 comments on commit 6791d4a

Please sign in to comment.