1
0
mirror of https://github.com/QtExcel/QXlsx.git synced 2025-01-16 04:42:53 +08:00
QXlsx/HowToSetProject-cmake.md

53 lines
1.1 KiB
Markdown
Raw Normal View History

2021-02-12 22:11:11 +09:00
## Using cmake
> *Read this in other languages: [English](HowToSetProject-cmake.md), :kr: [한국어](HowToSetProject-cmake.ko.md)*
2022-10-15 14:29:30 +01:00
### To install QXlsx
2021-02-12 22:11:11 +09:00
2022-10-15 14:29:30 +01:00
Enter the command as shown below.
2021-02-12 23:52:03 +09:00
2022-10-15 14:29:30 +01:00
```sh
2021-02-12 22:11:11 +09:00
mkdir build
cd build
2022-10-15 14:29:30 +01:00
cmake ../QXlsx/ -DCMAKE_INSTALL_PREFIX=... -DCMAKE_BUILD_TYPE=Release
cmake --build .
cmake --install .
2021-02-12 23:52:03 +09:00
```
2022-10-15 14:29:30 +01:00
### To use in your application
2021-03-07 18:15:54 +09:00
2022-10-15 14:29:30 +01:00
In your CMakeLists.txt:
2021-03-07 18:15:54 +09:00
2022-10-15 14:29:30 +01:00
```cmake
find_package(QXlsxQt5 REQUIRED) # or QXlsxQt6
target_link_libraries(myapp PRIVATE QXlsx::QXlsx)
2021-03-07 18:15:54 +09:00
```
2022-10-15 14:29:30 +01:00
### To use in your application without installation
2021-03-07 18:15:54 +09:00
2022-10-30 11:27:58 +03:00
There are 2 possible ways:
1) Use cmake subdirectory
2022-10-15 14:29:30 +01:00
In your CMakeLists.txt:
2021-02-12 23:52:03 +09:00
2022-10-15 14:29:30 +01:00
```cmake
add_subdirectory(QXlsx)
target_link_libraries(myapp PRIVATE QXlsx::QXlsx)
2021-02-12 22:11:11 +09:00
```
2022-10-30 11:27:58 +03:00
2) Use cmake FetchContent
In your CMakeLists.txt:
```cmake
FetchContent_Declare(
QXlsx
GIT_REPOSITORY https://github.com/QtExcel/QXlsx.git
GIT_TAG sha-of-the-commit
SOURCE_SUBDIR QXlsx
)
FetchContent_MakeAvailable(QXlsx)
target_link_libraries(myapp PRIVATE QXlsx::QXlsx)
```
if `QT_VERSION_MAJOR` is not set, QXlsx's CMakeLists.txt will try to find a Qt version (5 or 6) itself.