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
This commit is contained in:
gitlost 2021-07-19 15:58:44 +01:00
parent ef6e1ca1e3
commit 141cc0b866
5 changed files with 32 additions and 29 deletions

View File

@ -2,7 +2,7 @@
# Copyright (C) 2009-2021 Robin Stuart <rstuart114@gmail.com>
# 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()

View File

@ -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)

View File

@ -3,7 +3,7 @@
# Copyright (C) 2006-2017 Kentaro Fukuchi <kentaro@fukuchi.org>
# 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()

View File

@ -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;

View File

@ -3,7 +3,7 @@
# Copyright (C) 2006-2017 Kentaro Fukuchi <kentaro@fukuchi.org>
# 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()