My goal is to write a simple, portable application using ImGUI. I also want a platform-agnostic build experience using cmake, and vcpkg to install dependencies. I got the program built and running on my Windows machine, but it's failing on my Macbook (macOS Monterey 12.6).
This is my vcpkg.json:
{
"name": "imguitest",
"version": "1.0",
"dependencies": [
"glad",
"glfw3",
{
"name": "imgui",
"features": [ "glfw-binding", "opengl3-binding" ]
}
]
}
This is my CMakeLists.txt:
cmake_minimum_required (VERSION 3.23)
project(ImGui-Test)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin)
add_executable(${PROJECT_NAME}
src/main.cpp
)
find_package(glad CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE glad::glad)
find_package(glfw3 CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE glfw)
find_package(imgui CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE imgui::imgui)
find_package(OpenGL REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE OpenGL::GL)
After running this:
# export VCPKG_DIR=/path/to/vcpkg/repo/
cmake -B ./build -S . "-DCMAKE_TOOLCHAIN_FILE=$VCPKG_DIR/scripts/buildsystems/vcpkg.cmake"
I get this error:
CMake Error at CMakeLists.txt:14 (find_package):
Could not find a package configuration file provided by "glad" with any of
the following names:
gladConfig.cmake
glad-config.cmake
Add the installation prefix of "glad" to CMAKE_PREFIX_PATH or set
"glad_DIR" to a directory containing one of the above files. If "glad"
provides a separate development package or SDK, be sure it has been
installed.
Do I have to manually install GLAD package myself and set the path? I thought vcpkg would handle that for me. Please let me know if I'm misunderstanding something, as I'm new to modern cmake and vcpkg.
This fixed it: brew install pkg-config
I got more descriptive error messages after I deleted the build
folder. This error message was hidden when configuring cmake with vscode, but was visible when doing it through zsh terminal.
Building glfw3[core]:arm64-osx...
warning: -- Using community triplet arm64-osx. This triplet configuration is not guaranteed to succeed.
-- [COMMUNITY] Loading triplet configuration from: /Users/munta/Dev/vcpkg/triplets/community/arm64-osx.cmake
-- Downloading https://github.com/glfw/glfw/archive/7482de6071d21db77a7236155da44c172a7f6c9e.tar.gz -> glfw-glfw-7482de6071d21db77a7236155da44c172a7f6c9e.tar.gz...
-- Extracting source /Users/munta/Dev/vcpkg/downloads/glfw-glfw-7482de6071d21db77a7236155da44c172a7f6c9e.tar.gz
-- Using source at /Users/munta/Dev/vcpkg/buildtrees/glfw3/src/172a7f6c9e-7678776297.clean
GLFW3 currently requires the following libraries from the system package manager:
xinerama
xcursor
xorg
libglu1-mesa
pkg-config
These can be installed via brew install libxinerama-dev libxcursor-dev xorg-dev libglu1-mesa-dev pkg-config
-- Configuring arm64-osx
-- Building arm64-osx-dbg
-- Building arm64-osx-rel
-- Fixing pkgconfig file: /Users/munta/Dev/vcpkg/packages/glfw3_arm64-osx/lib/pkgconfig/glfw3.pc
CMake Error at scripts/cmake/vcpkg_find_acquire_program.cmake:619 (message):
Could not find pkg-config. Please install it via your package manager:
brew install pkg-config
Call Stack (most recent call first):
scripts/cmake/vcpkg_fixup_pkgconfig.cmake:151 (vcpkg_find_acquire_program)
ports/glfw3/portfile.cmake:43 (vcpkg_fixup_pkgconfig)
scripts/ports.cmake:147 (include)