I have found servel pkg can not obtain the pkg_DIR, for example,
GTest_DIR
mathgl_DIR
SET(CMAKE_TOOLCHAIN_FILE "E:/vcpkg/scripts/buildsystems/vcpkg.cmake" CACHE STRING "Vcpkg toolchain file")
...
find_package(GTest CONFIG REQUIRED)
include_directories(${GTEST_INCLUDE_DIR})
message(gtest_include_dir=${GTEST_INCLUDE_DIR})
message(gtest_library=${GTEST_LIBRARY})
throw
1> [CMake] gtest_include_dir=
1> [CMake] gtest_library=
and
find_package(mathgl CONFIG REQUIRED)
throw
1> [CMake] Could not find a package configuration file provided by "mathgl" with any
1> [CMake] of the following names:
1> [CMake]
1> [CMake] mathglConfig.cmake
1> [CMake] mathgl-config.cmake
1> [CMake]
1> [CMake] Add the installation prefix of "mathgl" to CMAKE_PREFIX_PATH or set
1> [CMake] "mathgl_DIR" to a directory containing one of the above files.
There are 2 different issues here:
When you vcpkg install gtest it will print out the following instructions for linking, so you should use target_link_libraries() and that should add the correct include directories.
find_package(GTest CONFIG REQUIRED)
target_link_libraries(main PRIVATE GTest::gmock GTest::gtest GTest::gmock_main GTest::gtest_main)
There is a bug in the port, the CMake integration files are not produced correctly.
So the printed instructions won't work:
The package mathgl:x64-windows provides CMake targets:
find_package(mathgl CONFIG REQUIRED)
target_link_libraries(main PRIVATE mgl mgl-static)
You can workaround this by setting the include directories and library path manually.
Below is an example CMakeLists.txt that links both libraries:
cmake_minimum_required(VERSION 3.14)
project(example CXX)
add_executable(example main.cpp)
# Link GTest
find_package(GTest CONFIG REQUIRED)
# Link MathGL (work around broken config files, that make `find_package(mgl CONFIG REQUIRED)` fail)
find_path(MATHGL_INCLUDE_DIR mgl2/mgl.h)
find_library(MATHGL_LIBRARY mgl)
target_include_directories(example PRIVATE ${MATHGL_INCLUDE_DIR})
target_link_libraries(example
PRIVATE GTest::gtest GTest::gmock GTest::gtest_main GTest::gmock_main ${MATHGL_LIBRARY})
@vicroms thanks your help and your patience, solved my problem.
Most helpful comment
There are 2 different issues here:
Linking GTest
When you
vcpkg install gtestit will print out the following instructions for linking, so you should usetarget_link_libraries()and that should add the correct include directories.Linking mathgl
There is a bug in the port, the CMake integration files are not produced correctly.
So the printed instructions won't work:
You can workaround this by setting the include directories and library path manually.
Below is an example
CMakeLists.txtthat links both libraries: