Skip to content

Commit

Permalink
CMake: Allow for OPTIONAL shared lib build (#197)
Browse files Browse the repository at this point in the history
 * Allow this project to be used with CMake FetchContent
 * Make sure only public headers are installed
 * Add support to generate packages with CPack
 * Set the proper targets/interfaces when used as shared library
 * Fixes ISSUE #49 exporting symbols
  • Loading branch information
dantti authored Jun 7, 2022
1 parent 9ae0d17 commit 1b0a279
Show file tree
Hide file tree
Showing 23 changed files with 227 additions and 32 deletions.
166 changes: 151 additions & 15 deletions QXlsx/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
# CMakeLists.txt for QXlsx Library

cmake_minimum_required(VERSION 3.14)
cmake_minimum_required(VERSION 3.16)

project(QXlsx LANGUAGES CXX)
project(QXlsx
VERSION 1.4.4
LANGUAGES CXX
)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

include(GNUInstallDirs)

find_package(QT NAMES Qt6 Qt5 COMPONENTS Core Gui REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Gui REQUIRED)

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

if(NOT DEFINED ${QXLSX_PARENTPATH})
set(QXLSX_PARENTPATH ${CMAKE_CURRENT_SOURCE_DIR}/../)
endif(NOT DEFINED ${QXLSX_PARENTPATH})
Expand Down Expand Up @@ -46,20 +51,151 @@ add_definitions(
-DQT_DISABLE_DEPRECATED_BEFORE=0x050F00
)

file(GLOB QXLSX_CPP "${QXLSX_SOURCEPATH}/*.cpp")
file(GLOB QXLSX_H "${QXLSX_HEADERPATH}/*.h")
# Due historical reasons this value is kept off
option(BUILD_SHARED_LIBS "Build in shared lib mode" OFF)

set(SRC_FILES
source/xlsxcellrange.cpp
source/xlsxcellrange.cpp
source/xlsxcontenttypes.cpp
source/xlsxdrawinganchor.cpp
source/xlsxrichstring.cpp
source/xlsxworkbook.cpp
source/xlsxabstractooxmlfile.cpp
source/xlsxcellreference.cpp
source/xlsxdatavalidation.cpp
source/xlsxdrawing.cpp
source/xlsxsharedstrings.cpp
source/xlsxworksheet.cpp
source/xlsxabstractsheet.cpp
source/xlsxchart.cpp
source/xlsxdatetype.cpp
source/xlsxformat.cpp
source/xlsxsimpleooxmlfile.cpp
source/xlsxzipreader.cpp
source/xlsxcell.cpp
source/xlsxchartsheet.cpp
source/xlsxdocpropsapp.cpp
source/xlsxmediafile.cpp
source/xlsxstyles.cpp
source/xlsxzipwriter.cpp
source/xlsxcellformula.cpp
source/xlsxcolor.cpp
source/xlsxdocpropscore.cpp
source/xlsxnumformatparser.cpp
source/xlsxtheme.cpp
source/xlsxcelllocation.cpp
source/xlsxconditionalformatting.cpp
source/xlsxdocument.cpp
source/xlsxrelationships.cpp
source/xlsxutility.cpp
header/xlsxabstractooxmlfile_p.h
header/xlsxchartsheet_p.h
header/xlsxdocpropsapp_p.h
header/xlsxformat_p.h
header/xlsxsharedstrings_p.h
header/xlsxworkbook_p.h
header/xlsxabstractsheet_p.h
header/xlsxcolor_p.h
header/xlsxdocpropscore_p.h
header/xlsxmediafile_p.h
header/xlsxsimpleooxmlfile_p.h
header/xlsxworksheet_p.h
header/xlsxcellformula_p.h
header/xlsxconditionalformatting_p.h
header/xlsxdocument_p.h
header/xlsxnumformatparser_p.h
header/xlsxstyles_p.h
header/xlsxzipreader_p.h
header/xlsxcell_p.h
header/xlsxcontenttypes_p.h
header/xlsxdrawinganchor_p.h
header/xlsxrelationships_p.h
header/xlsxtheme_p.h
header/xlsxzipwriter_p.h
header/xlsxchart_p.h
header/xlsxdatavalidation_p.h
header/xlsxdrawing_p.h
header/xlsxrichstring_p.h
header/xlsxutility_p.h
)

set(SRC_FILES ${QXLSX_CPP})
list(APPEND SRC_FILES ${QXLSX_H})
set(QXLSX_PUBLIC_HEADERS
header/xlsxabstractooxmlfile.h
header/xlsxabstractsheet.h
header/xlsxabstractsheet_p.h
header/xlsxcellformula.h
header/xlsxcell.h
header/xlsxcelllocation.h
header/xlsxcellrange.h
header/xlsxcellreference.h
header/xlsxchart.h
header/xlsxchartsheet.h
header/xlsxconditionalformatting.h
header/xlsxdatavalidation.h
header/xlsxdatetype.h
header/xlsxdocument.h
header/xlsxformat.h
header/xlsxglobal.h
header/xlsxrichstring.h
header/xlsxworkbook.h
header/xlsxworksheet.h
)

add_library(QXlsx STATIC
${SRC_FILES} )
add_library(QXlsx
${SRC_FILES}
${QXLSX_PUBLIC_HEADERS}
)

target_include_directories(QXlsx PRIVATE ${QXLSX_HEADERPATH})
add_library(QXlsx::QXlsx ALIAS QXlsx)

target_link_libraries(${PROJECT_NAME}
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::GuiPrivate
)
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::GuiPrivate
)

