CMake: GLFW as ExternalProject

≯℡__Kan透↙ 提交于 2019-12-08 21:40:39

问题


Issue

I am trying to make a project that uses GLFW. For this project I am using CMake as a build system. I would like to make it so the user just has to build my project with CMake, and as part of the process GLFW will get built and linked appropriately.

To do this I am adding GLFW as a ExternalProject in my CMake file:

EXTERNALPROJECT_ADD(glfw
    GIT_REPOSITORY https://github.com/glfw/glfw.git
    GIT_TAG 3.1
    INSTALL_DIR "${PROJECT_BINARY_DIR}/libs/glfw"
)

However when I generate the project(For VS12 2013 x64) and run ALL_BUILD I get the following error:

2>    CMake Error at cmake_install.cmake:31 (file):
2>      file INSTALL cannot make directory "C:/Program Files/GLFW/include/GLFW": No
2>      such file or directory

I get the same error when I try to build GLFW with CMake without specifying the CMAKE_INSTALL_PREFIX.

Attempted Solution

To fix this I would like to specify the CMAKE_INSTALL_PREFIX option for the glfw ExternalProject. However I do not seam to be able to do this. I have tried:

SET_TARGET_PROPERTIES(glfw PROPERTIES CMAKE_INSTALL_PREFIX "${PROJECT_BINARY_DIR}/libs/glfw")

After adding the ExternalProject. However this seams to have no effect.

Question

How do I set the CMAKE_INSTALL_PREFIX for the glfw ExternalProject?

As mentioned by @drescherjm the root of this failure is that CMake is trying to create files in C:/Program Files which it needs special permissions for. The issue is that CMake is defaulting to this location because I am unable to set the correct location in my CMake file.

Additional Information

OS: Windows 8.1 x64
CMake Version: 3.1.1
Visual Studio Version: Community 2013 V4.5.53349
CMake File


回答1:


You need to pass CMAKE_INSTALL_PREFIX argument manually to ExternalProject_Add. Try this one:

cmake_minimum_required(VERSION 2.8)
project(Foo)

include(ExternalProject)

ExternalProject_Add(
    GLFW
    URL "https://github.com/glfw/glfw/archive/3.1.tar.gz"
    URL_HASH SHA1=fe17a0610a239311a726ecabcd2dbd669fb24ca8
    CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/_my_install"
)


来源:https://stackoverflow.com/questions/28291238/cmake-glfw-as-externalproject

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!