-
Notifications
You must be signed in to change notification settings - Fork 13
/
CMakeLists.txt
151 lines (134 loc) · 4.77 KB
/
CMakeLists.txt
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
cmake_minimum_required(VERSION 3.13)
project(bxzstr)
## For FindZstd
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
if(DEFINED ZLIB_FOUND)
if(ZLIB_FOUND)
set(BXZSTR_Z_SUPPORT 1)
else()
set(BXZSTR_Z_SUPPORT 0)
endif()
else()
# -- locate zlib
find_package(ZLIB) # defines imported target ZLIB::ZLIB
if(ZLIB_FOUND)
message(STATUS "bxzstr - found libz (version: ${ZLIB_VERSION_STRING})")
set(BXZSTR_Z_SUPPORT 1)
else()
set(BXZSTR_Z_SUPPORT 0)
endif()
endif()
if(DEFINED BZIP2_FOUND)
if(BZIP2_FOUND)
set(BXZSTR_BZ2_SUPPORT 1)
else()
set(BXZSTR_BZ2_SUPPORT 0)
endif()
else()
find_package(BZip2)
if(BZIP2_FOUND)
message(STATUS "bxzstr - found libbz2 (version: ${BZIP2_VERSION_STRING})")
set(BXZSTR_BZ2_SUPPORT 1)
else()
set(BXZSTR_BZ2_SUPPORT 0)
endif()
endif()
if(DEFINED LIBLZMA_FOUND)
if(LIBLZMA_FOUND)
set(BXZSTR_LZMA_SUPPORT 1)
else()
set(BXZSTR_LZMA_SUPPORT 0)
endif()
else()
find_package(LibLZMA)
if(LIBLZMA_FOUND)
message(STATUS "bxzstr - found liblzma (version: ${LIBLZMA_VERSION_STRING})")
set(BXZSTR_LZMA_SUPPORT 1)
else()
set(BXZSTR_LZMA_SUPPORT 0)
endif()
endif()
if(DEFINED ZSTD_FOUND)
if(ZSTD_FOUND)
set(BXZSTR_ZSTD_SUPPORT 1)
else()
set(BXZSTR_ZSTD_SUPPORT 0)
endif()
else()
find_package(Zstd)
if(ZSTD_FOUND)
message(STATUS "bxzstr - found libzstd (version: ${ZSTD_VERSION_STRING})")
set(BXZSTR_ZSTD_SUPPORT 1)
else()
set(BXZSTR_ZSTD_SUPPORT 0)
endif()
endif()
configure_file(include/config.hpp.in ${CMAKE_CURRENT_SOURCE_DIR}/include/config.hpp @ONLY)
if(CMAKE_BUILD_TYPE MATCHES Debug)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -Wextra -Wpedantic")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -g -Wall -Wextra -Wpedantic")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -g -Wall -Wextra -Wpedantic")
endif()
if (CMAKE_VERSION VERSION_LESS "3.1")
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
endif ()
else ()
set (CMAKE_CXX_STANDARD 11)
endif ()
# -- add target
add_library(bxzstr INTERFACE)
add_library(bxzstr::bxzstr ALIAS bxzstr)
# -- set target properties
target_include_directories(bxzstr INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include")
target_link_libraries(bxzstr INTERFACE ZLIB::ZLIB BZip2::BZip2 LibLZMA::LibLZMA Zstd::Zstd)
target_compile_features(bxzstr INTERFACE cxx_std_11) # require c++11 flag
## Download googletest if building tests
if(CMAKE_BUILD_TESTS)
if (DEFINED CMAKE_GOOGLETEST_HEADERS)
message(STATUS "googletest headers provided in: ${CMAKE_GOOGLETEST_HEADERS}")
else()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists-googletest.txt.in ${CMAKE_CURRENT_BINARY_DIR}/external/googletest-download/CMakeLists.txt)
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/external/googletest-download )
if(result)
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/external/googletest-download )
if(result)
message(FATAL_ERROR "Build step for googletest failed: ${result}")
endif()
set(CMAKE_GOOGLETEST_HEADERS ${CMAKE_CURRENT_BINARY_DIR}/external/googletest/googletest/include)
add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/external/googletest
${CMAKE_CURRENT_BINARY_DIR}/external/googletest/build)
endif()
set_target_properties(gmock PROPERTIES EXCLUDE_FROM_ALL 1)
set_target_properties(gmock_main PROPERTIES EXCLUDE_FROM_ALL 1)
include_directories("${CMAKE_GOOGLETEST_HEADERS}")
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/test/include ${CMAKE_CURRENT_SOURCE_DIR}/include)
enable_testing()
add_executable(runTests
${CMAKE_CURRENT_SOURCE_DIR}/test/src/compression_types_unittest.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/src/z_stream_wrapper_unittest.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/src/bz_stream_wrapper_unittest.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/src/lzma_stream_wrapper_unittest.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/src/zstd_stream_wrapper_unittest.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/src/bxzstr_ofstream_integrationtest.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/src/bxzstr_ifstream_integrationtest.cpp)
add_test(runTests runTests)
if(DEFINED ZLIB_FOUND)
target_link_libraries(runTests gtest gtest_main z)
endif()
if(DEFINED BZIP2_FOUND)
target_link_libraries(runTests gtest gtest_main bz2)
endif()
if(DEFINED LIBLZMA_FOUND)
target_link_libraries(runTests gtest gtest_main lzma)
endif()
if(DEFINED ZSTD_FOUND)
target_link_libraries(runTests gtest gtest_main zstd)
endif()
endif()