Skip to content

Commit

Permalink
CMakeLists.txt: Support building as shared library (as one would need…
Browse files Browse the repository at this point in the history
… for packaging a DEB package).
  • Loading branch information
sunweaver committed Oct 12, 2022
1 parent 4f3a13f commit bd3ccbe
Showing 1 changed file with 60 additions and 8 deletions.
68 changes: 60 additions & 8 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
cmake_minimum_required(VERSION 3.3)
project(QZXing)

option(BUILD_SHARED "Build as shared library" OFF)

if(BUILD_SHARED)
SET(SOVERSION_MAJOR 3)
SET(SOVERSION_MINOR 3)
SET(SOVERSION_PATCH 0)

OPTION(QZXING_MULTIMEDIA "" OFF)
OPTION(QZXING_USE_QML "" OFF)
OPTION(QZXING_USE_ENCODER "" OFF)
OPTION(QZXING_MULTIMEDIA "" OFF)
OPTION(QZXING_USE_QML "" OFF)
OPTION(QZXING_USE_ENCODER "" OFF)
OPTION(QZXING_USE_DECODER_QR_CODE "" OFF)
OPTION(QZXING_USE_DECODER_1D_BARCODES "" OFF)
OPTION(QZXING_USE_DECODER_DATA_MATRIX "" OFF)
OPTION(QZXING_USE_DECODER_AZTEC "" OFF)
OPTION(QZXING_USE_DECODER_PDF17 "" OFF)
OPTION(QZXING_USE_DECODER_1D_BARCODES "" OFF)
endif()

find_package(Qt5 COMPONENTS Core REQUIRED)
find_package(Qt5 COMPONENTS Gui REQUIRED)
find_package(Qt5 COMPONENTS Multimedia )
Expand All @@ -13,20 +34,25 @@ SET(ZXING_DIR ${CMAKE_CURRENT_SOURCE_DIR}/zxing/zxing)
set(CMAKE_AUTOMOC ON)
set(CMAKE_WARN_ON)

set(PUBLIC_HEADERS
QZXing.h
QZXing_global.h
)

set(SOURCES

CameraImageWrapper.cpp
CameraImageWrapper.h
ImageHandler.cpp
ImageHandler.h
QZXing.cpp
QZXing.h
QZXing_global.h
${PUBLIC_HEADERS}
)

if(QZXING_MULTIMEDIA)

LIST(APPEND SOURCES QZXingFilter.cpp QZXingFilter.h)
LIST(APPEND PUBLIC_HEADERS QZXingFilter.h)
add_definitions(-DQZXING_MULTIMEDIA)

SET(QZXING_USE_QML ON)
Expand All @@ -35,14 +61,24 @@ endif(QZXING_MULTIMEDIA)

if(QZXING_USE_QML)
LIST(APPEND SOURCES QZXingImageProvider.cpp QZXingImageProvider.h)
LIST(APPEND PUBLIC_HEADERS QZXingImageProvider.h)
add_definitions(-DQZXING_QML)
endif(QZXING_USE_QML)

if(QZXING_USE_ENCODER)
add_definitions(-DENABLE_ENCODER_GENERIC -DENABLE_ENCODER_QR_CODE)
endif(QZXING_USE_ENCODER)

add_library(qzxing "" ${SOURCES})
if(BUILD_SHARED)
add_library(qzxing SHARED ${SOURCES})
set_target_properties(qzxing
PROPERTIES
VERSION ${SOVERSION_MAJOR}.${SOVERSION_MINOR}.${SOVERSION_PATCH}
SOVERSION ${SOVERSION_MAJOR}
)
else()
add_library(qzxing "" ${SOURCES})
endif()

if(WIN32)
add_subdirectory(zxing/win32)
Expand Down Expand Up @@ -108,9 +144,10 @@ if(QZXING_USE_DECODER_1D_BARCODES)
target_compile_definitions(qzxing PRIVATE -DENABLE_DECODER_1D_BARCODES)
endif()


# Change Global Definitions depending on how you want to use the library
target_compile_definitions(qzxing PUBLIC DISABLE_LIBRARY_FEATURES)
if(!BUILD_SHARED)
# Change Global Definitions depending on how you want to use the library
target_compile_definitions(qzxing PUBLIC DISABLE_LIBRARY_FEATURES)
endif()

# Target includes
target_include_directories(qzxing
Expand All @@ -120,7 +157,22 @@ target_include_directories(qzxing
zxing/win32/zxing
zxing/zxing
zxing/bigint
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
)

include (GNUInstallDirs)

# TODO: find a working generator expression for this... :-/
set(QZXING_INSTALL_TARGETS qzxing)

install (
TARGETS ${QZXING_INSTALL_TARGETS} EXPORT QZXingTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

install (
FILES ${PUBLIC_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/qzxing"
)

0 comments on commit bd3ccbe

Please sign in to comment.