Reputation: 50989
Suppose I have installed some library with vcpkg
and it's numerous dependencied (say cgal
). Now I want to compile some program against these libraries with CMake
.
How should I tell CMake
about all locations of all libraries I have downloaded? Including main library I have installed? I have only one setting in CMake
, called "source directory" which will point to my code. Where are settings for libraries?
D:\Users\ThirdPartyDesign\CGAL-5.0-examples\CGAL-5.0\examples\Triangulation_2
λ env | grep CMAKE
CMAKE_TOOLCHAIN_FILE=D:\Users\ThirdPartyDesign\vcpkg\scripts\buildsystems\vcpkg.cmake
D:\Users\ThirdPartyDesign\CGAL-5.0-examples\CGAL-5.0\examples\Triangulation_2
λ cmake .
CMake Warning at CMakeLists.txt:18 (find_package):
By not providing "FindCGAL.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "CGAL", but
CMake did not find one.
Could not find a package configuration file provided by "CGAL" with any of
the following names:
CGALConfig.cmake
cgal-config.cmake
Add the installation prefix of "CGAL" to CMAKE_PREFIX_PATH or set
"CGAL_DIR" to a directory containing one of the above files. If "CGAL"
provides a separate development package or SDK, be sure it has been
installed.
-- This program requires the CGAL library, and will not be compiled.
-- Configuring done
-- Generating done
-- Build files have been written to: D:/Users/ThirdPartyDesign/CGAL-5.0-examples/CGAL-5.0/examples/Triangulation_2
Upvotes: 12
Views: 28600
Reputation: 375
I added the jsoncpp package through vcpkg. I used the following command to clone the vcpkg repository to the external folder, I even put it in an install_dependencies.sh file:
DIR="external"
git clone https://github.com/Microsoft/vcpkg.git "$DIR/vcpkg"
cd "$DIR/vcpkg"
./bootstrap-vcpkg.sh
./vcpkg integrate install
./vcpkg install jsoncpp
Then, in the CMakeLists.txt file I added the following commands after the add_executable function:
# ...
add_executable(${PROJECT_NAME} ${SOURCE_FILES} ${HEADERS})
#-- JSONCPP ------------------------------
set(JSON_INC_PATH external/vcpkg/packages/jsoncpp_x64-osx/include)
target_include_directories(${PROJECT_NAME} PUBLIC ${JSON_INC_PATH})
set(JSON_LIB_PATH external/vcpkg/packages/jsoncpp_x64-osx/lib)
target_link_directories(${PROJECT_NAME} PUBLIC ${JSON_LIB_PATH})
#----------------------------------------
target_link_libraries(${PROJECT_NAME}
#...
jsoncpp
)
Now after reloading, I can include the json library using:
#include <json/json.h>
# Rest of code here...
Upvotes: 7
Reputation: 401
Normally you need to set; CMAKE_TOOLCHAIN_FILE
and VCPKG_TARGET_TRIPLET
.
Set VCPKG_TARGET_TRIPLET
to the vcpkg triplet that you are using. The default is x86-windows
Set CMAKE_TOOLCHAIN_FILE
to point to path_to_vcpkg\scripts\buildsystems\vcpkg.cmake
Then you can use cmake functions such as find_package
to find the required package.
see https://github.com/microsoft/vcpkg/blob/master/docs/examples/installing-and-using-packages.md#cmake-toolchain-file for more information.
Upvotes: 15