CMake: allow ctest to be run without having to install zint or

manually set LD_LIBRARY_PATH and PATH (ticket #279, props
  Alexey Dokuchaev)
This commit is contained in:
gitlost 2023-01-09 01:14:42 +00:00
parent be0d9bc663
commit 5669addf01
6 changed files with 45 additions and 11 deletions

View File

@ -1,5 +1,5 @@
# Copyright (C) 2008 by BogDan Vatra < bogdan@licentia.eu > # Copyright (C) 2008 by BogDan Vatra < bogdan@licentia.eu >
# Copyright (C) 2009-2022 Robin Stuart <rstuart114@gmail.com> # Copyright (C) 2009-2023 Robin Stuart <rstuart114@gmail.com>
# vim: set ts=4 sw=4 et : # vim: set ts=4 sw=4 et :
cmake_minimum_required(VERSION 3.5) 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_USE_QT "Build with Qt support" ON)
option(ZINT_QT6 "If ZINT_USE_QT, use Qt6" OFF) 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(SetPaths.cmake)
include(CheckCXXCompilerFlag) include(CheckCXXCompilerFlag)

View File

@ -15,6 +15,8 @@ Bugs
---- ----
- CEPNET: fix no HRT (library: `has_hrt()`) - CEPNET: fix no HRT (library: `has_hrt()`)
- man page: fix Code 11 check digit info - 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) Version 2.12.0 (2022-12-12)

View File

@ -17,8 +17,11 @@ can be provided via --config:
cd <project-dir> cd <project-dir>
mkdir build mkdir build
cd build cd build
cmake -DZINT_TEST=ON .. cmake -DZINT_TEST=ON -DCMAKE_BUILD_TYPE=Debug ..
cmake --build . --config 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 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 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 <build-dir>): To run all tests (within <build-dir>):
@ -72,7 +79,7 @@ To exclude a single dataset item in a single test function, use '-x <index>':
This can also take a range, '-x <start>-<end>': This can also take a range, '-x <start>-<end>':
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'): Exclude can be used multiple times (unlike '-i'):

View File

@ -1,4 +1,4 @@
# Copyright (C) 2021 Robin Stuart <rstuart114@gmail.com> # Copyright (C) 2021-23 Robin Stuart <rstuart114@gmail.com>
# vim: set ts=4 sw=4 et : # vim: set ts=4 sw=4 et :
cmake_minimum_required(VERSION 3.5) cmake_minimum_required(VERSION 3.5)
@ -17,6 +17,12 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOMOC ON)
add_executable(test_qzint test_qzint.cpp) 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) 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()

View File

@ -1,4 +1,4 @@
# Copyright (C) 2021 Robin Stuart <rstuart114@gmail.com> # Copyright (C) 2021-23 Robin Stuart <rstuart114@gmail.com>
# Adapted from qrencode/tests/CMakeLists.txt # Adapted from qrencode/tests/CMakeLists.txt
# Copyright (C) 2006-2017 Kentaro Fukuchi <kentaro@fukuchi.org> # Copyright (C) 2006-2017 Kentaro Fukuchi <kentaro@fukuchi.org>
# vim: set ts=4 sw=4 et : # 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) add_executable(${test_command} ${test_command}.c)
target_link_libraries(${test_command} testcommon ${ADDITIONAL_LIBS}) target_link_libraries(${test_command} testcommon ${ADDITIONAL_LIBS})
add_test(${test_name} ${test_command}) 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() endif()
if(ZINT_STATIC) if(ZINT_STATIC)
add_executable(${test_command}-static ${test_command}.c) add_executable(${test_command}-static ${test_command}.c)
target_link_libraries(${test_command}-static testcommon-static ${ADDITIONAL_LIBS}) target_link_libraries(${test_command}-static testcommon-static ${ADDITIONAL_LIBS})
add_test(${test_name}-static ${test_command}-static) 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() endif()
endmacro() endmacro()

View File

@ -1,4 +1,4 @@
# Copyright (C) 2020 Robin Stuart <rstuart114@gmail.com> # Copyright (C) 2020-23 Robin Stuart <rstuart114@gmail.com>
# Adapted from qrencode/tests/CMakeLists.txt # Adapted from qrencode/tests/CMakeLists.txt
# Copyright (C) 2006-2017 Kentaro Fukuchi <kentaro@fukuchi.org> # Copyright (C) 2006-2017 Kentaro Fukuchi <kentaro@fukuchi.org>
# vim: set ts=4 sw=4 et : # vim: set ts=4 sw=4 et :
@ -10,4 +10,7 @@ enable_testing()
include(${zint-package_SOURCE_DIR}/cmake/zint_add_test.cmake) include(${zint-package_SOURCE_DIR}/cmake/zint_add_test.cmake)
if(ZINT_SHARED)
set(ZINT_STATIC "")
endif()
zint_add_test(args test_args) zint_add_test(args test_args)