https://vcpkg.io/en/index.html
Install vckpg
Step 1: Clone the vcpkg repo
PS ...> cd C:\dev\
PS C:\dev> git clone https://github.com/Microsoft/vcpkg.git
Step 2: Run the bootstrap script to build vcpkg
PS C:\dev> cd .\vckpg\
PS C:\dev\vcpkg> .\bootstrap-vcpkg.bat
Install libraries for your project
PS C:\dev\vcpkg> .\vcpkg install glib:x64-windows
Use
https://vcpkg.io/en/docs/examples/installing-and-using-packages.html
VS/MSBuild Project (User-wide integration)
PS C:\dev\vcpkg> .\vcpkg integrate install
Applied user-wide integration for this vcpkg root.
All C++ projects can now #include any installed libraries.
Linking will be handled automatically.
Installing new libraries will make them instantly available.
Remove
PS C:\dev\vcpkg> .\vcpkg integrate remove
CMake (Toolchain File)
The best way to use installed libraries with cmake is via the toolchain file scripts/buildsystems/vcpkg.cmake.
To use this file, you simply need to add it onto your CMake command line as:
-DCMAKE_TOOLCHAIN_FILE=C:\dev\vcpkg\scripts\buildsystems\vcpkg.cmake.
If you are using CMake through Open Folder with Visual Studio you can define CMAKE_TOOLCHAIN_FILE by adding a "variables" section to each of your CMakeSettings.json configurations:
{
"configurations": [{
"name": "x86-Debug",
"generator": "Visual Studio 15 2017",
"configurationType" : "Debug",
"buildRoot": "${env.LOCALAPPDATA}\\CMakeBuild\\${workspaceHash}\\build\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "-m -v:minimal",
"variables": [{
"name": "CMAKE_TOOLCHAIN_FILE",
"value": "C:/Dev/vcpkg/scripts/buildsystems/vcpkg.cmake"
}]
}]
}
Note: It might be necessary to delete the CMake cache folder of each modified configuration, to force a full regeneration. In the CMake menu, under Cache (<configuration name>) you'll find Delete Cache Folders.
Now let's make a simple CMake project with a main file.
# CMakeLists.txt
cmake_minimum_required(VERSION 3.0)
project(test)
find_package(unofficial-sqlite3 CONFIG REQUIRED)
add_executable(main main.cpp)
target_link_libraries(main PRIVATE unofficial::sqlite3::sqlite3)
// main.cpp
#include <sqlite3.h>
#include <stdio.h>
int main()
{
printf("%s\n", sqlite3_libversion());
return 0;
}
Then, we build our project in the normal CMake way:
PS D:\src\cmake-test> mkdir build
PS D:\src\cmake-test> cd build
PS D:\src\cmake-test\build> cmake .. "-DCMAKE_TOOLCHAIN_FILE=D:\src\vcpkg\scripts\buildsystems\vcpkg.cmake"
// omitted CMake output here //
-- Build files have been written to: D:/src/cmake-test/build
PS D:\src\cmake-test\build> cmake --build .
// omitted MSBuild output here //
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:02.38
PS D:\src\cmake-test\build> .\Debug\main.exe
3.15.0
Note: The correct sqlite3.dll is automatically copied to the output folder when building for x86-windows. You will need to distribute this along with your application.
Handling libraries without native cmake support
Unlike other platforms, we do not automatically add the include\ directory to your compilation line by default.
If you're using a library that does not provide CMake integration, you will need to explicitly search for the files and add them yourself using find_path() and find_library().
# To find and use catch
find_path(CATCH_INCLUDE_DIR catch.hpp)
include_directories(${CATCH_INCLUDE_DIR})
# To find and use azure-storage-cpp
find_path(WASTORAGE_INCLUDE_DIR was/blob.h)
find_library(WASTORAGE_LIBRARY wastorage)
include_directories(${WASTORAGE_INCLUDE_DIR})
link_libraries(${WASTORAGE_LIBRARY})
# Note that we recommend using the target-specific directives for a cleaner cmake:
# target_include_directories(main ${LIBRARY})
# target_link_libraries(main PRIVATE ${LIBRARY})
'C, C++' 카테고리의 다른 글
xlnt - XLSX 파일 다루기 (0) | 2022.12.22 |
---|---|
To install the MinGW-w64 toolchain (0) | 2022.10.28 |
문자열 구분자로 분리 (0) | 2021.10.20 |
Get DLL path at run time (0) | 2021.10.05 |
ticktock (0) | 2021.08.15 |