How can I connect my QT cmake project to LibXL
-
I am making an project and I need the LibXL library for modifying excel sheets.
I tried some ways to connect the library to the projectcmake_minimum_required(VERSION 3.5) project(TM_Checker VERSION 0.1 LANGUAGES CXX) # Enable automatic Qt features set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) # Set the C++ standard set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) # Find Qt package find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets Sql) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Sql) # Project source files set(PROJECT_SOURCES TMCheckerDoc.h TMCheckerDoc.cpp main.cpp mainwindow.cpp dialogbrowsefiles.cpp dialogbrowsefiles.h mainwindow.h mainwindow.ui dialogbrowsefiles.ui ) # Add executable for different Qt versions and platforms if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) qt_add_executable(TM_Checker MANUAL_FINALIZATION ${PROJECT_SOURCES} ) else() if(ANDROID) add_library(TM_Checker SHARED ${PROJECT_SOURCES} ) set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") else() add_executable(TM_Checker ${PROJECT_SOURCES} ) endif() endif() # Set target properties set_target_properties(TM_Checker PROPERTIES MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} MACOSX_BUNDLE TRUE WIN32_EXECUTABLE TRUE ) # Install rules install(TARGETS TM_Checker BUNDLE DESTINATION . LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) # Include libxl if(NOT DEFINED LIBXL_HEADERPATH) # set(LIBXL_HEADERPATH ${CMAKE_CURRENT_SOURCE_DIR}/libxl/include/) set(LIBXL_HEADERPATH ${CMAKE_CURRENT_SOURCE_DIR}/libxl-4.3.0.14/include_cpp/) endif() if(NOT DEFINED LIBXL_LIBPATH) # set(LIBXL_LIBPATH ${CMAKE_CURRENT_SOURCE_DIR}/libxl/lib/) set(LIBXL_LIBPATH ${CMAKE_CURRENT_SOURCE_DIR}/libxl-4.3.0.14/lib/) endif() target_include_directories(TM_Checker PRIVATE ${LIBXL_HEADERPATH} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/header> $<INSTALL_INTERFACE:include/libxlQt${QT_VERSION_MAJOR}> ) # Link libxl and Qt libraries link_directories(${LIBXL_LIBPATH}) target_link_libraries(TM_Checker PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Sql xl ) # Finalize executable for Qt 6 if(QT_VERSION_MAJOR EQUAL 6) qt_finalize_executable(TM_Checker) endif()
above is the code but it won't make it display in the projects tab even though there is no issue.
Help me with this issue please. -
@Mihil-Ranasinghe said in How can I connect my QT cmake project to LibXL:
but it won't make it display in the projects tab
What do you mean by that?
Does ${CMAKE_CURRENT_SOURCE_DIR}/libxl-4.3.0.14/lib contain the library file? -
@jsulm said in How can I connect my QT cmake project to LibXL:
What do you mean by that?
The library not being displayed. -
@Mihil-Ranasinghe said in How can I connect my QT cmake project to LibXL:
The library not being displayed
Why should libraries linked to the project should be shown in the project tree? Do you see QtWidgets lib in there? They are not shown there.
-
@Mihil-Ranasinghe You either build the library and add it to your project like any other shared library (using target_link_libraries) or you add the library source code to your project.
-
@Christian-Ehrlicher Because LibXL is a external library, I am saying this because when I was using QXlsx library it was shown in project tree.
like this. -
@Mihil-Ranasinghe said in How can I connect my QT cmake project to LibXL:
Because LibXL is a external library
Then link it properly using target_link_libraries
-
@jsulm OK thanks a lot. I think I found the issue.
The thing is I guess it has been recognised and loaded. It's not displayed in the project tree is because LibXL(https://www.libxl.com/download.html) does not contain a CMakeList.txt in it.Anyways thanks alot @jsulm 🙏
-
@Mihil-Ranasinghe said in How can I connect my QT cmake project to LibXL:
was using QXlsx library it was shown in project tree.
You did not - you just added the sources to your project instead linking to an external library - these are two completely different things.