target_include_directories(QXlsx
PRIVATE
${QXLSX_HEADERPATH}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/header>
$<INSTALL_INTERFACE:include/QXlsx>
)

set_target_properties(QXlsx PROPERTIES
EXPORT_NAME QXlsx
VERSION ${PROJECT_VERSION}
SOVERSION 0
PUBLIC_HEADER "${QXLSX_PUBLIC_HEADERS}"
)

install(TARGETS QXlsx
EXPORT QXlsxTargets DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION bin COMPONENT runtime
ARCHIVE DESTINATION lib COMPONENT devel
PUBLIC_HEADER DESTINATION include/QXlsx COMPONENT devel
)

install(EXPORT QXlsxTargets
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/QXlsx/
FILE QXlsxTargets.cmake
NAMESPACE QXlsx::
COMPONENT devel
)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/qxlsx-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/QXlsxConfig.cmake
@ONLY
)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/qxlsx-config-version.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/QXlsxConfigVersion.cmake
@ONLY
)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/QXlsxConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/QXlsxConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/QXlsx/
)

target_compile_definitions(QXlsx PRIVATE QXLSX_LIBRARY)
include(CPackConfig)
3 changes: 3 additions & 0 deletions QXlsx/QXlsx.pri
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ CONFIG += c++11
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# For DLL visibility
DEFINES += QXlsx_EXPORTS

# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
Expand Down
21 changes: 21 additions & 0 deletions QXlsx/cmake/modules/CPackConfig.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# SPDX-FileCopyrightText: (C) 2021 Daniel Nicoletti <[email protected]>
# SPDX-License-Identifier: MIT

set(CPACK_PACKAGE_VENDOR "Daniel Nicoletti")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "QXlsx library.")
set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/../README.md")
set(CPACK_PACKAGE_CONTACT "Daniel Nicoletti <[email protected]>")

if(UNIX)
if(NOT CPACK_GENERATOR)
set(CPACK_GENERATOR "DEB")
endif()

set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
set(CPACK_STRIP_FILES 1)
if(${CMAKE_VERSION} VERSION_GREATER "3.5")
set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
endif()
endif()

include(CPack)
15 changes: 15 additions & 0 deletions QXlsx/cmake/modules/qxlsx-config-version.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# SPDX-FileCopyrightText: (C) 2021 Daniel Nicoletti <[email protected]>
# SPDX-License-Identifier: MIT

SET(PACKAGE_VERSION @PROJECT_VERSION@)
IF (PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION)
SET(PACKAGE_VERSION_EXACT "true")
ENDIF (PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION)
IF (NOT PACKAGE_FIND_VERSION VERSION_GREATER PACKAGE_VERSION)
SET(PACKAGE_VERSION_COMPATIBLE "true")
ELSE (NOT PACKAGE_FIND_VERSION VERSION_GREATER PACKAGE_VERSION)
SET(PACKAGE_VERSION_UNSUITABLE "true")
ENDIF (NOT PACKAGE_FIND_VERSION VERSION_GREATER PACKAGE_VERSION)
IF (PACKAGE_VERSION_UNSUITABLE)
MESSAGE("VERSION CHECK FAILED FOR ${PACKAGE_FIND_NAME}. WANTED ${PACKAGE_FIND_VERSION}, HAVE ${PACKAGE_VERSION}")
ENDIF(PACKAGE_VERSION_UNSUITABLE)
14 changes: 14 additions & 0 deletions QXlsx/cmake/modules/qxlsx-config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# SPDX-FileCopyrightText: (C) 2021 Daniel Nicoletti <[email protected]>
# SPDX-License-Identifier: MIT

# - Config information for QXlsx
# This file defines:
#
# QXlsx_INCLUDE_DIR - the QXlsx include directory
# QXlsx_LIBRARY - Link these to use QXlsx

SET(prefix "@CMAKE_INSTALL_PREFIX@")
SET(exec_prefix "@CMAKE_INSTALL_PREFIX@")
SET(QXlsx_FOUND "TRUE")

