Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ruslo/leathers
:rocket: Warning suppression library (C++)
https://github.com/ruslo/leathers
Last synced: about 2 months ago
JSON representation
:rocket: Warning suppression library (C++)
- Host: GitHub
- URL: https://github.com/ruslo/leathers
- Owner: ruslo
- License: bsd-2-clause
- Created: 2014-04-15T18:43:59.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2020-03-08T09:00:42.000Z (almost 5 years ago)
- Last Synced: 2023-03-23T05:33:44.232Z (almost 2 years ago)
- Language: CMake
- Homepage: http://goo.gl/JKqObJ
- Size: 138 KB
- Stars: 79
- Watchers: 10
- Forks: 8
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
leathers
========This C++ header only library helps to save some space while ignoring
compiler warnings by pragma pop/push mechanism.### Example
Some mix-compiler code:```cpp
#if defined(BOOST_MSVC)
# pragma warning(push)
# pragma warning(disable : 4511 4512)
#elif defined(BOOST_CLANG)
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wexit-time-destructors"
#endif
// some code
#if defined(BOOST_MSVC)
# pragma warning(pop)
#elif defined(BOOST_CLANG)
# pragma clang diagnostic pop
#endif
```12 lines of code for 2 compilers to ignore warning in 1 line.
Using this library:
```cpp
#include
#include
// some code
#include
```3 lines of code for **any** number of compilers to ignore warning in 1 line.
### Example (all)
Suppressing warnings in third party libraries:
```cpp
#include
#include
# include
# include
#include
```### Usage (manual install)
* Install `boost` (`predef` library)
* Add `Source` directory to compiler include option: `-I${LEATHERS_ROOT}/Source`
```bash
> cat foo.cpp
#include // std::printfint main() {
const char* fmt = "%d";#include
#include
std::printf(fmt, 1);
#include
}
> clang++ -I${BOOST_ROOT}/include -I${LEATHERS_ROOT}/Source -Weverything foo.cpp
```### Usage (CMake, hunter package manager)
`Leathers` can be installed using [hunter](https://github.com/ruslo/hunter) package manager:
```bash
> cat CMakeLists.txt
cmake_minimum_required(VERSION 3.0)
project(Foo)include(HunterGate.cmake)
hunter_add_package(Leathers)find_package(Leathers CONFIG REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Weverything -Werror")
add_executable(foo foo.cpp)
target_link_libraries(foo leathers)
> cat foo.cpp
#include // std::printfint main() {
const char* fmt = "%d";#include
#include
std::printf(fmt, 1);
#include
}
> cmake -H. -B_builds -DHUNTER_STATUS_DEBUG=ON
> cmake --build _builds
```*Note* that boost installed automatically
### CMake (companion function to generate warning flags)
[This][2] function can be used to generate cross-platform target flags and properties:
```bash
> cat CMakeLists.txt
cmake_minimum_required(VERSION 3.0)
project(Foo)include(HunterGate.cmake)
hunter_add_package(Leathers)
hunter_add_package(Sugar)find_package(Leathers CONFIG REQUIRED)
include(${SUGAR_ROOT}/cmake/Sugar)
include(sugar_generate_warning_flags)sugar_generate_warning_flags(
flags properties ENABLE ALL TREAT_AS_ERROR ALL CLEAR_GLOBAL
)add_executable(foo foo.cpp)
target_link_libraries(foo leathers)set_target_properties(
foo PROPERTIES ${properties} COMPILE_OPTIONS "${flags}"
)
> cat foo.cpp
#include // std::printfint main() {
const char* fmt = "%d";#include
#include
std::printf(fmt, 1);
#include
}
> cmake -H. -B_builds -DHUNTER_STATUS_DEBUG=ON
> cmake --build _builds
```### Wiki
* [warnings list](https://github.com/ruslo/leathers/wiki/List)
* [pitfalls](https://github.com/ruslo/leathers/wiki/Pitfalls)[1]: https://github.com/ruslo/sugar/wiki/Cross-platform-warning-suppression
[2]: https://github.com/ruslo/sugar/tree/master/cmake/core#sugar_generate_warning_flags