- Added CMAKE custom FindEXPAT.cmake for finding libs with "d" suffix for debug build on Windows

- Added optional include of conanbuildinfo.txt in project CMakeLists.txt
- Added conanfile.py with receipt to build conan package and written dependenices as conan packages
- Added conan build instruction to README.md
This commit is contained in:
Igor Pronin 2022-04-28 12:21:47 +03:00
parent cd779f611c
commit 2acde8e447
4 changed files with 411 additions and 243 deletions

81
CMake/FindEXPAT.cmake Normal file
View File

@ -0,0 +1,81 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
#[=======================================================================[.rst:
FindEXPAT
---------
Find the native Expat headers and library.
Expat is a stream-oriented XML parser library written in C.
Imported Targets
^^^^^^^^^^^^^^^^
This module defines the following :prop_tgt:`IMPORTED` targets:
``EXPAT::EXPAT``
The Expat ``expat`` library, if found.
Result Variables
^^^^^^^^^^^^^^^^
This module will set the following variables in your project:
``EXPAT_INCLUDE_DIRS``
where to find expat.h, etc.
``EXPAT_LIBRARIES``
the libraries to link against to use Expat.
``EXPAT_FOUND``
true if the Expat headers and libraries were found.
#]=======================================================================]
find_package(PkgConfig QUIET)
pkg_check_modules(PC_EXPAT QUIET expat)
# Look for the header file.
find_path(EXPAT_INCLUDE_DIR NAMES expat.h HINTS ${PC_EXPAT_INCLUDE_DIRS})
# Look for the library.
find_library(EXPAT_LIBRARY NAMES expat expatd libexpat libexpatd NAMES_PER_DIR HINTS ${PC_EXPAT_LIBRARY_DIRS})
if (EXPAT_INCLUDE_DIR AND EXISTS "${EXPAT_INCLUDE_DIR}/expat.h")
file(STRINGS "${EXPAT_INCLUDE_DIR}/expat.h" expat_version_str
REGEX "^#[\t ]*define[\t ]+XML_(MAJOR|MINOR|MICRO)_VERSION[\t ]+[0-9]+$")
unset(EXPAT_VERSION_STRING)
foreach(VPART MAJOR MINOR MICRO)
foreach(VLINE ${expat_version_str})
if(VLINE MATCHES "^#[\t ]*define[\t ]+XML_${VPART}_VERSION[\t ]+([0-9]+)$")
set(EXPAT_VERSION_PART "${CMAKE_MATCH_1}")
if(EXPAT_VERSION_STRING)
string(APPEND EXPAT_VERSION_STRING ".${EXPAT_VERSION_PART}")
else()
set(EXPAT_VERSION_STRING "${EXPAT_VERSION_PART}")
endif()
endif()
endforeach()
endforeach()
endif ()
#include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(EXPAT
REQUIRED_VARS EXPAT_LIBRARY EXPAT_INCLUDE_DIR
VERSION_VAR EXPAT_VERSION_STRING)
# Copy the results to the output variables and target.
if(EXPAT_FOUND)
set(EXPAT_LIBRARIES ${EXPAT_LIBRARY})
set(EXPAT_INCLUDE_DIRS ${EXPAT_INCLUDE_DIR})
if(NOT TARGET EXPAT::EXPAT)
add_library(EXPAT::EXPAT UNKNOWN IMPORTED)
set_target_properties(EXPAT::EXPAT PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${EXPAT_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${EXPAT_INCLUDE_DIRS}")
endif()
endif()
mark_as_advanced(EXPAT_INCLUDE_DIR EXPAT_LIBRARY)

View File

@ -1,243 +1,249 @@
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT(xlsxio DESCRIPTION "C libraries for reading and writing .xlsx files")
# get version number
FILE(READ "include/xlsxio_version.h" VERFILE)
STRING(REGEX MATCH "#define XLSXIO_VERSION_MAJOR ([0-9]*)" DUMMYVAR ${VERFILE})
SET(XLSXIO_VER_MAJOR ${CMAKE_MATCH_1})
STRING(REGEX MATCH "#define XLSXIO_VERSION_MINOR ([0-9]*)" DUMMYVAR ${VERFILE})
SET(XLSXIO_VER_MINOR ${CMAKE_MATCH_1})
STRING(REGEX MATCH "#define XLSXIO_VERSION_MICRO ([0-9]*)" DUMMYVAR ${VERFILE})
SET(XLSXIO_VER_MICRO ${CMAKE_MATCH_1})
SET(XLSXIO_VER "${XLSXIO_VER_MAJOR}.${XLSXIO_VER_MINOR}.${XLSXIO_VER_MICRO}")
UNSET(DUMMYVAR)
UNSET(VERFILE)
MESSAGE(STATUS "XLSX I/O library version: ${XLSXIO_VER}")
# parameters
OPTION(BUILD_STATIC "Build static libraries" ON)
OPTION(BUILD_SHARED "Build shared libraries" ON)
OPTION(BUILD_PC_FILES "Build pkg-config .pc" ON)
OPTION(BUILD_TOOLS "Build tools" ON)
OPTION(BUILD_EXAMPLES "Build examples" ON)
OPTION(WITH_LIBZIP "Use libzip instead of Minizip" OFF)
OPTION(WITH_WIDE "Also build UTF-16 library (libxlsxio_readw)" OFF)
SET(ZLIB_DIR "" CACHE PATH "Path to the zlib library")
IF(WITH_LIBZIP)
SET(LIBZIP_DIR "" CACHE PATH "Path to the libzip library")
ELSE()
SET(MINIZIP_DIR "" CACHE PATH "Path to the Minizip library")
ENDIF()
SET(EXPAT_DIR "" CACHE PATH "Path to the Expat library")
# check conditions
IF(NOT BUILD_STATIC AND NOT BUILD_SHARED)
MESSAGE(FATAL_ERROR "Cannot build with both BUILD_STATIC and BUILD_SHARED disabled")
ENDIF()
# dependancies
SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake" ${CMAKE_MODULE_PATH})
# dependancy: zlib (dependancy of libzip/Minizip, should be detected there)
IF(ZLIB_DIR)
SET(ZLIB_ROOT ${ZLIB_DIR})
ENDIF()
#FIND_PACKAGE(ZLIB REQUIRED)
# dependancy: libzip
IF(WITH_LIBZIP)
FIND_PACKAGE(LibZip REQUIRED)
SET(ANYZIP_INCLUDE_DIRS ${LIBZIP_INCLUDE_DIRS})
SET(ANYZIP_LIBRARIES ${LIBZIP_LIBRARIES})
SET(ANYZIP_DEF USE_LIBZIP)
ELSE()
FIND_PACKAGE(Minizip REQUIRED)
SET(ANYZIP_INCLUDE_DIRS ${MINIZIP_INCLUDE_DIRS})
SET(ANYZIP_LIBRARIES ${MINIZIP_LIBRARIES})
SET(ANYZIP_DEF USE_MINIZIP)
ENDIF()
# dependancy: expat
IF(EXPAT_DIR)
#FIND_PACKAGE(EXPAT MODULE REQUIRED NO_DEFAULT_PATH PATHS ${EXPAT_DIR})
FIND_PATH(EXPAT_INCLUDE_DIR NAMES expat.h NO_DEFAULT_PATH PATHS ${EXPAT_DIR}/include ${EXPAT_DIR})
FIND_LIBRARY(EXPAT_LIBRARIES NAMES expat libexpat NO_DEFAULT_PATH PATHS ${EXPAT_DIR}/lib ${EXPAT_DIR})
ELSE()
FIND_PACKAGE(EXPAT REQUIRED)
ENDIF()
# dependancy: expatw (if wide library was requested)
IF(WITH_WIDE)
IF(EXPAT_DIR)
FIND_LIBRARY(EXPATW_LIBRARIES NAMES expatw libexpatw NO_DEFAULT_PATH PATHS ${EXPAT_DIR}/lib ${EXPAT_DIR})
ELSE()
FIND_LIBRARY(EXPATW_LIBRARIES NAMES expatw)
ENDIF()
ENDIF()
# Doxygen
FIND_PACKAGE(Doxygen)
OPTION(BUILD_DOCUMENTATION "Create and install API documentation (requires Doxygen)" ${DOXYGEN_FOUND})
# build parameters
#SET(CMAKE_CXX_FLAGS "-g -Wall")
#ADD_SUBDIRECTORY(src)
IF(NOT WIN32 AND NOT APPLE)
SET(THREADLIB "-pthread")
ENDIF()
INCLUDE_DIRECTORIES(include)
INCLUDE_DIRECTORIES(${ANYZIP_INCLUDE_DIRS})
INCLUDE_DIRECTORIES(${EXPAT_INCLUDE_DIR})
# build definitions
SET(ALLTARGETS)
SET(LINKTYPES)
IF(BUILD_STATIC)
LIST(APPEND LINKTYPES "STATIC")
ENDIF()
IF(BUILD_SHARED)
LIST(APPEND LINKTYPES "SHARED")
ENDIF()
FOREACH(LINKTYPE ${LINKTYPES})
ADD_LIBRARY(xlsxio_read_${LINKTYPE} ${LINKTYPE} lib/xlsxio_read.c lib/xlsxio_read_sharedstrings.c)
SET_TARGET_PROPERTIES(xlsxio_read_${LINKTYPE} PROPERTIES COMPILE_DEFINITIONS "BUILD_XLSXIO;${ANYZIP_DEF};BUILD_XLSXIO_${LINKTYPE}")
SET_TARGET_PROPERTIES(xlsxio_read_${LINKTYPE} PROPERTIES OUTPUT_NAME xlsxio_read)
IF(MINGW AND LINKTYPE STREQUAL "SHARED")
SET_TARGET_PROPERTIES(xlsxio_read_${LINKTYPE} PROPERTIES LINK_FLAGS "-Wl,--output-def=libxlsxio_read.def")
SET_SOURCE_FILES_PROPERTIES(xlsxio_read.def PROPERTIES HEADER_FILE_ONLY TRUE)
ENDIF()
TARGET_INCLUDE_DIRECTORIES(xlsxio_read_${LINKTYPE} PRIVATE lib)
TARGET_LINK_LIBRARIES(xlsxio_read_${LINKTYPE} ${ANYZIP_LIBRARIES} ${EXPAT_LIBRARIES})
SET(ALLTARGETS ${ALLTARGETS} xlsxio_read_${LINKTYPE})
ADD_LIBRARY(xlsxio_write_${LINKTYPE} ${LINKTYPE} lib/xlsxio_write.c)
SET_TARGET_PROPERTIES(xlsxio_write_${LINKTYPE} PROPERTIES COMPILE_DEFINITIONS "BUILD_XLSXIO;${ANYZIP_DEF};BUILD_XLSXIO_${LINKTYPE}")
SET_TARGET_PROPERTIES(xlsxio_write_${LINKTYPE} PROPERTIES OUTPUT_NAME xlsxio_write)
IF(MINGW AND LINKTYPE STREQUAL "SHARED")
SET_TARGET_PROPERTIES(xlsxio_write_${LINKTYPE} PROPERTIES LINK_FLAGS "-Wl,--output-def=libxlsxio_write.def")
ENDIF()
TARGET_LINK_LIBRARIES(xlsxio_write_${LINKTYPE} ${ANYZIP_LIBRARIES} ${THREADLIB})
SET(ALLTARGETS ${ALLTARGETS} xlsxio_write_${LINKTYPE})
IF(WITH_WIDE)
ADD_LIBRARY(xlsxio_readw_${LINKTYPE} ${LINKTYPE} lib/xlsxio_read.c lib/xlsxio_read_sharedstrings.c)
SET_TARGET_PROPERTIES(xlsxio_readw_${LINKTYPE} PROPERTIES DEFINE_SYMBOL "BUILD_XLSXIO_DLL")
SET_TARGET_PROPERTIES(xlsxio_readw_${LINKTYPE} PROPERTIES COMPILE_DEFINITIONS "XML_UNICODE;BUILD_XLSXIO;${ANYZIP_DEF}")
SET_TARGET_PROPERTIES(xlsxio_readw_${LINKTYPE} PROPERTIES OUTPUT_NAME xlsxio_readw)
IF(MINGW AND LINKTYPE STREQUAL "SHARED")
SET_TARGET_PROPERTIES(xlsxio_readw_${LINKTYPE} PROPERTIES LINK_FLAGS "-Wl,--output-def=libxlsxio_readw.def")
ENDIF()
TARGET_INCLUDE_DIRECTORIES(xlsxio_readw_${LINKTYPE} PRIVATE lib)
TARGET_LINK_LIBRARIES(xlsxio_readw_${LINKTYPE} ${ANYZIP_LIBRARIES} ${EXPATW_LIBRARIES})
SET(ALLTARGETS ${ALLTARGETS} xlsxio_readw_${LINKTYPE})
#ADD_LIBRARY(xlsxio_writew_${LINKTYPE} ${LINKTYPE} lib/xlsxio_write.c)
#SET_TARGET_PROPERTIES(xlsxio_writew_${LINKTYPE} PROPERTIES DEFINE_SYMBOL "BUILD_XLSXIO_DLL")
#SET_TARGET_PROPERTIES(xlsxio_writew_${LINKTYPE} PROPERTIES COMPILE_DEFINITIONS "XML_UNICODE;BUILD_XLSXIO;${ANYZIP_DEF}")
#SET_TARGET_PROPERTIES(xlsxio_writew_${LINKTYPE} PROPERTIES OUTPUT_NAME xlsxio_write_w)
#IF(MINGW AND LINKTYPE STREQUAL "SHARED")
# SET_TARGET_PROPERTIES(xlsxio_writew_${LINKTYPE} PROPERTIES LINK_FLAGS "-Wl,--output-def=libxlsxio_writew.def")
#ENDIF()
#TARGET_LINK_LIBRARIES(xlsxio_writew_${LINKTYPE} ${ANYZIP_LIBRARIES} ${THREADLIB})
#SET(ALLTARGETS ${ALLTARGETS} xlsxio_writew_${LINKTYPE})
ENDIF()
SET(EXELINKTYPE ${LINKTYPE})
ENDFOREACH()
#SET_TARGET_PROPERTIES(xlsxio_read_SHARED PROPERTIES DEFINE_SYMBOL "BUILD_XLSXIO_DLL")
#SET_TARGET_PROPERTIES(xlsxio_write_SHARED PROPERTIES DEFINE_SYMBOL "BUILD_XLSXIO_DLL")
IF(BUILD_TOOLS)
ADD_EXECUTABLE(xlsxio_xlsx2csv src/xlsxio_xlsx2csv.c)
TARGET_LINK_LIBRARIES(xlsxio_xlsx2csv xlsxio_read_${EXELINKTYPE})
SET(ALLTARGETS ${ALLTARGETS} xlsxio_xlsx2csv)
ADD_EXECUTABLE(xlsxio_csv2xlsx src/xlsxio_csv2xlsx.c)
TARGET_LINK_LIBRARIES(xlsxio_csv2xlsx xlsxio_write_${EXELINKTYPE})
SET(ALLTARGETS ${ALLTARGETS} xlsxio_csv2xlsx)
ENDIF()
IF(BUILD_EXAMPLES)
ADD_EXECUTABLE(example_xlsxio_write_getversion examples/example_xlsxio_write_getversion.c)
TARGET_LINK_LIBRARIES(example_xlsxio_write_getversion xlsxio_write_${EXELINKTYPE})
SET(ALLTARGETS ${ALLTARGETS} example_xlsxio_write_getversion)
ADD_EXECUTABLE(example_xlsxio_write examples/example_xlsxio_write.c)
TARGET_LINK_LIBRARIES(example_xlsxio_write xlsxio_write_${EXELINKTYPE})
SET(ALLTARGETS ${ALLTARGETS} example_xlsxio_write)
ADD_EXECUTABLE(example_xlsxio_read examples/example_xlsxio_read.c)
TARGET_LINK_LIBRARIES(example_xlsxio_read xlsxio_read_${EXELINKTYPE})
SET(ALLTARGETS ${ALLTARGETS} example_xlsxio_read)
ADD_EXECUTABLE(example_xlsxio_read_advanced examples/example_xlsxio_read_advanced.c)
TARGET_LINK_LIBRARIES(example_xlsxio_read_advanced xlsxio_read_${EXELINKTYPE})
SET(ALLTARGETS ${ALLTARGETS} example_xlsxio_read_advanced)
IF(WITH_WIDE)
ADD_EXECUTABLE(example_xlsxio_readw examples/example_xlsxio_read.c)
SET_TARGET_PROPERTIES(example_xlsxio_readw PROPERTIES COMPILE_DEFINITIONS "XML_UNICODE")
TARGET_LINK_LIBRARIES(example_xlsxio_readw xlsxio_readw_${EXELINKTYPE})
SET(ALLTARGETS ${ALLTARGETS} example_xlsxio_readw)
ENDIF()
ENDIF()
IF(BUILD_DOCUMENTATION)
IF(NOT DOXYGEN_FOUND)
MESSAGE(FATAL_ERROR "Doxygen is needed to build the documentation.")
ENDIF()
ADD_CUSTOM_TARGET(doc ALL
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/doc/Doxyfile
#WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Generating API documentation with Doxygen"
VERBATIM
)
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/doc/man
DESTINATION .
)
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/doc/html
DESTINATION share/xlsxio
)
ENDIF()
# installation specifications
INSTALL(TARGETS ${ALLTARGETS}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)
INSTALL(DIRECTORY include/
DESTINATION include
FILES_MATCHING PATTERN "xlsxio*.h"
)
IF(MINGW AND BUILD_SHARED)
INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/libxlsxio_read.def" DESTINATION lib)
INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/libxlsxio_write.def" DESTINATION lib)
IF(WITH_WIDE)
INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/libxlsxio_readw.def" DESTINATION lib)
#INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/libxlsxio_writew.def" DESTINATION lib)
ENDIF()
ENDIF()
# generate .cmake and .pc files
MACRO(generate_and_install_config_files _NAME _DESC _LIBS _HEADER)
SET(XLSXIO_NAME "${_NAME}")
SET(XLSXIO_DESC "${_DESC}")
SET(XLSXIO_HEADER "${_HEADER}")
STRING(REGEX REPLACE "^lib\([^ ]*\)" "\\1" XLSXIO_LIB "${XLSXIO_NAME}")
STRING(REPLACE ";" " " XLSXIO_LDFLAGS "-l${XLSXIO_LIB} ${_LIBS}")
STRING(REGEX REPLACE "\([^ ]*\)[/\\]lib([^ /\\.]*).[^ ]*" "-L\\1 -l\\2" XLSXIO_LDFLAGS "${XLSXIO_LDFLAGS}")
CONFIGURE_FILE(templateConfig.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/${XLSXIO_NAME}Config.cmake" @ONLY)
CONFIGURE_FILE(templateConfigVersion.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/${XLSXIO_NAME}ConfigVersion.cmake" @ONLY)
INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/${XLSXIO_NAME}Config.cmake" "${CMAKE_CURRENT_BINARY_DIR}/${XLSXIO_NAME}ConfigVersion.cmake" DESTINATION cmake/)
IF (BUILD_PC_FILES)
CONFIGURE_FILE(template.pc.in "${CMAKE_CURRENT_BINARY_DIR}/${XLSXIO_NAME}.pc" @ONLY)
INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/${XLSXIO_NAME}.pc" DESTINATION lib/pkgconfig)
ENDIF()
ENDMACRO()
generate_and_install_config_files("libxlsxio_write" "C library for writing .xlsx files" "${ANYZIP_LIBRARIES} ${THREADLIB}" "xlsxio_write.h")
generate_and_install_config_files("libxlsxio_read" "C library for writing .xlsx files" "${ANYZIP_LIBRARIES} ${EXPAT_LIBRARIES}" "xlsxio_read.h")
IF(WITH_WIDE)
generate_and_install_config_files("libxlsxio_readw" "C library for reading .xlsx files using wide characters" "${ANYZIP_LIBRARIES} ${EXPAT_LIBRARIES}" "xlsxio_read.h")
ENDIF()
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT(xlsxio DESCRIPTION "C libraries for reading and writing .xlsx files")
# get version number
FILE(READ "include/xlsxio_version.h" VERFILE)
STRING(REGEX MATCH "#define XLSXIO_VERSION_MAJOR ([0-9]*)" DUMMYVAR ${VERFILE})
SET(XLSXIO_VER_MAJOR ${CMAKE_MATCH_1})
STRING(REGEX MATCH "#define XLSXIO_VERSION_MINOR ([0-9]*)" DUMMYVAR ${VERFILE})
SET(XLSXIO_VER_MINOR ${CMAKE_MATCH_1})
STRING(REGEX MATCH "#define XLSXIO_VERSION_MICRO ([0-9]*)" DUMMYVAR ${VERFILE})
SET(XLSXIO_VER_MICRO ${CMAKE_MATCH_1})
SET(XLSXIO_VER "${XLSXIO_VER_MAJOR}.${XLSXIO_VER_MINOR}.${XLSXIO_VER_MICRO}")
UNSET(DUMMYVAR)
UNSET(VERFILE)
MESSAGE(STATUS "XLSX I/O library version: ${XLSXIO_VER}")
find_path(CONANBUILDINFO NAMES conanbuildinfo.cmake NO_DEFAULT_PATH PATHS ${CMAKE_BINARY_DIR})
if (CONANBUILDINFO)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
endif()
# parameters
OPTION(BUILD_STATIC "Build static libraries" ON)
OPTION(BUILD_SHARED "Build shared libraries" ON)
OPTION(BUILD_PC_FILES "Build pkg-config .pc" ON)
OPTION(BUILD_TOOLS "Build tools" ON)
OPTION(BUILD_EXAMPLES "Build examples" ON)
OPTION(WITH_LIBZIP "Use libzip instead of Minizip" OFF)
OPTION(WITH_WIDE "Also build UTF-16 library (libxlsxio_readw)" OFF)
SET(ZLIB_DIR "" CACHE PATH "Path to the zlib library")
IF(WITH_LIBZIP)
SET(LIBZIP_DIR "" CACHE PATH "Path to the libzip library")
ELSE()
SET(MINIZIP_DIR "" CACHE PATH "Path to the Minizip library")
ENDIF()
SET(EXPAT_DIR "" CACHE PATH "Path to the Expat library")
# check conditions
IF(NOT BUILD_STATIC AND NOT BUILD_SHARED)
MESSAGE(FATAL_ERROR "Cannot build with both BUILD_STATIC and BUILD_SHARED disabled")
ENDIF()
# dependancies
SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake" ${CMAKE_MODULE_PATH})
# dependancy: zlib (dependancy of libzip/Minizip, should be detected there)
IF(ZLIB_DIR)
SET(ZLIB_ROOT ${ZLIB_DIR})
ENDIF()
#FIND_PACKAGE(ZLIB REQUIRED)
# dependancy: libzip
IF(WITH_LIBZIP)
FIND_PACKAGE(LibZip REQUIRED)
SET(ANYZIP_INCLUDE_DIRS ${LIBZIP_INCLUDE_DIRS})
SET(ANYZIP_LIBRARIES ${LIBZIP_LIBRARIES})
SET(ANYZIP_DEF USE_LIBZIP)
ELSE()
FIND_PACKAGE(Minizip REQUIRED)
SET(ANYZIP_INCLUDE_DIRS ${MINIZIP_INCLUDE_DIRS})
SET(ANYZIP_LIBRARIES ${MINIZIP_LIBRARIES})
SET(ANYZIP_DEF USE_MINIZIP)
ENDIF()
# dependancy: expat
IF(EXPAT_DIR)
#FIND_PACKAGE(EXPAT MODULE REQUIRED NO_DEFAULT_PATH PATHS ${EXPAT_DIR})
FIND_PATH(EXPAT_INCLUDE_DIR NAMES expat.h NO_DEFAULT_PATH PATHS ${EXPAT_DIR}/include ${EXPAT_DIR})
FIND_LIBRARY(EXPAT_LIBRARIES NAMES expat libexpat NO_DEFAULT_PATH PATHS ${EXPAT_DIR}/lib ${EXPAT_DIR})
ELSE()
FIND_PACKAGE(EXPAT REQUIRED)
ENDIF()
# dependancy: expatw (if wide library was requested)
IF(WITH_WIDE)
IF(EXPAT_DIR)
FIND_LIBRARY(EXPATW_LIBRARIES NAMES expatw libexpatw NO_DEFAULT_PATH PATHS ${EXPAT_DIR}/lib ${EXPAT_DIR})
ELSE()
FIND_LIBRARY(EXPATW_LIBRARIES NAMES expatw)
ENDIF()
ENDIF()
# Doxygen
FIND_PACKAGE(Doxygen)
OPTION(BUILD_DOCUMENTATION "Create and install API documentation (requires Doxygen)" ${DOXYGEN_FOUND})
# build parameters
#SET(CMAKE_CXX_FLAGS "-g -Wall")
#ADD_SUBDIRECTORY(src)
IF(NOT WIN32 AND NOT APPLE)
SET(THREADLIB "-pthread")
ENDIF()
INCLUDE_DIRECTORIES(include)
INCLUDE_DIRECTORIES(${ANYZIP_INCLUDE_DIRS})
INCLUDE_DIRECTORIES(${EXPAT_INCLUDE_DIR})
# build definitions
SET(ALLTARGETS)
SET(LINKTYPES)
IF(BUILD_STATIC)
LIST(APPEND LINKTYPES "STATIC")
ENDIF()
IF(BUILD_SHARED)
LIST(APPEND LINKTYPES "SHARED")
ENDIF()
FOREACH(LINKTYPE ${LINKTYPES})
ADD_LIBRARY(xlsxio_read_${LINKTYPE} ${LINKTYPE} lib/xlsxio_read.c lib/xlsxio_read_sharedstrings.c)
SET_TARGET_PROPERTIES(xlsxio_read_${LINKTYPE} PROPERTIES COMPILE_DEFINITIONS "BUILD_XLSXIO;${ANYZIP_DEF};BUILD_XLSXIO_${LINKTYPE}")
SET_TARGET_PROPERTIES(xlsxio_read_${LINKTYPE} PROPERTIES OUTPUT_NAME xlsxio_read)
IF(MINGW AND LINKTYPE STREQUAL "SHARED")
SET_TARGET_PROPERTIES(xlsxio_read_${LINKTYPE} PROPERTIES LINK_FLAGS "-Wl,--output-def=libxlsxio_read.def")
SET_SOURCE_FILES_PROPERTIES(xlsxio_read.def PROPERTIES HEADER_FILE_ONLY TRUE)
ENDIF()
TARGET_INCLUDE_DIRECTORIES(xlsxio_read_${LINKTYPE} PRIVATE lib)
TARGET_LINK_LIBRARIES(xlsxio_read_${LINKTYPE} ${ANYZIP_LIBRARIES} ${EXPAT_LIBRARIES})
SET(ALLTARGETS ${ALLTARGETS} xlsxio_read_${LINKTYPE})
ADD_LIBRARY(xlsxio_write_${LINKTYPE} ${LINKTYPE} lib/xlsxio_write.c)
SET_TARGET_PROPERTIES(xlsxio_write_${LINKTYPE} PROPERTIES COMPILE_DEFINITIONS "BUILD_XLSXIO;${ANYZIP_DEF};BUILD_XLSXIO_${LINKTYPE}")
SET_TARGET_PROPERTIES(xlsxio_write_${LINKTYPE} PROPERTIES OUTPUT_NAME xlsxio_write)
IF(MINGW AND LINKTYPE STREQUAL "SHARED")
SET_TARGET_PROPERTIES(xlsxio_write_${LINKTYPE} PROPERTIES LINK_FLAGS "-Wl,--output-def=libxlsxio_write.def")
ENDIF()
TARGET_LINK_LIBRARIES(xlsxio_write_${LINKTYPE} ${ANYZIP_LIBRARIES} ${THREADLIB})
SET(ALLTARGETS ${ALLTARGETS} xlsxio_write_${LINKTYPE})
IF(WITH_WIDE)
ADD_LIBRARY(xlsxio_readw_${LINKTYPE} ${LINKTYPE} lib/xlsxio_read.c lib/xlsxio_read_sharedstrings.c)
SET_TARGET_PROPERTIES(xlsxio_readw_${LINKTYPE} PROPERTIES DEFINE_SYMBOL "BUILD_XLSXIO_DLL")
SET_TARGET_PROPERTIES(xlsxio_readw_${LINKTYPE} PROPERTIES COMPILE_DEFINITIONS "XML_UNICODE;BUILD_XLSXIO;${ANYZIP_DEF}")
SET_TARGET_PROPERTIES(xlsxio_readw_${LINKTYPE} PROPERTIES OUTPUT_NAME xlsxio_readw)
IF(MINGW AND LINKTYPE STREQUAL "SHARED")
SET_TARGET_PROPERTIES(xlsxio_readw_${LINKTYPE} PROPERTIES LINK_FLAGS "-Wl,--output-def=libxlsxio_readw.def")
ENDIF()
TARGET_INCLUDE_DIRECTORIES(xlsxio_readw_${LINKTYPE} PRIVATE lib)
TARGET_LINK_LIBRARIES(xlsxio_readw_${LINKTYPE} ${ANYZIP_LIBRARIES} ${EXPATW_LIBRARIES})
SET(ALLTARGETS ${ALLTARGETS} xlsxio_readw_${LINKTYPE})
#ADD_LIBRARY(xlsxio_writew_${LINKTYPE} ${LINKTYPE} lib/xlsxio_write.c)
#SET_TARGET_PROPERTIES(xlsxio_writew_${LINKTYPE} PROPERTIES DEFINE_SYMBOL "BUILD_XLSXIO_DLL")
#SET_TARGET_PROPERTIES(xlsxio_writew_${LINKTYPE} PROPERTIES COMPILE_DEFINITIONS "XML_UNICODE;BUILD_XLSXIO;${ANYZIP_DEF}")
#SET_TARGET_PROPERTIES(xlsxio_writew_${LINKTYPE} PROPERTIES OUTPUT_NAME xlsxio_write_w)
#IF(MINGW AND LINKTYPE STREQUAL "SHARED")
# SET_TARGET_PROPERTIES(xlsxio_writew_${LINKTYPE} PROPERTIES LINK_FLAGS "-Wl,--output-def=libxlsxio_writew.def")
#ENDIF()
#TARGET_LINK_LIBRARIES(xlsxio_writew_${LINKTYPE} ${ANYZIP_LIBRARIES} ${THREADLIB})
#SET(ALLTARGETS ${ALLTARGETS} xlsxio_writew_${LINKTYPE})
ENDIF()
SET(EXELINKTYPE ${LINKTYPE})
ENDFOREACH()
#SET_TARGET_PROPERTIES(xlsxio_read_SHARED PROPERTIES DEFINE_SYMBOL "BUILD_XLSXIO_DLL")
#SET_TARGET_PROPERTIES(xlsxio_write_SHARED PROPERTIES DEFINE_SYMBOL "BUILD_XLSXIO_DLL")
IF(BUILD_TOOLS)
ADD_EXECUTABLE(xlsxio_xlsx2csv src/xlsxio_xlsx2csv.c)
TARGET_LINK_LIBRARIES(xlsxio_xlsx2csv xlsxio_read_${EXELINKTYPE})
SET(ALLTARGETS ${ALLTARGETS} xlsxio_xlsx2csv)
ADD_EXECUTABLE(xlsxio_csv2xlsx src/xlsxio_csv2xlsx.c)
TARGET_LINK_LIBRARIES(xlsxio_csv2xlsx xlsxio_write_${EXELINKTYPE})
SET(ALLTARGETS ${ALLTARGETS} xlsxio_csv2xlsx)
ENDIF()
IF(BUILD_EXAMPLES)
ADD_EXECUTABLE(example_xlsxio_write_getversion examples/example_xlsxio_write_getversion.c)
TARGET_LINK_LIBRARIES(example_xlsxio_write_getversion xlsxio_write_${EXELINKTYPE})
SET(ALLTARGETS ${ALLTARGETS} example_xlsxio_write_getversion)
ADD_EXECUTABLE(example_xlsxio_write examples/example_xlsxio_write.c)
TARGET_LINK_LIBRARIES(example_xlsxio_write xlsxio_write_${EXELINKTYPE})
SET(ALLTARGETS ${ALLTARGETS} example_xlsxio_write)
ADD_EXECUTABLE(example_xlsxio_read examples/example_xlsxio_read.c)
TARGET_LINK_LIBRARIES(example_xlsxio_read xlsxio_read_${EXELINKTYPE})
SET(ALLTARGETS ${ALLTARGETS} example_xlsxio_read)
ADD_EXECUTABLE(example_xlsxio_read_advanced examples/example_xlsxio_read_advanced.c)
TARGET_LINK_LIBRARIES(example_xlsxio_read_advanced xlsxio_read_${EXELINKTYPE})
SET(ALLTARGETS ${ALLTARGETS} example_xlsxio_read_advanced)
IF(WITH_WIDE)
ADD_EXECUTABLE(example_xlsxio_readw examples/example_xlsxio_read.c)
SET_TARGET_PROPERTIES(example_xlsxio_readw PROPERTIES COMPILE_DEFINITIONS "XML_UNICODE")
TARGET_LINK_LIBRARIES(example_xlsxio_readw xlsxio_readw_${EXELINKTYPE})
SET(ALLTARGETS ${ALLTARGETS} example_xlsxio_readw)
ENDIF()
ENDIF()
IF(BUILD_DOCUMENTATION)
IF(NOT DOXYGEN_FOUND)
MESSAGE(FATAL_ERROR "Doxygen is needed to build the documentation.")
ENDIF()
ADD_CUSTOM_TARGET(doc ALL
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/doc/Doxyfile
#WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Generating API documentation with Doxygen"
VERBATIM
)
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/doc/man
DESTINATION .
)
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/doc/html
DESTINATION share/xlsxio
)
ENDIF()
# installation specifications
INSTALL(TARGETS ${ALLTARGETS}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)
INSTALL(DIRECTORY include/
DESTINATION include
FILES_MATCHING PATTERN "xlsxio*.h"
)
IF(MINGW AND BUILD_SHARED)
INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/libxlsxio_read.def" DESTINATION lib)
INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/libxlsxio_write.def" DESTINATION lib)
IF(WITH_WIDE)
INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/libxlsxio_readw.def" DESTINATION lib)
#INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/libxlsxio_writew.def" DESTINATION lib)
ENDIF()
ENDIF()
# generate .cmake and .pc files
MACRO(generate_and_install_config_files _NAME _DESC _LIBS _HEADER)
SET(XLSXIO_NAME "${_NAME}")
SET(XLSXIO_DESC "${_DESC}")
SET(XLSXIO_HEADER "${_HEADER}")
STRING(REGEX REPLACE "^lib\([^ ]*\)" "\\1" XLSXIO_LIB "${XLSXIO_NAME}")
STRING(REPLACE ";" " " XLSXIO_LDFLAGS "-l${XLSXIO_LIB} ${_LIBS}")
STRING(REGEX REPLACE "\([^ ]*\)[/\\]lib([^ /\\.]*).[^ ]*" "-L\\1 -l\\2" XLSXIO_LDFLAGS "${XLSXIO_LDFLAGS}")
CONFIGURE_FILE(templateConfig.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/${XLSXIO_NAME}Config.cmake" @ONLY)
CONFIGURE_FILE(templateConfigVersion.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/${XLSXIO_NAME}ConfigVersion.cmake" @ONLY)
INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/${XLSXIO_NAME}Config.cmake" "${CMAKE_CURRENT_BINARY_DIR}/${XLSXIO_NAME}ConfigVersion.cmake" DESTINATION cmake/)
IF (BUILD_PC_FILES)
CONFIGURE_FILE(template.pc.in "${CMAKE_CURRENT_BINARY_DIR}/${XLSXIO_NAME}.pc" @ONLY)
INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/${XLSXIO_NAME}.pc" DESTINATION lib/pkgconfig)
ENDIF()
ENDMACRO()
generate_and_install_config_files("libxlsxio_write" "C library for writing .xlsx files" "${ANYZIP_LIBRARIES} ${THREADLIB}" "xlsxio_write.h")
generate_and_install_config_files("libxlsxio_read" "C library for writing .xlsx files" "${ANYZIP_LIBRARIES} ${EXPAT_LIBRARIES}" "xlsxio_read.h")
IF(WITH_WIDE)
generate_and_install_config_files("libxlsxio_readw" "C library for reading .xlsx files using wide characters" "${ANYZIP_LIBRARIES} ${EXPAT_LIBRARIES}" "xlsxio_read.h")
ENDIF()

View File

@ -212,6 +212,19 @@ for (i = 0; i < 1000; i++) {
xlsxiowrite_close(handle);
```
### Conan Package
Build conan package:
```bash
cd xlsxio
conan create . --build=missing <user>/<channel>
```
You can specify `settings` with `-s` and package options with `-o`.
[Read about Conan](https://docs.conan.io/en/latest/reference/commands/creator/create.html).
License
-------
XLSX I/O is released under the terms of the MIT License (MIT), see LICENSE.txt.

68
conanfile.py Normal file
View File

@ -0,0 +1,68 @@
from conans import ConanFile, CMake, tools
import os
class xlsxioConan(ConanFile):
name = "xlsxio"
version = "0.2.33"
url = "https://github.com/brechtsanders/xlsxio"
homepage = "https://zlib.net"
license = ""
generators = "cmake"
exports_sources = "CMakeLists.txt", "build/*", "include/*", "lib/*", "src/*", "CMake/*", "Makefile", "template*"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"libzip": [True, False],
"pc_files": [True, False],
"tools": [True, False],
"examples": [True, False],
"write": [True, False]
}
default_options = {
"minizip:bzip2": False, # Disable bzip2 for minizip, because it is not necessary and break building
"shared": True,
"libzip": False, # Not implemented another option
"pc_files": False,
"tools": False,
"examples": False,
"write": True
}
build_requires = ("minizip/1.2.12",
"expat/2.2.7")
def build(self):
cmake = CMake(self)
cmake.definitions["BUILD_SHARED"] = self.options.shared
cmake.definitions["BUILD_STATIC"] = not self.options.shared
cmake.definitions["WITH_LIBZIP"] = self.options.libzip
cmake.definitions["BUILD_PC_FILES"] = self.options.pc_files
cmake.definitions["BUILD_TOOLS"] = self.options.tools
cmake.definitions["BUILD_EXAMPLES"] = self.options.examples
cmake.configure()
cmake.build()
def package(self):
self.copy("*.h", src="include", dst="include")
if os.getcwd() == self.build_folder:
if self.options.shared:
self.copy("*.dll", src=self.build_folder, dst="bin", keep_path=False)
self.copy("*.so*", src=self.build_folder, dst="bin", symlinks=True, keep_path=False)
else:
self.copy("*{0}.lib".format(self.name), src=self.build_folder, dst="lib", keep_path=False)
self.copy("*.a", src=self.build_folder, dst="lib", keep_path=False)
def package_info(self):
self.cpp_info.includedirs = ["include"]
self.cpp_info.libs = ["{0}_read".format(self.name)]
if self.options.write:
self.cpp_info.libs + ["{0}_write".format(self.name)]
if not self.options.shared:
self.cpp_info.defines = ["{0}_STATICLIB".format(self.name.upper())]