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

Add pkg-config export to CMake script #248

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
98 changes: 82 additions & 16 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
cmake_minimum_required(VERSION 3.3)
project(QZXing)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

option(BUILD_SHARED "Build as shared library" OFF)

if(BUILD_SHARED)
SET(SOVERSION_MAJOR 3)
SET(SOVERSION_MINOR 3)
SET(SOVERSION_PATCH 0)
SET(SOVERSION_FULL "${SOVERSION_MAJOR}.${SOVERSION_MINOR}.${SOVERSION_PATCH}")

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,36 +37,53 @@ 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(PUBLIC_DEFINES "")

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)
add_definitions(-DQZXING_MULTIMEDIA)
LIST(APPEND PUBLIC_HEADERS QZXingFilter.h)
LIST(APPEND PUBLIC_DEFINES QZXING_MULTIMEDIA)

SET(QZXING_USE_QML ON)

endif(QZXING_MULTIMEDIA)

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

if(QZXING_USE_ENCODER)
add_definitions(-DENABLE_ENCODER_GENERIC -DENABLE_ENCODER_QR_CODE)
LIST(APPEND PUBLIC_DEFINES ENABLE_ENCODER_GENERIC ENABLE_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_FULL}
SOVERSION ${SOVERSION_MAJOR}
)
else()
add_library(qzxing "" ${SOURCES})
endif()

if(WIN32)
add_subdirectory(zxing/win32)
Expand All @@ -69,21 +110,15 @@ target_link_libraries(qzxing Qt5::Core Qt5::Gui)

if(QZXING_MULTIMEDIA)
target_link_libraries(qzxing Qt5::Multimedia)
target_compile_definitions(qzxing PUBLIC -DQZXING_MULTIMEDIA)
endif(QZXING_MULTIMEDIA)

if(QZXING_USE_QML)
target_link_libraries(qzxing
Qt5::Svg
Qt5::Quick
Qt5::QuickControls2)
target_compile_definitions(qzxing PUBLIC -DQZXING_QML)
endif(QZXING_USE_QML)

if(QZXING_USE_ENCODER)
target_compile_definitions(qzxing PUBLIC -DENABLE_ENCODER_GENERIC -DENABLE_ENCODER_QR_CODE)
endif(QZXING_USE_ENCODER)

if(QZXING_USE_DECODER_QR_CODE)
target_compile_definitions(qzxing PRIVATE -DENABLE_DECODER_QR_CODE)
endif()
Expand All @@ -108,9 +143,12 @@ if(QZXING_USE_DECODER_1D_BARCODES)
target_compile_definitions(qzxing PRIVATE -DENABLE_DECODER_1D_BARCODES)
endif()

if(!BUILD_SHARED)
# Change Global Definitions depending on how you want to use the library
list(APPEND PUBLIC_DEFINES DISABLE_LIBRARY_FEATURES)
endif()

# Change Global Definitions depending on how you want to use the library
target_compile_definitions(qzxing PUBLIC DISABLE_LIBRARY_FEATURES)
target_compile_definitions(qzxing PUBLIC ${PUBLIC_DEFINES})

# Target includes
target_include_directories(qzxing
Expand All @@ -120,7 +158,35 @@ 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)
include (JoinPaths)

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"
)

join_paths(PC_LIBDIR "\${prefix}" "${CMAKE_INSTALL_LIBDIR}")
join_paths(PC_INCLUDEDIR "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}" "qzxing")

string(REPLACE ";" " -D" PC_DEFINES "${PUBLIC_DEFINES}")
if(PC_DEFINES)
set(PC_DEFINES "-D${PC_DEFINES}")
endif()

configure_file(QZXing.pc.in ${CMAKE_CURRENT_BINARY_DIR}/QZXing.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/QZXing.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
endif()
10 changes: 10 additions & 0 deletions src/QZXing.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
libdir=@PC_LIBDIR@
includedir=@PC_INCLUDEDIR@

Name: Qzxing
Description: Qzxing Library
Version: @SOVERSION_FULL@
Cflags: @PC_DEFINES@ -I${includedir}
Libs: -L${libdir} -lqzxing
23 changes: 23 additions & 0 deletions src/cmake/JoinPaths.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# This module provides function for joining paths
# known from most languages
#
# SPDX-License-Identifier: (MIT OR CC0-1.0)
# Copyright 2020 Jan Tojnar
# https://github.com/jtojnar/cmake-snips
#
# Modelled after Python’s os.path.join
# https://docs.python.org/3.7/library/os.path.html#os.path.join
# Windows not supported
function(join_paths joined_path first_path_segment)
set(temp_path "${first_path_segment}")
foreach(current_segment IN LISTS ARGN)
if(NOT ("${current_segment}" STREQUAL ""))
if(IS_ABSOLUTE "${current_segment}")
set(temp_path "${current_segment}")
else()
set(temp_path "${temp_path}/${current_segment}")
endif()
endif()
endforeach()
set(${joined_path} "${temp_path}" PARENT_SCOPE)
endfunction()