Skip to content

Commit d2006a7

Browse files
Initial cmake setup
1 parent f8d7cbe commit d2006a7

7 files changed

Lines changed: 113 additions & 0 deletions

File tree

CMakeLists.txt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
cmake_minimum_required(VERSION 3.25)
2+
3+
project(cpuscope VERSION 0.1.0 LANGUAGES CXX)
4+
5+
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
6+
message(FATAL_ERROR "In-source builds are not allowed. Please use a separate build directory.")
7+
endif()
8+
9+
option(CI "Enable CI build mode and treat warnings as errors" OFF)
10+
option(ENABLE_MARCH_NATIVE "Enable -march=native optimization" OFF)
11+
12+
set(CMAKE_CXX_STANDARD 20)
13+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
14+
set(CMAKE_CXX_EXTENSIONS OFF)
15+
16+
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
17+
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
18+
endif()
19+
20+
if(CMAKE_CXX_COMPILER_ID MATCHES "^(GNU|Clang|AppleClang)$")
21+
add_compile_options(-Wall -Wextra -Wpedantic)
22+
if(CI)
23+
add_compile_options(-Werror)
24+
endif()
25+
if(ENABLE_MARCH_NATIVE)
26+
add_compile_options(-march=native)
27+
endif()
28+
endif()
29+
30+
if(NOT CMAKE_CXX_FLAGS MATCHES "-O[0-3s]")
31+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")
32+
endif()
33+
34+
find_package(Threads REQUIRED)
35+
find_package(LLVM QUIET)
36+
37+
add_subdirectory(src)
38+
add_subdirectory(tests)

src/CMakeLists.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
add_library(cpuscope_lib STATIC
2+
cpuscope_lib.cpp
3+
cpuscope_lib.hpp
4+
)
5+
6+
target_include_directories(cpuscope_lib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
7+
8+
target_link_libraries(cpuscope_lib PUBLIC Threads::Threads)
9+
10+
if(LLVM_FOUND)
11+
message(STATUS "Optional LLVM integration enabled: ${LLVM_PACKAGE_VERSION}")
12+
target_link_libraries(cpuscope_lib PUBLIC LLVM)
13+
else()
14+
message(STATUS "LLVM not found; continuing without optional LLVM support.")
15+
endif()
16+
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+
)

src/cpuscope_lib.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include "cpuscope_lib.hpp"
2+
3+
// Implementation is header-only for the initial placeholder functionality.

src/cpuscope_lib.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
inline std::string format_message(std::span<const std::string_view> args)
12+
{
13+
return std::format("CPUScope CLI placeholder: {} arguments received.", args.size());
14+
}
15+
16+
} // namespace cpuscope

src/main.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <string_view>
4+
5+
#include "cpuscope_lib.hpp"
6+
7+
int main(int argc, char* argv[])
8+
{
9+
std::vector<std::string_view> args;
10+
args.reserve(argc);
11+
for (int i = 0; i < argc; ++i) {
12+
args.emplace_back(argv[i]);
13+
}
14+
15+
std::cout << cpuscope::format_message(args) << '\n';
16+
return 0;
17+
}

tests/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
add_executable(cpuscope_tests test_main.cpp)
2+
3+
target_link_libraries(cpuscope_tests PRIVATE cpuscope_lib)
4+
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)

tests/test_main.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
int main()
2+
{
3+
// Placeholder test target. GoogleTest integration will be added in a future issue.
4+
return 0;
5+
}

0 commit comments

Comments
 (0)