Optionalize the PNG and the Qt dependencies

Expose the ability to turn these dependencies off, which results in reduced
functionality. However, it enables a developer using the zint library to
instruct cmake to build a libzint as deployed by e.g. build servers which
don't have png/zint installed, without having to uninstall those libraries
from the development system
This commit is contained in:
Schaich 2021-03-29 23:35:57 +09:00
parent fd656358a3
commit 9ff3f13c19
3 changed files with 11 additions and 5 deletions

View File

@ -23,6 +23,8 @@ option(ZINT_DEBUG "Set debug compile flag" OFF)
option(ZINT_SANITIZE "Set sanitize compile/link flags" OFF) option(ZINT_SANITIZE "Set sanitize compile/link flags" OFF)
option(ZINT_TEST "Set test compile flag" OFF) option(ZINT_TEST "Set test compile flag" OFF)
option(ZINT_STATIC "Build static library" OFF) option(ZINT_STATIC "Build static library" OFF)
option(ZINT_USE_PNG "Build with PNG support" ON)
option(ZINT_USE_QT "Build with QT support" ON)
include(SetPaths.cmake) include(SetPaths.cmake)
@ -90,7 +92,9 @@ ENDIF(APPLE)
add_subdirectory(backend) add_subdirectory(backend)
add_subdirectory(frontend) add_subdirectory(frontend)
if($ENV{CMAKE_PREFIX_PATH} MATCHES "6[.][0-9][.][0-9]") if(NOT ZINT_USE_QT)
message(STATUS "Qt support was disabled for this build")
elseif($ENV{CMAKE_PREFIX_PATH} MATCHES "6[.][0-9][.][0-9]")
set(USE_QT6 TRUE) set(USE_QT6 TRUE)
message(STATUS "Using Qt6") message(STATUS "Using Qt6")
cmake_policy(SET CMP0012 NEW) # Recognize constants in if() cmake_policy(SET CMP0012 NEW) # Recognize constants in if()

View File

@ -5,8 +5,6 @@ project(zint)
configure_file(zintconfig.h.in ../../backend/zintconfig.h) configure_file(zintconfig.h.in ../../backend/zintconfig.h)
find_package(PNG)
set(zint_COMMON_SRCS common.c library.c large.c reedsol.c gs1.c eci.c general_field.c sjis.c gb2312.c gb18030.c) set(zint_COMMON_SRCS common.c library.c large.c reedsol.c gs1.c eci.c general_field.c sjis.c gb2312.c gb18030.c)
set(zint_ONEDIM_SRCS code.c code128.c 2of5.c upcean.c telepen.c medical.c plessey.c rss.c) set(zint_ONEDIM_SRCS code.c code128.c 2of5.c upcean.c telepen.c medical.c plessey.c rss.c)
set(zint_POSTAL_SRCS postal.c auspost.c imail.c mailmark.c) set(zint_POSTAL_SRCS postal.c auspost.c imail.c mailmark.c)
@ -37,7 +35,11 @@ endfunction()
set_target_properties(zint PROPERTIES SOVERSION "${ZINT_VERSION_MAJOR}.${ZINT_VERSION_MINOR}" set_target_properties(zint PROPERTIES SOVERSION "${ZINT_VERSION_MAJOR}.${ZINT_VERSION_MINOR}"
VERSION ${ZINT_VERSION}) VERSION ${ZINT_VERSION})
if(PNG_FOUND) if(ZINT_USE_PNG)
find_package(PNG)
endif()
if(ZINT_USE_PNG AND PNG_FOUND)
zint_target_link_libraries(PNG::PNG) zint_target_link_libraries(PNG::PNG)
else() else()
zint_target_compile_definitions(PUBLIC NO_PNG) zint_target_compile_definitions(PUBLIC NO_PNG)

View File

@ -81,7 +81,7 @@ zint_add_test(medical test_medical)
zint_add_test(pcx test_pcx) zint_add_test(pcx test_pcx)
zint_add_test(pdf417 test_pdf417) zint_add_test(pdf417 test_pdf417)
zint_add_test(plessey test_plessey) zint_add_test(plessey test_plessey)
if(PNG_FOUND) if(ZINT_USE_PNG AND PNG_FOUND)
zint_add_test(png test_png) zint_add_test(png test_png)
endif() endif()
zint_add_test(postal test_postal) zint_add_test(postal test_postal)