我正在尝试构建一个跨平台的OpenGL应用程序,这意味着构建并包含多个库(glfw,glbinding,glm等)因为我的应用程序是跨平台的,所以使用cmake生成所有构建脚本是有意义的而不必亲自与他们混在一起。我试图专门针对Windows和Linux。
我需要的一个主要功能是我需要的库没有安装在主机系统上。此外,它们无法安装(由于管理原因)。我需要的是构建这些库,然后构建我的应用程序。
我主要使用Visual Studio 2017在Windows上工作,它包含cmake支持。目前,我已经尝试自己构建这些库,但是我在使用find_package做正确的事情时遇到了很多问题。
我的目录结构如下所示:
project/
|-src/
|- my sources for my application
|-include/
|- my header files
|-external/
|-glfw-3.2.1/
|-glbinding-2.1.4/
|-glfw-build/
|-glbinidng-build/
所以我试图构建外部库并在我的应用程序中使用它们。我也试图遵循cmake最佳实践。我的CMakeLists.txt目前看起来像这样:
cmake_minimum_required(VERSION 3.5)
project(glTestProj)
set(CMAKE_PREFIX_PATH "external/")
find_package(glfw3 3.2 REQUIRED)
find_package(glbinding REQUIRED)
add_executable(glTest src/main.cpp)
target_compile_features(glTest PRIVATE cxx_std_17)
target_compile_options(glTest PRIVATE -Wall -Wextra)
target_link_libraries(
glTest
glfw
glbinding::glbinding
)
相关库(glfw和glbinding)都有关于通过cmake包含它们的说明,但是我遇到了这个问题:
CMake Error at CMakeLists.txt:6 (find_package):
By not providing "Findglfw3.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "glfw3", but
CMake did not find one.
Could not find a package configuration file provided by "glfw3" (requested
version 3.2) with any of the following names:
glfw3Config.cmake
glfw3-config.cmake
Add the installation prefix of "glfw3" to CMAKE_PREFIX_PATH or set
"glfw3_DIR" to a directory containing one of the above files. If "glfw3"
provides a separate development package or SDK, be sure it has been
installed.