-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
111 lines (90 loc) · 3.21 KB
/
CMakeLists.txt
File metadata and controls
111 lines (90 loc) · 3.21 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
99
100
101
102
103
104
105
106
107
108
109
110
111
cmake_minimum_required(VERSION 3.15.0)
project(cc-compression-tool-cpp VERSION 0.1.0 LANGUAGES C CXX)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# ----------------------------- Find Packages -----------------------------
# 1. Boost (iostreams is compiled, others are headers)
find_package(Boost REQUIRED COMPONENTS iostreams CONFIG)
# 2. GMP (Search for headers and library)
find_path(GMP_INCLUDE_DIR NAMES gmp.h)
find_library(GMP_LIBRARY NAMES gmp)
if(NOT GMP_INCLUDE_DIR OR NOT GMP_LIBRARY)
message(FATAL_ERROR "GMP not found. Run 'brew install gmp' on macOS.")
endif()
# Create a "Formal" CMake Target for GMP (Cleaner than using variables)
add_library(GMP::GMP UNKNOWN IMPORTED)
set_target_properties(GMP::GMP PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${GMP_INCLUDE_DIR}"
IMPORTED_LOCATION "${GMP_LIBRARY}"
)
# ----------------------------- Main Executable -----------------------------
set(SRC_FILES
src/exceptions/exceptions.cpp
src/argument/arguments.cpp
src/file_handler/input_file.cpp
src/file_handler/output_file.cpp
src/file_handler/compressed_format.cpp
src/frequency_table/frequency_table.cpp
src/prefix_codes/prefix_codes.cpp
)
add_executable(${PROJECT_NAME} src/main.cpp ${SRC_FILES})
target_include_directories(${PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/src
)
# Link everything to the main app
target_link_libraries(${PROJECT_NAME} PRIVATE
Boost::iostreams
Boost::headers
GMP::GMP
)
# Crucial: Tell Boost to use GMP
target_compile_definitions(${PROJECT_NAME} PRIVATE BOOST_MULTIPRECISION_USE_GMP)
# ----------------------------- Testing -----------------------------
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/e9907112b47255d50b4d343e7e2160bce8dc85d1.zip
)
FetchContent_MakeAvailable(googletest)
enable_testing()
add_executable(cc_compression_tool_test
test/hello_test.cpp
test/arguments_test.cpp
test/file_handler_test.cpp
test/output_file_test.cpp
test/frequency_table_test.cpp
test/prefix_codes_test.cpp
test/read_header_test.cpp
test/decode_and_write_test.cpp
test/decompress_test.cpp
${SRC_FILES}
)
target_include_directories(cc_compression_tool_test PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/src
)
target_link_libraries(cc_compression_tool_test PRIVATE
GTest::gtest_main
Boost::iostreams
Boost::headers
GMP::GMP
)
# Tell Boost to use GMP in tests too
target_compile_definitions(cc_compression_tool_test PRIVATE BOOST_MULTIPRECISION_USE_GMP)
include(GoogleTest)
gtest_discover_tests(cc_compression_tool_test
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
# Round-trip test: encode sample/test.txt, decode, diff (files must match)
set(ROUNDTRIP_COMPRESSED "${CMAKE_BINARY_DIR}/roundtrip.compressed")
set(ROUNDTRIP_DECOMPRESSED "${CMAKE_BINARY_DIR}/roundtrip.txt")
add_test(NAME RoundTripEncodeDecode
COMMAND ${CMAKE_COMMAND}
-DEXE=$<TARGET_FILE:${PROJECT_NAME}>
-DINPUT=${CMAKE_SOURCE_DIR}/sample/test.txt
-DCOMPRESSED=${ROUNDTRIP_COMPRESSED}
-DDECOMPRESSED=${ROUNDTRIP_DECOMPRESSED}
-P ${CMAKE_SOURCE_DIR}/test/roundtrip_encode_decode.cmake
)