libxlsxwriter library - How to connect to personal project with CMake C++

169 Views Asked by At

How do I connect the libxlsxwriter library to my personal project using CMake.

I cloned the official library files from https://github.com/jmcnamara/libxlsxwriter.

Then I extracted it in my personal project and added a few lines of CMake:


cmake_minimum_required(VERSION 3.11.0)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

[enter image description here][1]

include(FetchContent)
FetchContent_Declare(
  googletest
  GIT_REPOSITORY https://github.com/google/googletest.git
  GIT_TAG        main # release-1.10.0
)

include(FetchContent)
FetchContent_Declare(
        Bcrypt
        GIT_REPOSITORY https://github.com/veltro123/Bcrypt.cpp
        GIT_TAG master
)
FetchContent_MakeAvailable(Bcrypt)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)

# Now simply link against gtest or gtest_main as needed. Eg

#ADDED
include_directories("libxlsxwriter/include")
set(XLSXWRITER_LIBRARY "libxlsxwriter/build/libxlsxwriter.a")
add_library(xlsxwriter STATIC IMPORTED)
set_target_properties(xlsxwriter PROPERTIES IMPORTED_LOCATION ${XLSXWRITER_LIBRARY})
target_link_libraries(${PROJECT_NAME} xlsxwriter)
#END

project(MONEYTRACKER)
enable_testing()

add_executable(${PROJECT_NAME} main.cpp Src/Transaction.cpp Src/Date.cpp Src/User.cpp)
add_executable(${PROJECT_NAME}-ut Testing/DateTests.cpp Testing/UserTests.cpp Src/Transaction.cpp Src/Date.cpp Src/User.cpp)

target_link_libraries(${PROJECT_NAME}-ut gtest_main)
target_link_libraries(${PROJECT_NAME} PRIVATE bcrypt)

include(GoogleTest)
gtest_discover_tests(${PROJECT_NAME}-ut)

This is the error I get:

enter image description here

0

There are 0 best solutions below