diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..796b96d1 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/build diff --git a/CMakeLists.txt b/CMakeLists.txt index b237e397..1efc98fc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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}") @@ -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() @@ -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() @@ -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() diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 02605de5..7d43ed2d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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) diff --git a/README.md b/README.md index 15c9ddee..5adc2a9b 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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): @@ -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. @@ -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 diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt index 133fb3e6..81cff615 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -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() #----------------------------------------------------------------------------- diff --git a/doc/advanced.md b/doc/advanced.md index d579538d..60089dba 100644 --- a/doc/advanced.md +++ b/doc/advanced.md @@ -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 diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 3dbd96d1..b9a8c2da 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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)