0

I am trying to understand how to compile and link another CMake project into my project without modifying the previous projects CMake configuration. In this case I want to build and compile the library glfw found here https://www.glfw.org/ with my own OpenGL project. How do I do this?

So I have looked into how to build multiple CMake projects from sources like CMake one build directory for multiple projects, and try to link them however everything I read recommends that I alter the CMake file for the project I am trying to build and then link.

Here is an example directory structure that I am using.

.
├── CMakeLists.txt
├── Proj1
│   ├── include
│   ├── lib
│   └── src
│       └── CMakeLists.txt
└── glfw-3.3
    ├── CMake
    ├── CMakeLists.txt
    ├── LICENSE.md
    ├── README.md
    ├── cmake_uninstall.cmake.in
    ├── deps
    ├── docs
    ├── examples
    ├── include
    ├── src
    └── tests

Here Proj1 is where I want to be building my OpenGL application. I have the directory Proj1/lib for any library files that I do not need to compile before hand. However, I have to compile the glfw library before using it. So should I just compile the glfw library in isolation then bring in the lib files and include files into my own project? Or is there a way to compile the glfw library and then link it in with my own CMake?

  • 1
    You can use the [`ExternalProject`](https://cmake.org/cmake/help/latest/module/ExternalProject.html) module to handle it for you. It's highly configurable, and I think would fit your use case nicely. – StoryTeller - Unslander Monica May 12 '19 at 05:41
  • Another could be to add `add_subdirectory(glfw_directory EXCLUDE_FROM_ALL)` in your project CMakeLists.txt see https://cmake.org/cmake/help/v3.14/command/add_subdirectory.html – Oliv May 12 '19 at 07:17
  • @StoryTeller Thank you! That seems to have worked! –  May 14 '19 at 19:47

0 Answers0