diff --git a/CMakeLists.txt b/CMakeLists.txt index c4af3492..4decf06b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ # Copyright (C) 2008 by BogDan Vatra < bogdan@licentia.eu > -# Copyright (C) 2009-2022 Robin Stuart +# Copyright (C) 2009-2023 Robin Stuart # vim: set ts=4 sw=4 et : cmake_minimum_required(VERSION 3.5) @@ -28,6 +28,10 @@ option(ZINT_USE_PNG "Build with PNG support" ON) option(ZINT_USE_QT "Build with Qt support" ON) option(ZINT_QT6 "If ZINT_USE_QT, use Qt6" OFF) +if(NOT ZINT_SHARED AND NOT ZINT_STATIC) + message(SEND_ERROR "Either ZINT_SHARED or ZINT_STATIC or both must be set") +endif() + include(SetPaths.cmake) include(CheckCXXCompilerFlag) diff --git a/ChangeLog b/ChangeLog index a59bab3c..39b15ec6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -15,6 +15,8 @@ Bugs ---- - CEPNET: fix no HRT (library: `has_hrt()`) - man page: fix Code 11 check digit info +- CMake: allow ctest to be run without having to install zint or manually set + LD_LIBRARY_PATH and PATH (ticket #279, props Alexey Dokuchaev) Version 2.12.0 (2022-12-12) diff --git a/backend/tests/README b/backend/tests/README index 51f62812..0d9bd54d 100644 --- a/backend/tests/README +++ b/backend/tests/README @@ -17,8 +17,11 @@ can be provided via --config: cd mkdir build cd build - cmake -DZINT_TEST=ON .. + cmake -DZINT_TEST=ON -DCMAKE_BUILD_TYPE=Debug .. cmake --build . --config Debug + +Note specifying a matching CMAKE_BUILD_TYPE is required to set the test PATH +environment for Windows. ------------------------------------------------------------------------------ @@ -33,7 +36,11 @@ exporting LD_LIBRARY_PATH to the path containing the zint library, which is Setting LD_LIBRARY_PATH is not required if the zint library to be tested is installed into a system library path ( /usr/lib for example ) prior to running -the tests. +the tests, or if the tests are not run individually. + +(On Windows, the PATH may need to be set to include the DLL location.) + +------------------------------------------------------------------------------ To run all tests (within ): @@ -72,7 +79,7 @@ To exclude a single dataset item in a single test function, use '-x ': This can also take a range, '-x -': - backend/tests/test_dotcode -f input -x 4,6 + backend/tests/test_dotcode -f input -x 4-6 Exclude can be used multiple times (unlike '-i'): diff --git a/backend_qt/tests/CMakeLists.txt b/backend_qt/tests/CMakeLists.txt index ac7a6526..220234d8 100644 --- a/backend_qt/tests/CMakeLists.txt +++ b/backend_qt/tests/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2021 Robin Stuart +# Copyright (C) 2021-23 Robin Stuart # vim: set ts=4 sw=4 et : cmake_minimum_required(VERSION 3.5) @@ -17,6 +17,12 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOMOC ON) add_executable(test_qzint test_qzint.cpp) -add_test(NAME qzint COMMAND test_qzint) - target_link_libraries(test_qzint PRIVATE QZint Qt${QT_VERSION_MAJOR}::Test) +add_test(NAME qzint COMMAND test_qzint) +if(MSVC) + set_tests_properties(qzint PROPERTIES ENVIRONMENT + "PATH=${CMAKE_BINARY_DIR}/backend/${CMAKE_BUILD_TYPE}\;${CMAKE_BINARY_DIR}/frontend/${CMAKE_BUILD_TYPE}\;$ENV{PATH}") +else() + set_tests_properties(qzint PROPERTIES ENVIRONMENT + "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/backend;PATH=${CMAKE_BINARY_DIR}/frontend:$ENV{PATH}") +endif() diff --git a/cmake/zint_add_test.cmake b/cmake/zint_add_test.cmake index ca019614..a0276ce8 100644 --- a/cmake/zint_add_test.cmake +++ b/cmake/zint_add_test.cmake @@ -1,4 +1,4 @@ -# Copyright (C) 2021 Robin Stuart +# Copyright (C) 2021-23 Robin Stuart # Adapted from qrencode/tests/CMakeLists.txt # Copyright (C) 2006-2017 Kentaro Fukuchi # vim: set ts=4 sw=4 et : @@ -9,12 +9,24 @@ macro(zint_add_test test_name test_command) add_executable(${test_command} ${test_command}.c) target_link_libraries(${test_command} testcommon ${ADDITIONAL_LIBS}) add_test(${test_name} ${test_command}) - set_tests_properties(${test_name} PROPERTIES ENVIRONMENT "CMAKE_CURRENT_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}") + if(MSVC) + set_tests_properties(${test_name} PROPERTIES ENVIRONMENT + "CMAKE_CURRENT_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR};PATH=${CMAKE_BINARY_DIR}/backend/${CMAKE_BUILD_TYPE}\;${CMAKE_BINARY_DIR}/frontend/${CMAKE_BUILD_TYPE}\;$ENV{PATH}") + else() + set_tests_properties(${test_name} PROPERTIES ENVIRONMENT + "CMAKE_CURRENT_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR};LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/backend;PATH=${CMAKE_BINARY_DIR}/frontend:$ENV{PATH}") + endif() endif() if(ZINT_STATIC) add_executable(${test_command}-static ${test_command}.c) target_link_libraries(${test_command}-static testcommon-static ${ADDITIONAL_LIBS}) add_test(${test_name}-static ${test_command}-static) - set_tests_properties(${test_name}-static PROPERTIES ENVIRONMENT "CMAKE_CURRENT_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}") + if(MSVC) + set_tests_properties(${test_name}-static PROPERTIES ENVIRONMENT + "CMAKE_CURRENT_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR};PATH=${CMAKE_BINARY_DIR}/backend/${CMAKE_BUILD_TYPE}\;${CMAKE_BINARY_DIR}/frontend/${CMAKE_BUILD_TYPE}\;$ENV{PATH}") + else() + set_tests_properties(${test_name}-static PROPERTIES ENVIRONMENT + "CMAKE_CURRENT_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR};LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/backend;PATH=${CMAKE_BINARY_DIR}/frontend:$ENV{PATH}") + endif() endif() endmacro() diff --git a/frontend/tests/CMakeLists.txt b/frontend/tests/CMakeLists.txt index bd907a47..74beb4a3 100644 --- a/frontend/tests/CMakeLists.txt +++ b/frontend/tests/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2020 Robin Stuart +# Copyright (C) 2020-23 Robin Stuart # Adapted from qrencode/tests/CMakeLists.txt # Copyright (C) 2006-2017 Kentaro Fukuchi # vim: set ts=4 sw=4 et : @@ -10,4 +10,7 @@ enable_testing() include(${zint-package_SOURCE_DIR}/cmake/zint_add_test.cmake) +if(ZINT_SHARED) + set(ZINT_STATIC "") +endif() zint_add_test(args test_args)