-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
98 lines (85 loc) · 2.85 KB
/
CMakeLists.txt
File metadata and controls
98 lines (85 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
cmake_minimum_required(VERSION 3.20)
project(ccwc
VERSION 1.0.0
DESCRIPTION "High-performance word count tool"
LANGUAGES CXX
)
# ===============================
# Compiler and Language Standards
# ===============================
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Always export compile_commands.json (for clangd / tooling)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# =============
# Sources
# =============
# Source files (.cpp)
set(SOURCES
src/main.cpp
src/algorithm/counter_state_machine.cpp
src/algorithm/universal_input_stream.cpp
src/argument_parser/argument_parser.cpp
src/output_formatter/output_formatter.cpp
)
# Header files (.hpp)
set(HEADERS
src/algorithm/counter.hpp
src/algorithm/counter_state_machine.hpp
src/algorithm/processor.hpp
src/algorithm/universal_input_stream.hpp
src/argument_parser/argument_parser.hpp
src/argument_parser/input_objects.hpp
src/output_formatter/output_formatter.hpp
)
add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS})
target_include_directories(${PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
)
# =================
# Compiler Warnings
# =================
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang|AppleClang|GNU")
target_compile_options(${PROJECT_NAME} PRIVATE
-Wall -Wextra -Wpedantic -Wshadow -Wconversion -Wsign-conversion
-Wold-style-cast -Woverloaded-virtual -Wnon-virtual-dtor
-Wnull-dereference -Wdouble-promotion -Wformat=2
)
elseif (MSVC)
target_compile_options(${PROJECT_NAME} PRIVATE /W4 /permissive- /EHsc)
endif()
# ======================
# Static Analysis (clang-tidy)
# ======================
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang|AppleClang")
find_program(CLANG_TIDY_EXE NAMES clang-tidy)
if (CLANG_TIDY_EXE)
message(STATUS "clang-tidy found: ${CLANG_TIDY_EXE}")
set(CLANG_TIDY_COMMAND
${CLANG_TIDY_EXE};
-p=${CMAKE_BINARY_DIR};
--warnings-as-errors=*;
--extra-arg-before=--driver-mode=g++
)
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}")
else()
message(WARNING "clang-tidy not found — static analysis disabled")
endif()
endif()
# ============
# Dependencies
# ============
find_package(Boost REQUIRED COMPONENTS iostreams locale CONFIG)
target_link_libraries(${PROJECT_NAME} PRIVATE Boost::iostreams Boost::locale)
# ============
# Installation
# ============
install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin)
# Install sample/test.txt next to the binary
# Only install test.txt if it exists
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/sample/test.txt")
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/sample/test.txt" DESTINATION bin)
else()
message(WARNING "sample/test.txt not found — skipping its installation")
endif()