6

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

Community
  • 1
  • 1
Noah Huppert
  • 4,028
  • 6
  • 36
  • 58
  • The main problem is UAC is preventing you from creating folders and files in Program Files. – drescherjm Feb 03 '15 at 04:20
  • @drescherjm I know. The issue is I do not want GLFW to install in that location. Instead I want it to install in my CMake project directory. CMake just defaults to that location on windows. – Noah Huppert Feb 03 '15 at 04:21
  • Set `CMAKE_INSTALL_PREFIX` to something other than Program Files. I do not use the set_target_properties to do this I use set change the install prefix for all targets in my CMakeLists.txt – drescherjm Feb 03 '15 at 04:25
  • @drescherjm Setting the `CMAKE_INSTALL_PREFIX` for my project has no effect on the build process of GLFW. I need to set it for the `glfw` ExternalProject. – Noah Huppert Feb 03 '15 at 04:30
  • 1
    From the Docs http://www.cmake.org/cmake/help/v3.0/module/ExternalProject.html `EXTERNALPROJECT_ADD` has a `INSTALL_DIR` parameter that sets the install prefix. – drescherjm Feb 03 '15 at 04:32
  • @drescherjm Look at the first code snippet. I set that parameter. [Full CMake file](https://github.com/Noah-Huppert/glib/blob/restart/CMakeLists.txt) – Noah Huppert Feb 03 '15 at 04:36
  • Not sure why that does not work. Sorry to waste your time. I use CMake daily since 2008 but I do not use ExternalProject_Add mainly because most of my applications require the same libraries and I create these via batch scripting CMake. – drescherjm Feb 03 '15 at 04:41
  • @drescherjm No problem, that thanks for taking a shot at it. I'm glad someone who knew what they were doing at least looked at it. Would you recommend any other ways of linking other CMake projects? – Noah Huppert Feb 03 '15 at 04:46
  • 1
    If you want a easier way to use GLFW in your project, take a look at [biicode](https://www.biicode.com/) and [this example](http://docs.biicode.com/c++/examples/glfw.html). It takes only a while and will save you a lot of time ;) Disclaimer: I work at biicode – fenix688 Feb 03 '15 at 13:57

1 Answers1

4

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"
)
  • Just curious, why do you specify a URL to a tar instead of a git url? Is it so users can build without having git installed? – Noah Huppert Feb 03 '15 at 19:48
  • @NoahHuppert yes, I've tested it on windows now, won't bother with the git location :) –  Feb 03 '15 at 19:49