From ad1241bd95e571fd92d4ad939148b0d903c2e843 Mon Sep 17 00:00:00 2001 From: Simon Cahill Date: Mon, 7 Sep 2020 16:16:08 +0200 Subject: [PATCH 1/3] Added missing include guards. Fixes a lot of compile issues. --- include/gzip/compress.hpp | 6 ++++++ include/gzip/decompress.hpp | 5 +++++ include/gzip/utils.hpp | 5 +++++ 3 files changed, 16 insertions(+) diff --git a/include/gzip/compress.hpp b/include/gzip/compress.hpp index 2ec56c2..b2eb15d 100644 --- a/include/gzip/compress.hpp +++ b/include/gzip/compress.hpp @@ -1,3 +1,7 @@ +#ifndef GZIP_HPP_INCLUDE_GZIP_COMPRESS_HPP +#define GZIP_HPP_INCLUDE_GZIP_COMPRESS_HPP + + #include // zlib @@ -111,3 +115,5 @@ inline std::string compress(const char* data, } } // namespace gzip + +#endif // GZIP_HPP_INCLUDE_GZIP_COMPRESS_HPP diff --git a/include/gzip/decompress.hpp b/include/gzip/decompress.hpp index b70670f..7963f5a 100644 --- a/include/gzip/decompress.hpp +++ b/include/gzip/decompress.hpp @@ -1,3 +1,6 @@ +#ifndef GZIP_HPP_INCLUDE_GZIP_DECOMPRESS_HPP +#define GZIP_HPP_INCLUDE_GZIP_DECOMPRESS_HPP + #include // zlib @@ -103,3 +106,5 @@ inline std::string decompress(const char* data, std::size_t size) } } // namespace gzip + +#endif // GZIP_HPP_INCLUDE_GZIP_DECOMPRESS_HPP diff --git a/include/gzip/utils.hpp b/include/gzip/utils.hpp index db123d1..7bc2161 100644 --- a/include/gzip/utils.hpp +++ b/include/gzip/utils.hpp @@ -1,3 +1,6 @@ +#ifndef GZIP_HPP_INCLUDE_GZIP_UTILS_HPP +#define GZIP_HPP_INCLUDE_GZIP_UTILS_HPP + #include namespace gzip { @@ -20,3 +23,5 @@ inline bool is_compressed(const char* data, std::size_t size) (static_cast(data[0]) == 0x1F && static_cast(data[1]) == 0x8B)); } } // namespace gzip + +#endif // GZIP_HPP_INCLUDE_GZIP_UTILS_HPP From b04fa06a9b17c57f2903717f6275c3e5c62849e4 Mon Sep 17 00:00:00 2001 From: SimonC Date: Tue, 4 Jul 2023 14:55:09 +0200 Subject: [PATCH 2/3] Update CMakeLists.txt Fixed the Makefile generator so it can actually be used in Cmake projects without ruining everything and building tests which I don't need. To use: ``` add_subdirectory(gzip-hpp) target_link_libraries( mybin gzip-hpp ) ``` --- CMakeLists.txt | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9280ae1..281759b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.8) -project(hpp_skel LANGUAGES CXX) +project(gzip-hpp LANGUAGES CXX) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED on) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) @@ -38,16 +38,21 @@ include_directories(SYSTEM ${MASON_PACKAGE_benchmark_INCLUDE_DIRS}) mason_use(zlib VERSION 1.2.8) include_directories(SYSTEM ${MASON_PACKAGE_zlib_INCLUDE_DIRS}) -include_directories("${PROJECT_SOURCE_DIR}/include") +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) -file(GLOB TEST_SOURCES test/*.cpp) -add_executable(unit-tests ${TEST_SOURCES}) +add_library(${PROJECT_NAME} INTERFACE) +target_include_directories(${PROJECT_NAME} INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include) -# libbenchmark.a supports threads and therefore needs pthread support -find_package(Threads REQUIRED) -file(GLOB BENCH_SOURCES bench/*.cpp) -add_executable(bench-tests ${BENCH_SOURCES}) +if (gzip_BUILD_TESTS) + file(GLOB TEST_SOURCES test/*.cpp) + add_executable(unit-tests ${TEST_SOURCES}) -# link zlib static library to the unit-tests binary so the tests know where to find the zlib impl code -target_link_libraries(unit-tests ${MASON_PACKAGE_zlib_STATIC_LIBS}) -target_link_libraries(bench-tests ${MASON_PACKAGE_benchmark_STATIC_LIBS} ${CMAKE_THREAD_LIBS_INIT} ${MASON_PACKAGE_zlib_STATIC_LIBS}) + # libbenchmark.a supports threads and therefore needs pthread support + find_package(Threads REQUIRED) + file(GLOB BENCH_SOURCES bench/*.cpp) + add_executable(bench-tests ${BENCH_SOURCES}) + + # link zlib static library to the unit-tests binary so the tests know where to find the zlib impl code + target_link_libraries(unit-tests ${MASON_PACKAGE_zlib_STATIC_LIBS}) + target_link_libraries(bench-tests ${MASON_PACKAGE_benchmark_STATIC_LIBS} ${CMAKE_THREAD_LIBS_INIT} ${MASON_PACKAGE_zlib_STATIC_LIBS}) +endif() From 1cf3be33ff2aca0ed31132b0511f21c9515e4382 Mon Sep 17 00:00:00 2001 From: SimonC Date: Wed, 26 Jul 2023 16:55:51 +0200 Subject: [PATCH 3/3] Update CMakeLists.txt --- CMakeLists.txt | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 281759b..392be5a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,22 +28,22 @@ if (WERROR) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror") endif() -# mason_use is a mason function within the mason.cmake file and provides ready-to-go vars, like "STATIC_LIBS" and "INCLUDE_DIRS" -mason_use(catch VERSION 1.9.6 HEADER_ONLY) -include_directories(SYSTEM ${MASON_PACKAGE_catch_INCLUDE_DIRS}) - -mason_use(benchmark VERSION 1.3.0) -include_directories(SYSTEM ${MASON_PACKAGE_benchmark_INCLUDE_DIRS}) - -mason_use(zlib VERSION 1.2.8) -include_directories(SYSTEM ${MASON_PACKAGE_zlib_INCLUDE_DIRS}) - include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) add_library(${PROJECT_NAME} INTERFACE) target_include_directories(${PROJECT_NAME} INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include) if (gzip_BUILD_TESTS) + # mason_use is a mason function within the mason.cmake file and provides ready-to-go vars, like "STATIC_LIBS" and "INCLUDE_DIRS" + mason_use(catch VERSION 1.9.6 HEADER_ONLY) + include_directories(SYSTEM ${MASON_PACKAGE_catch_INCLUDE_DIRS}) + + mason_use(benchmark VERSION 1.3.0) + include_directories(SYSTEM ${MASON_PACKAGE_benchmark_INCLUDE_DIRS}) + + mason_use(zlib VERSION 1.2.8) + include_directories(SYSTEM ${MASON_PACKAGE_zlib_INCLUDE_DIRS}) + file(GLOB TEST_SOURCES test/*.cpp) add_executable(unit-tests ${TEST_SOURCES})