include("${CMAKE_CURRENT_LIST_DIR}/QXlsxTargets.cmake")
2 changes: 1 addition & 1 deletion QXlsx/header/xlsxabstractooxmlfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ QT_BEGIN_NAMESPACE_XLSX
class Relationships;
class AbstractOOXmlFilePrivate;

class AbstractOOXmlFile
class QXLSX_EXPORT AbstractOOXmlFile
{
Q_DECLARE_PRIVATE(AbstractOOXmlFile)

Expand Down
2 changes: 1 addition & 1 deletion QXlsx/header/xlsxabstractsheet.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Workbook;
class Drawing;
class AbstractSheetPrivate;

class AbstractSheet : public AbstractOOXmlFile
class QXLSX_EXPORT AbstractSheet : public AbstractOOXmlFile
{
Q_DECLARE_PRIVATE(AbstractSheet)

Expand Down
2 changes: 1 addition & 1 deletion QXlsx/header/xlsxcell.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class CellFormula;
class CellPrivate;
class WorksheetPrivate;

class Cell
class QXLSX_EXPORT Cell
{
Q_DECLARE_PRIVATE(Cell)

Expand Down
2 changes: 1 addition & 1 deletion QXlsx/header/xlsxcellformula.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class CellRange;
class Worksheet;
class WorksheetPrivate;

class CellFormula
class QXLSX_EXPORT CellFormula
{
public:
enum FormulaType { NormalType, ArrayType, DataTableType, SharedType };
Expand Down
2 changes: 1 addition & 1 deletion QXlsx/header/xlsxcelllocation.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ QT_BEGIN_NAMESPACE_XLSX

class Cell;

class CellLocation
class QXLSX_EXPORT CellLocation
{
public:
CellLocation();
Expand Down
2 changes: 1 addition & 1 deletion QXlsx/header/xlsxcellrange.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
QT_BEGIN_NAMESPACE_XLSX

// dev57
class CellRange
class QXLSX_EXPORT CellRange
{
public:
CellRange();
Expand Down
2 changes: 1 addition & 1 deletion QXlsx/header/xlsxcellreference.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

QT_BEGIN_NAMESPACE_XLSX

class CellReference
class QXLSX_EXPORT CellReference
{
public:
CellReference();
Expand Down
2 changes: 1 addition & 1 deletion QXlsx/header/xlsxchart.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ChartPrivate;
class CellRange;
class DrawingAnchor;

class Chart : public AbstractOOXmlFile
class QXLSX_EXPORT Chart : public AbstractOOXmlFile
{
Q_DECLARE_PRIVATE(Chart)
public:
Expand Down
2 changes: 1 addition & 1 deletion QXlsx/header/xlsxchartsheet.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class DocumentPrivate;
class ChartsheetPrivate;
class Chart;

class Chartsheet : public AbstractSheet
class QXLSX_EXPORT Chartsheet : public AbstractSheet
{
Q_DECLARE_PRIVATE(Chartsheet)

Expand Down
2 changes: 1 addition & 1 deletion QXlsx/header/xlsxconditionalformatting.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Worksheet;
class Styles;
class ConditionalFormattingPrivate;

class ConditionalFormatting
class QXLSX_EXPORT ConditionalFormatting
{
public:
enum HighlightRuleType {
Expand Down
2 changes: 1 addition & 1 deletion QXlsx/header/xlsxdatavalidation.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CellRange;
class CellReference;

class DataValidationPrivate;
class DataValidation
class QXLSX_EXPORT DataValidation
{
public:
enum ValidationType
Expand Down
2 changes: 1 addition & 1 deletion QXlsx/header/xlsxdatetype.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

QT_BEGIN_NAMESPACE_XLSX

class DateType
class QXLSX_EXPORT DateType
{
public:
DateType();
Expand Down
2 changes: 1 addition & 1 deletion QXlsx/header/xlsxdocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Chart;
class CellReference;
class DocumentPrivate;

class Document : public QObject
class QXLSX_EXPORT Document : public QObject
{
Q_OBJECT
Q_DECLARE_PRIVATE(Document) // D-Pointer. Qt classes have a Q_DECLARE_PRIVATE
Expand Down
2 changes: 1 addition & 1 deletion QXlsx/header/xlsxformat.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class SharedStrings;

class FormatPrivate;

class Format
class QXLSX_EXPORT Format
{
public:
enum FontScript
Expand Down
6 changes: 6 additions & 0 deletions QXlsx/header/xlsxglobal.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
#include <QStringList>
#include <QSharedPointer>

#if defined(QXlsx_EXPORTS)
# define QXLSX_EXPORT Q_DECL_EXPORT
#else
# define QXLSX_EXPORT Q_DECL_IMPORT
#endif

#define QT_BEGIN_NAMESPACE_XLSX namespace QXlsx {
#define QT_END_NAMESPACE_XLSX }

Expand Down
Loading

0 comments on commit 1b0a279

Please sign in to comment.