Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMakeLists.txt: Support building as shared library (as one would need… #222

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 61 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,23 @@ 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}>
)

if(BUILD_SHARED)
include (GNUInstallDirs)

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"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The QMake build installs the headers into the equivalent of just CMAKE_INSTALL_INCLUDEDIR. Could we make the install locations match to avoid differences between QMake & CMake being used for the build?

/nix/store/vyqb9vi69yrkmg4j1rw5vsd7rhfq7f5c-qzxing-3.3.0
├── include
│   ├── QZXing_global.h
│   └── QZXing.h
└── lib
    ├── libQZXing.so -> libQZXing.so.3.3.0
    ├── libQZXing.so.3 -> libQZXing.so.3.3.0
    ├── libQZXing.so.3.3 -> libQZXing.so.3.3.0
    ├── libQZXing.so.3.3.0
    └── pkgconfig
        └── QZXing.pc
Suggested change
FILES ${PUBLIC_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/qzxing"
FILES ${PUBLIC_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"

)
endif()