From 141cc0b866446c384805dcd2f3fe3a513277c5f8 Mon Sep 17 00:00:00 2001 From: gitlost Date: Mon, 19 Jul 2021 15:58:44 +0100 Subject: [PATCH] cmake min 3.9 -> 3.13 so LINK_LIBRARIES available in try_compile() cmake: hardcode -fsanitize=address for MSVC 2019 cmake: non-MSVC simplify setting sanitize address, undefined test_code128: test_hibc_input: extra tests --- CMakeLists.txt | 43 ++++++++++++++++++++--------------- backend/CMakeLists.txt | 9 -------- backend/tests/CMakeLists.txt | 2 +- backend/tests/test_code128.c | 5 ++++ frontend/tests/CMakeLists.txt | 2 +- 5 files changed, 32 insertions(+), 29 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c00de9ba..2a237e90 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ # Copyright (C) 2009-2021 Robin Stuart # vim: set ts=4 sw=4 et : -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.13) project(zint-package) set(CMAKE_INCLUDE_CURRENT_DIR ON) @@ -61,25 +61,32 @@ if(ZINT_TEST) enable_testing() endif() -set(SANITIZER_FLAGS "") if(ZINT_SANITIZE) - file(WRITE ${CMAKE_BINARY_DIR}/dummy.c "int main() { return 0; }") - set(SANITIZERS address leak undefined) #address hwaddress leak memory thread undefined - foreach(sanitizer IN ITEMS ${SANITIZERS}) - set(sanitizer_flag "-fsanitize=${sanitizer}") - try_compile(RESULT_VAR ${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}/dummy.c - COMPILE_DEFINITIONS ${sanitizer_flag} - LINK_OPTIONS ${sanitizer_flag} - ) - message(STATUS "Support for ${sanitizer_flag} available ... ${RESULT_VAR}") - if(RESULT_VAR) - set(SANITIZER_FLAGS ${SANITIZER_FLAGS} ${sanitizer_flag}) + if(MSVC) + if(MSVC_VERSION GREATER_EQUAL 1920) + add_compile_options(-fsanitize=address) + message(STATUS "ZINT_SANITIZE: setting -fsanitize=address for MSVC 2019") + else() + message(STATUS "ZINT_SANITIZE: ignoring for MSVC < 2019") + endif() + else() + file(WRITE ${CMAKE_BINARY_DIR}/dummy.c "int main() { return 0; }") + set(SANITIZERS address undefined) + foreach(sanitizer IN ITEMS ${SANITIZERS}) + set(sanitizer_flag "-fsanitize=${sanitizer}") + try_compile(RESULT_VAR ${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}/dummy.c + COMPILE_DEFINITIONS ${sanitizer_flag} + LINK_LIBRARIES ${sanitizer_flag}) + message(STATUS "Support for ${sanitizer_flag} available ... ${RESULT_VAR}") + if(RESULT_VAR) + add_compile_options(${sanitizer_flag}) + link_libraries(${sanitizer_flag}) + endif() + endforeach() + if(NOT ZINT_DEBUG AND CMAKE_CXX_COMPILER_ID MATCHES "GNU") + # Gives warning on MainWindow::setupUI() and retries (& takes forever) if var-tracking-assignments enabled + add_compile_options(-fno-var-tracking-assignments) endif() - endforeach() - message(STATUS "Sanitizer flags: ${SANITIZER_FLAGS}") - if(NOT ZINT_DEBUG AND CMAKE_CXX_COMPILER_ID MATCHES "GNU") - # Gives warning on MainWindow::setupUI() and retries (& takes forever) if var-tracking-assignments enabled - add_compile_options(-fno-var-tracking-assignments) endif() endif() diff --git a/backend/CMakeLists.txt b/backend/CMakeLists.txt index 772b630d..c79eabea 100644 --- a/backend/CMakeLists.txt +++ b/backend/CMakeLists.txt @@ -19,15 +19,6 @@ if(ZINT_STATIC) add_library(zint-static STATIC ${zint_SRCS}) endif() -if(SANITIZER_FLAGS) - target_compile_options(zint PUBLIC ${SANITIZER_FLAGS}) - target_link_options(zint PUBLIC ${SANITIZER_FLAGS}) - if(ZINT_STATIC) - target_compile_options(zint-static PUBLIC ${SANITIZER_FLAGS}) - target_link_options(zint-static PUBLIC ${SANITIZER_FLAGS}) - endif() -endif() - function(zint_target_link_libraries library) target_link_libraries(zint ${library}) if(ZINT_STATIC) diff --git a/backend/tests/CMakeLists.txt b/backend/tests/CMakeLists.txt index 9fc91d25..c2043fda 100644 --- a/backend/tests/CMakeLists.txt +++ b/backend/tests/CMakeLists.txt @@ -3,7 +3,7 @@ # Copyright (C) 2006-2017 Kentaro Fukuchi # vim: set ts=4 sw=4 et : -cmake_minimum_required(VERSION 3.9) +cmake_minimum_required(VERSION 3.13) project(zint_backend_tests) enable_testing() diff --git a/backend/tests/test_code128.c b/backend/tests/test_code128.c index 275d665a..a3cc6301 100644 --- a/backend/tests/test_code128.c +++ b/backend/tests/test_code128.c @@ -454,6 +454,11 @@ static void test_hibc_input(int index, int generate, int debug) { struct item data[] = { /* 0*/ { ",", ZINT_ERROR_INVALID_DATA, -1, "Error 203: Invalid character in data (alphanumerics, space and \"-.$/+%\" only)", "" }, /* 1*/ { "A99912345/$$52001510X3", 0, 255, "(23) 104 11 33 99 99 91 23 45 100 15 4 4 99 52 0 15 10 100 56 19 19 53 106", "Check digit 3" }, + /* 2*/ { "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%", 0, 497, "(45) 104 11 99 1 23 45 67 89 100 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51", "Check digit +" }, + /* 3*/ { "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%", 0, 695, "(63) 104 11 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5", "Check digit Q" }, + /* 4*/ { "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%", ZINT_ERROR_TOO_LONG, -1, "Error 341: Input too long (60 symbol character maximum)", "" }, + /* 5*/ { "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", 0, 684, "(62) 104 11 99 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "Check digit %" }, + /* 6*/ { "09AZ-.19AZ-.29AZ-.39AZ-.49AZ-.59AZ-.69AZ-.79AZ-.89AZ-.99AZ", 0, 695, "(63) 104 11 16 25 33 58 13 14 17 25 33 58 13 14 18 25 33 58 13 14 19 25 33 58 13 14 20 25", "Check digit -" }, }; int data_size = ARRAY_SIZE(data); int i, length, ret; diff --git a/frontend/tests/CMakeLists.txt b/frontend/tests/CMakeLists.txt index e4e6fa85..27acf20e 100644 --- a/frontend/tests/CMakeLists.txt +++ b/frontend/tests/CMakeLists.txt @@ -3,7 +3,7 @@ # Copyright (C) 2006-2017 Kentaro Fukuchi # vim: set ts=4 sw=4 et : -cmake_minimum_required(VERSION 3.9) +cmake_minimum_required(VERSION 3.13) project(zint_frontend_tests) enable_testing()