Skip to content

Commit b8a085c

Browse files
Merge pull request #7 from codingwithmagga/feature/CWM/2-configure-googletest-framework
Integrate GoogleTest + restructure library/CLI layout
2 parents 7b19189 + 1a6e101 commit b8a085c

11 files changed

Lines changed: 87 additions & 42 deletions

File tree

CMakeLists.txt

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ endif()
88

99
option(CI "Enable CI build mode and treat warnings as errors" OFF)
1010
option(ENABLE_MARCH_NATIVE "Enable -march=native optimization" OFF)
11+
option(CPUSCOPE_BUILD_TESTS "Build tests" OFF)
1112

1213
set(CMAKE_CXX_STANDARD 20)
1314
set(CMAKE_CXX_STANDARD_REQUIRED ON)
@@ -34,5 +35,21 @@ endif()
3435
find_package(Threads REQUIRED)
3536
find_package(LLVM QUIET)
3637

37-
add_subdirectory(src)
38-
add_subdirectory(tests)
38+
if(CPUSCOPE_BUILD_TESTS)
39+
include(CTest)
40+
enable_testing()
41+
42+
include(FetchContent)
43+
FetchContent_Declare(
44+
googletest
45+
GIT_REPOSITORY https://github.com/google/googletest.git
46+
GIT_TAG v1.17.0
47+
)
48+
FetchContent_MakeAvailable(googletest)
49+
endif()
50+
51+
add_subdirectory(lib)
52+
add_subdirectory(cli)
53+
if(CPUSCOPE_BUILD_TESTS)
54+
add_subdirectory(tests)
55+
endif()

cli/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
add_executable(cpuscope_cli main.cpp)
2+
3+
target_link_libraries(cpuscope_cli PRIVATE cpuscope_lib)
4+
5+
set_target_properties(cpuscope_cli PROPERTIES
6+
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
7+
)

src/main.cpp renamed to cli/main.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44

55
#include "cpuscope_lib.hpp"
66

7-
int main(int argc, char* argv[])
7+
int main(int argc, char *argv[])
88
{
99
std::vector<std::string_view> args;
1010
args.reserve(argc);
11-
for (int i = 0; i < argc; ++i) {
11+
for (int i = 0; i < argc; ++i)
12+
{
1213
args.emplace_back(argv[i]);
1314
}
1415

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
add_library(cpuscope_lib STATIC
2-
cpuscope_lib.cpp
3-
cpuscope_lib.hpp
2+
src/cpuscope_lib.cpp
43
)
54

6-
target_include_directories(cpuscope_lib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
5+
target_include_directories(cpuscope_lib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
76

87
target_link_libraries(cpuscope_lib PUBLIC Threads::Threads)
98

@@ -14,12 +13,4 @@ else()
1413
message(STATUS "LLVM not found; continuing without optional LLVM support.")
1514
endif()
1615

17-
target_compile_features(cpuscope_lib PUBLIC cxx_std_20)
18-
19-
add_executable(cpuscope_cli main.cpp)
20-
21-
target_link_libraries(cpuscope_cli PRIVATE cpuscope_lib)
22-
23-
set_target_properties(cpuscope_cli PROPERTIES
24-
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
25-
)
16+
target_compile_features(cpuscope_lib PUBLIC cxx_std_20)

lib/include/cpuscope_lib.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#pragma once
2+
3+
#include <format>
4+
#include <span>
5+
#include <string>
6+
#include <string_view>
7+
#include <vector>
8+
9+
namespace cpuscope
10+
{
11+
12+
inline std::string format_message(std::span<const std::string_view> args)
13+
{
14+
return std::format("CPUScope CLI placeholder: {} arguments received.", args.size());
15+
}
16+
17+
} // namespace cpuscope

lib/include/version.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#pragma once
2+
3+
#include <string>
4+
5+
namespace cpuscope
6+
{
7+
8+
std::string get_version()
9+
{
10+
return "0.1.0";
11+
}
12+
13+
} // namespace cpuscope

lib/src/cpuscope_lib.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include "cpuscope_lib.hpp"
2+
3+
namespace cpuscope
4+
{
5+
6+
// Implementation is header-only for the initial placeholder functionality.
7+
8+
} // namespace cpuscope

src/cpuscope_lib.cpp

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

src/cpuscope_lib.hpp

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

tests/CMakeLists.txt

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
add_executable(cpuscope_tests test_main.cpp)
1+
add_executable(cpuscope_tests test_dummy.cpp)
22

3-
target_link_libraries(cpuscope_tests PRIVATE cpuscope_lib)
3+
target_link_libraries(cpuscope_tests PRIVATE gtest_main cpuscope_lib)
44

5-
set_target_properties(cpuscope_tests PROPERTIES
6-
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
7-
)
8-
9-
add_test(NAME cpuscope_tests COMMAND cpuscope_tests)
5+
include(GoogleTest)
6+
gtest_discover_tests(cpuscope_tests)

0 commit comments

Comments
 (0)