CMake: GLFW as an external project

Question

I am trying to create a project that uses GLFW . For this project, I use CMake as a build system. I would like to make the user just need to create my project using CMake, and as part of the GLFW process, it will be built and linked accordingly.

To do this, I add GLFW as an ExternalProject to 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 using CMake without specifying CMAKE_INSTALL_PREFIX .

Attempt to solve

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

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

After adding an external project. However, these seams have no effect.

Question

How to set CMAKE_INSTALL_PREFIX for glfw ExternalProject?

As @drescherjm mentioned, the root of this failure is that CMake tries to create files in C:/Program Files , which require special permissions to do this. The problem is that CMake defaults to this location because I cannot 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

+5
source share
1 answer

You need to pass the CMAKE_INSTALL_PREFIX argument manually to ExternalProject_Add . Try the following:

 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" ) 
+3
source

Source: https://habr.com/ru/post/1212501/


All Articles