Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
26 changes: 22 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ endif()
#
#-----------------------------------------------------------------------------
message(STATUS "Looking for clang-tidy")
find_program(CLANG_TIDY NAMES clang-tidy-20 clang-tidy-19 clang-tidy-18 clang-tidy-17 clang-tidy-16 clang-tidy-15)
find_program(CLANG_TIDY NAMES clang-tidy-20 clang-tidy-19 clang-tidy-18 clang-tidy-17 clang-tidy-16 clang-tidy-15 clang-tidy)

if(CLANG_TIDY AND PROTOBUF_FOUND)
message(STATUS "Looking for clang-tidy - found ${CLANG_TIDY}")
Expand All @@ -93,6 +93,10 @@ if(CLANG_TIDY AND PROTOBUF_FOUND)
else()
message(STATUS "Looking for clang-tidy - not found")
message(STATUS " Build target 'clang-tidy' will not be available.")
add_custom_target(clang-tidy
COMMAND ${CMAKE_COMMAND} -E echo "ERROR: clang-tidy not found. Install it and re-run cmake."
COMMAND false
VERBATIM)
endif()


Expand All @@ -118,7 +122,10 @@ if(CPPCHECK)
)
else()
message(STATUS "Looking for cppcheck - not found")
message(STATUS " Build target 'cppcheck' will not be available.")
add_custom_target(cppcheck
COMMAND ${CMAKE_COMMAND} -E echo "ERROR: cppcheck not found. Install it and re-run cmake."
COMMAND false
VERBATIM)
endif()


Expand All @@ -128,16 +135,27 @@ endif()
#
#-----------------------------------------------------------------------------
message(STATUS "Looking for iwyu")
find_program(IWYU_TOOL NAMES iwyu_tool)
find_program(IWYU_TOOL NAMES iwyu_tool iwyu_tool.py)

if(IWYU_TOOL)
message(STATUS "Looking for iwyu - found")
set(IWYU_EXTRA_ARGS)
if(APPLE)
execute_process(COMMAND xcrun --show-sdk-path
OUTPUT_VARIABLE IWYU_SDK_PATH
OUTPUT_STRIP_TRAILING_WHITESPACE)
list(APPEND IWYU_EXTRA_ARGS -isysroot ${IWYU_SDK_PATH} -Wno-c2y-extensions)
endif()
add_custom_target(iwyu
${IWYU_TOOL} -p ${CMAKE_BINARY_DIR}
${IWYU_TOOL} -p ${CMAKE_BINARY_DIR} -- ${IWYU_EXTRA_ARGS}
)
else()
message(STATUS "Looking for iwyu - not found")
message(STATUS " Build target 'iwyu' will not be available.")
add_custom_target(iwyu
COMMAND ${CMAKE_COMMAND} -E echo "ERROR: iwyu not found. Install it and re-run cmake."
COMMAND false
VERBATIM)
endif()


Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
To release a new protozero version:

- Make sure all tests are passing locally and on Github Actions
- Make sure "make doc" builds
- Make sure `cmake --build build --target doc` builds
- Update version number in
- include/protozero/version.hpp (two places)
- CMakeLists.txt (one place)
Expand Down
26 changes: 16 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,10 @@ tell us about your system.

Extensive tests are included. Build them using CMake:

mkdir build
cd build
cmake ..
make
cmake -Bbuild
cmake --build build

Call `ctest` to run the tests.
Call `ctest -test-dir build` to run the tests.

The unit and reader tests are always build, the writer tests are only build if
the Google Protobuf library is found when running CMake.
Expand All @@ -88,9 +86,9 @@ See `test/README.md` for more details about the test.

To get a coverage report set `CXXFLAGS` and `LDFLAGS` before calling CMake:

CXXFLAGS="--coverage" LDFLAGS="--coverage" cmake ..
CXXFLAGS="--coverage" LDFLAGS="--coverage" cmake -Bbuild

Then call `make` as usual and run the tests using `ctest`.
Then call `cmake --build build` as usual and run the tests using `ctest -test-dir build`.

If you are using `g++` use `gcov` to generate a report (results are in `*.gcov`
files):
Expand All @@ -113,7 +111,7 @@ Open `coverage/index.html` in your browser to see the report.

After the CMake step, run

make clang-tidy
cmake --build build --target clang-tidy

to check the code with [clang-tidy](https://clang.llvm.org/extra/clang-tidy/).
You might have to set `CLANG_TIDY` in CMake config.
Expand All @@ -124,12 +122,20 @@ You might have to set `CLANG_TIDY` in CMake config.
For extra checks with [Cppcheck](https://cppcheck.sourceforge.io/) you can,
after the CMake step, call

make cppcheck
cmake --build build --target cppcheck


## Include What You Use

For checking `#include` hygiene with [include-what-you-use](https://include-what-you-use.org/)
you can, after the CMake step, call

cmake --build build --target iwyu


## Installation

After the CMake step, call `make install` to install the include files in
After the CMake step, call `cmake --build build --target install` to install the include files in
`/usr/local/include/protozero`.

If you are using CMake to build your own software, you can copy the file
Expand Down
4 changes: 4 additions & 0 deletions doc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ if(DOXYGEN_FOUND AND DOXYGEN_DOT_FOUND)
else()
message(STATUS "Looking for doxygen - not found")
message(STATUS " Disabled making of documentation.")
add_custom_target(doc
COMMAND ${CMAKE_COMMAND} -E echo "ERROR: doxygen (or graphviz/dot) not found. Install them and re-run cmake."
COMMAND false
VERBATIM)
endif()

#-----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion doc/advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ decode_zigzag32()
decode_zigzag64()
```

See the reference documentation created by `make doc` for details.
See the reference documentation created by `cmake --build build --target doc` for details.


## Vectored input for length-delimited fields
Expand Down
5 changes: 5 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ if(PROTOBUF_FOUND)
endif()
endforeach()

if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# Google Protobuf library adds non-standard _Nonnull to Abseil macros
set_source_files_properties(${PROTO_SRCS} PROPERTIES COMPILE_FLAGS "-Wno-nullability-extension")
endif()

add_executable(writer_tests writer_tests.cpp ${SOURCES} ${PROTO_SRCS} ${PROTO_HDRS})

target_compile_features(writer_tests PUBLIC cxx_std_14)
Expand Down
Loading