https://github.com/tfussell/xlnt

 

GitHub - tfussell/xlnt: Cross-platform user-friendly xlsx library for C++11+

:bar_chart: Cross-platform user-friendly xlsx library for C++11+ - GitHub - tfussell/xlnt: Cross-platform user-friendly xlsx library for C++11+

github.com

 

Windows

> cd vcpkg
> ./vcpkg install xlnt:x64-windows

Linux

$ git clone https://github.com/microsoft/vcpkg.git
$ cd vcpkg
$ ./bootstrap-vcpkg.sh
$ sudo ./vcpkg integrate install
$ ./vcpkg install xlnt
...
-- Configuring x64-linux
-- Building x64-linux-dbg
-- Building x64-linux-rel
-- Installing: /home/jym/dev/vcpkg/packages/xlnt_x64-linux/share/xlnt/copyright
-- Fixing pkgconfig file: /home/jym/dev/vcpkg/packages/xlnt_x64-linux/lib/pkgconfig/xlnt.pc
-- Fixing pkgconfig file: /home/jym/dev/vcpkg/packages/xlnt_x64-linux/debug/lib/pkgconfig/xlnt.pc
...
xlnt provides CMake targets:

    # this is heuristically generated, and may not be correct
    find_package(Xlnt CONFIG REQUIRED)
    target_link_libraries(main PRIVATE xlnt::xlnt)

 

Specify the toolchain as a CMake option:

-DCMAKE_TOOLCHAIN_FILE=/home/jym/dev/vcpkg/scripts/buildsystems/vcpkg.cmake

But this won't work if you already specify a toolchain, such as when cross-compiling.

To avoid this problem, include it.

include(/home/jym/dev/vcpkg/scripts/buildsystems/vcpkg.cmake)

 

Example: CMakeLists.txt

cmake_minimum_required(VERSION 3.16)
project(test-xlnt CXX)

set(CMAKE_VERBOSE_MAKEFILE true)
set(CMAKE_CXX_STANDARD 14)

include(/home/jym/dev/vcpkg/scripts/buildsystems/vcpkg.cmake)

list(APPEND CMAKE_PREFIX_PATH "/home/jym/dev/vcpkg/installed/x64-linux/share")

find_package(Xlnt CONFIG REQUIRED)

message("XLNT_CMAKE_DIR:   ${XLNT_CMAKE_DIR}")
message("xlnt_INCLUDE_DIR: ${xlnt_INCLUDE_DIR}")

set(SRC_FILES main.cpp)

add_executable(${PROJECT_NAME} ${SRC_FILES})

target_include_directories(${PROJECT_NAME} PRIVATE
    ${xlnt_INCLUDE_DIR})
target_link_libraries(${PROJECT_NAME} PRIVATE
    xlnt::xlnt)

 

다른 방법:

Findxlnt.cmake

# Findxlnt.cmake
#
# Finds the xlnt library
#
# This will define the following variables
#
#   xlnt_FOUND
#   xlnt_LIBRARY
#   xlnt_LIBRARIES
#   xlnt_LIBRARY_DEBUG
#   xlnt_LIBRARY_RELEASE
#
# and the following imported targets
#
#   xlnt::xlnt
#
# Author: John Coffey - johnco3@gmail.com
#

find_path(xlnt_INCLUDE_DIR NAMES xlnt/xlnt.hpp)

if (NOT xlnt_LIBRARIES)
    find_library(xlnt_LIBRARY_RELEASE NAMES xlnt DOC "xlnt release library")
    find_library(xlnt_LIBRARY_DEBUG NAMES xlntd DOC "xlnt debug library")
    include(SelectLibraryConfigurations)
    select_library_configurations(xlnt)
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(xlnt
    REQUIRED_VARS xlnt_INCLUDE_DIR xlnt_LIBRARY)
mark_as_advanced(
    xlnt_INCLUDE_DIR
    xlnt_LIBRARY)

if(xlnt_FOUND AND NOT (TARGET xlnt::xlnt))
    # debug output showing the located libraries
    message(STATUS "xlnt_INCLUDE_DIR=${xlnt_INCLUDE_DIR}")
    message(STATUS "xlnt_LIBRARY=${xlnt_LIBRARY}")
    message(STATUS "xlnt_LIBRARIES=${xlnt_LIBRARIES}")
    message(STATUS "xlnt_LIBRARY_DEBUG=${xlnt_LIBRARY_DEBUG}")
    message(STATUS "xlnt_LIBRARY_RELEASE=${xlnt_LIBRARY_RELEASE}")
    # Add a blank imported library
    add_library(xlnt::xlnt UNKNOWN IMPORTED)

    # add the transitive includes property
    set_target_properties(xlnt::xlnt PROPERTIES
        INTERFACE_INCLUDE_DIRECTORIES "${xlnt_INCLUDE_DIR}")

    # Optimized library
    if(xlnt_LIBRARY_RELEASE)
        set_property(TARGET xlnt::xlnt APPEND PROPERTY
            IMPORTED_CONFIGURATIONS RELEASE)
        set_target_properties(xlnt::xlnt PROPERTIES
            IMPORTED_LOCATION_RELEASE "${xlnt_LIBRARY_RELEASE}")
    endif()

    # Debug library
    if(xlnt_LIBRARY_DEBUG)
        set_property(TARGET xlnt::xlnt APPEND PROPERTY
            IMPORTED_CONFIGURATIONS DEBUG)
        set_target_properties(xlnt::xlnt PROPERTIES
            IMPORTED_LOCATION_DEBUG "${xlnt_LIBRARY_DEBUG}")
    endif()

    # some other configuration
    if(NOT xlnt_LIBRARY_RELEASE AND NOT xlnt_LIBRARY_DEBUG)
        set_property(TARGET xlnt::xlnt APPEND PROPERTY
            IMPORTED_LOCATION "${xlnt_LIBRARY}")
    endif()
endif()

CMakeLists.txt 수정

...
# For finding Findxlnt.cmake
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../cmake")
find_package(xlnt REQUIRED)

message("xlnt_INCLUDE_DIR: ${xlnt_INCLUDE_DIR}")
message("xlnt_LIBRARY:     ${xlnt_LIBRARY}")
message("xlnt_LIBRARIES:   ${xlnt_LIBRARIES}")
...

 

 

 

'C, C++' 카테고리의 다른 글

To install the MinGW-w64 toolchain  (0) 2022.10.28
문자열 구분자로 분리  (0) 2021.10.20
VSCode + vcpkg  (0) 2021.10.19
Get DLL path at run time  (0) 2021.10.05
ticktock  (0) 2021.08.15

+ Recent posts