Skip to content

Commit

Permalink
Add WERROR option, fix some build errors & warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
multiplemonomials committed Oct 14, 2023
1 parent 2160d39 commit c6a1437
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 16 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/compile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
run: |
mkdir build
cd build
cmake .. -DCMAKE_PREFIX_PATH=C:\vcpkg\installed\x64-windows
cmake .. -DUSE_WERROR=TRUE -DCMAKE_PREFIX_PATH=C:\vcpkg\installed\x64-windows
cmake --build .
build-windows-mingw:
Expand All @@ -26,15 +26,15 @@ jobs:
with:
submodules: true
- name: Install libusb and ucrt64 GCC compiler
shell: msys2bash.cmd
shell: C:\shells\msys2bash.cmd
run: |
pacman -S mingw-w64-ucrt-x86_64-libusb mingw-w64-ucrt-x86_64-gcc ninja
- name: Compile project
shell: msys2bash.cmd
run: |
mkdir build
cd build
cmake .. -GNinja -DCMAKE_C_COMPILER=mingw-w64-ucrt-x86_64-gcc -DCMAKE_CXX_COMPILER=mingw-w64-ucrt-x86_64-g++
cmake .. -GNinja -DUSE_WERROR=TRUE -DCMAKE_C_COMPILER=mingw-w64-ucrt-x86_64-gcc -DCMAKE_CXX_COMPILER=mingw-w64-ucrt-x86_64-g++
ninja
build-mac:
Expand All @@ -51,7 +51,7 @@ jobs:
run: |
mkdir build
cd build
cmake .. -GNinja
cmake .. -GNinja -DUSE_WERROR=TRUE
ninja
build-ubuntu:
Expand All @@ -69,5 +69,5 @@ jobs:
run: |
mkdir build
cd build
cmake .. -GNinja
cmake .. -GNinja -DUSE_WERROR=TRUE
ninja
62 changes: 58 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,58 @@ if("${CMAKE_BUILD_TYPE}" STREQUAL "")
set(CMAKE_BUILD_TYPE RELEASE CACHE STRING "Type of build. Controls debugging information and optimizations." FORCE)
endif()

option(USE_WERROR "If set to true, convert compiler warnings into compiler errors. Mainly intended for CI." FALSE)

# compile flags
if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")

set(CMAKE_C_FLAGS_RELEASE "-O3")
set(CMAKE_C_FLAGS_DEBUG "-g3 -O0")
string(APPEND CMAKE_C_FLAGS " -Wall")
if(USE_WERROR)
string(APPEND CMAKE_C_FLAGS " -Werror")
endif()

elseif("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")

set(CMAKE_C_FLAGS_RELEASE "/O2 /MD")
set(CMAKE_C_FLAGS_DEBUG "/MDd /Zi /Ob0 /Od /RTC1")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W3") # Use reasonable warning flags

# Suppress warning about zero sized arrays used by libusb
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4200")

if(USE_WERROR)
string(APPEND CMAKE_C_FLAGS " /WX")
endif()

# disable verbose security warnings
add_definitions(-D_CRT_SECURE_NO_WARNINGS=1)

elseif(${CMAKE_C_COMPILER_ID} STREQUAL "Clang" OR ${CMAKE_C_COMPILER_ID} STREQUAL "AppleClang")

set(CMAKE_C_FLAGS_RELEASE "-O3")
set(CMAKE_C_FLAGS_DEBUG "-g3 -O0")
string(APPEND CMAKE_C_FLAGS " -Wall")

if(USE_WERROR)
string(APPEND CMAKE_CXX_FLAGS " -Werror")
endif()

else()

message(WARNING "Unknown compiler, don't know how to set CXXFLAGS")
endif()


if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")

set(CMAKE_CXX_FLAGS_RELEASE "-O3")
set(CMAKE_CXX_FLAGS_DEBUG "-g3 -O0")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
string(APPEND CMAKE_CXX_FLAGS " -Wall")
if(USE_WERROR)
string(APPEND CMAKE_CXX_FLAGS " -Werror")
endif()

elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")

Expand All @@ -28,20 +74,28 @@ elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
# Suppress warning about zero sized arrays used by libusb
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4200")

# disable verbose security warnings
add_definitions(-D_CRT_SECURE_NO_WARNINGS=1)
if(USE_WERROR)
string(APPEND CMAKE_CXX_FLAGS " /WX")
endif()

elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "AppleClang")

set(CMAKE_CXX_FLAGS_RELEASE "-O3")
set(CMAKE_CXX_FLAGS_DEBUG "-g3 -O0")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")

if(USE_WERROR)
string(APPEND CMAKE_CXX_FLAGS " -Werror")
endif()

else()

message(WARNING "Unknown compiler, don't know how to set CXXFLAGS")
endif()

# use C++17, with extensions
# use C99 and C++17, with extensions
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_EXTENSIONS TRUE)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_EXTENSIONS TRUE)

Expand Down
7 changes: 4 additions & 3 deletions src/ezusb.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>

#include "libusb.h"

Expand Down Expand Up @@ -60,7 +61,7 @@ void logerror(const char *format, ...)
* The Cypress FX parts are largely compatible with the Anchorhip ones.
*/

bool verbose;
int verbose;

/*
* return true iff [addr,addr+len) includes external RAM
Expand Down Expand Up @@ -282,7 +283,7 @@ int parse_ihex (
const unsigned char *data, uint16_t len)
)
{
unsigned char data [1023];
uint8_t data [1023];
unsigned short data_addr = 0;
uint16_t data_len = 0;
int rc;
Expand Down Expand Up @@ -361,7 +362,7 @@ int parse_ihex (
}

if (type != 0) {
logerror("unsupported record type: %u\n", type);
logerror("unsupported record type: %lu\n", type);
return -3;
}

Expand Down
4 changes: 2 additions & 2 deletions src/ezusb.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ extern int ezusb_load_eeprom (
);


/* boolean flag, says whether to write extra messages to stderr */
extern bool verbose;
/* Verbosity level from 0 (least verbose) to 3 (most verbose) */
extern int verbose;


#define USB_DIR_OUT 0 /* to device */
Expand Down
6 changes: 4 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ libusb_device_handle *get_usb_device(struct device_spec *wanted) {
libusb_device_handle *dev_h = NULL;

libusb_init(NULL);
libusb_set_debug(NULL, 0);

// If in double-verbose mode or above, set libusb to debug log mode.
libusb_set_option(nullptr, LIBUSB_OPTION_LOG_LEVEL, verbose >= 2 ? LIBUSB_LOG_LEVEL_DEBUG : LIBUSB_LOG_LEVEL_WARNING);

libusb_device *found = NULL;
int nr_found = 0;
Expand Down Expand Up @@ -248,7 +250,7 @@ int main(int argc, char*argv[])
std::string stage1_loader = app_install_dir + AppPaths::PATH_SEP + ".." + AppPaths::PATH_SEP + "share" + AppPaths::PATH_SEP + "fxload" + AppPaths::PATH_SEP + "Vend_Ax.hex";

// List of CLI options
app.add_flag("-v,--verbose", verbose, "show verbose message");
app.add_flag("-v,--verbose", verbose, "Verbose mode. May be supplied up to 3 times for more verbosity."); // note: CLI11 will count the occurrences of a flag when you pass an integer variable to add_flag()
app.add_option("-I,--ihex-path", ihex_path, "Hex file to program")
->required()
->check(CLI::ExistingFile);
Expand Down

0 comments on commit c6a1437

Please sign in to comment.